Expected output of the program - c program, C/C++ Programming

Expected output of the program:

1. Consider the following programs. For each, indicate whether the program is correct. If yes, what is the expected output? If not, what is the error? (Hint: remember the discussion about scope and how curly braces { } form a new scope.)

a)

            #include

            int main()

            {

                        int my_var(19);

                        my_var += 2;

                        char my_var('a');

                        std::cout << my_var << std::endl;

                        return 0;

            }

b)

            #include

            int main()

            {

                        int my_var(19);

                        my_var += 2;

                        {

                                    char my_var('a');

                                    std::cout << my_var << std::endl;

                        }

                        return 0;

            }

c)

            #include

            int my_var = 23;

            int main()

            {

                        int my_var(19);

                        my_var += 2;

                        {

                                    char my_var('a');

                                    std::cout << my_var << std::endl;

                                    std::cout << ::my_var << std::endl;

                        }

                        return 0;

            }

2. What is the expected output of the following code snippet if the user enters the following values for "number":

            a) 0

            b) 2

            c) 10

#include

int main()

{

            int number;

            std::cout << "Enter a number : ";

            std::cin >> number;

            switch(number) {

                        case 0:

                                    std::cout << "Zero\n";

                                    break;

                        case 1:

                                    std::cout << "One\n";

                        case 2:

                                    std::cout << "Two\n";

                        case 3:

                                    std::cout << "Three\n";

                                    break;

                        case 4:

                                    std::cout << "Four\n";

                                    break;

                        default:

                                    std::cout << "Less than zero or greater than four\n";           

            }

            return 0;

}

3. Consider the following code snippet:

            int *p;

            int i;

            int k;

            i = 42;

            k = i;

            p = &i;

            (i) Assume that the above code snippet is followed by the following statements (each of them separately). For the statements that you believe are correct and will compile, what would the expected values of i and k be in each case? If you believe there is a compile-time error in any of the cases, please indicate this and briefly explain your answer.

1.*p = 10;

2.   *k = 100;

3.   p = 4532;

4.   k = 75;

 

            (ii) If the statement "p = &i;" is moved and placed right before "k = i;", which of the above answers would change (indicate A, B, C or D)?

Posted Date: 2/11/2013 3:00:22 AM | Location : United States







Related Discussions:- Expected output of the program - c program, Assignment Help, Ask Question on Expected output of the program - c program, Get Answer, Expert's Help, Expected output of the program - c program Discussions

Write discussion on Expected output of the program - c program
Your posts are moderated
Related Questions
wap to read an employee salary and calculate DA,HRA,pf,GROSS,NET conditions:- BASIC DA HRA PF >10000 7% 9% 10% & >20000 9% 11% 15% &

i need a program that generates this output: The highest card wins! Suit Order is: clubs, diamonds, hearts and spades The computers card is the 5 of Spades. The player’s card is t

assume that the first integer read with cin specifies the number of values remaining to be entered. that program should read only one value each time cin is executed .a typical inp

Described the ISA and HASA class relationships. How would you apply each in a class design? A: A specialized class "is" specialization of another class and, thus, has the ISA re

What are header files? What are their uses? - Header files are also known as library files. - They carry two significant things: definitions and prototypes of functions bein

find the area of a curve y=f(x) between x=a and x=b integrate f(x) between limits a and b   #include float start_point, /* GLOBAL VARIABLES */

payment system, in c++ only..just use the printf or scanf.please

Prepare a script for providing Instagram Followers/Likes I need to prepare a panel where my customer able to get Instagram followers or likes automatically. - A panel where I

how to define the structures

Hello, Do you have any idea for programming project to simulate a network attack (threat) mechanism or a defense mechanism. Can I get some suggestions for this. Please include th