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

Assignment Help:

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)?


Related Discussions:- Expected output of the program - c program

ASCII, A string S is said to be "Super ASCII", if it contains the character...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

multithreaded server, Implement a multithreaded server that can be used as...

Implement a multithreaded server that can be used as a proxy server to access some designated file (say it reflects the proxy copy of two file1.txt, file2.txt). Now use a client to

Make c code works equally on 64 and 32 bit, Project Description: I have ...

Project Description: I have a code that works different on 64 bit and 32 bit system. Code is relative to some crypt functions, similar, but not equal to: I have to move fr

#podavan string, ##question.A Padovan string P(n) for a natural number n is...

##question.A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string co   program in jav

Subrotine assembly language, You have to write a subroutine (assembly langu...

You have to write a subroutine (assembly language code using NASM) for the following equation.

Arrays within a class, A r r a y s w i t h i n a c l a s s:...

A r r a y s w i t h i n a c l a s s: I t i s j u s t d ecl a r i n g o r c on s t ru c ti n g a d e r i v e d t

Structures, please answer the question of following Write a function that c...

please answer the question of following Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? B

What is a template in c++, Templates permit to create generic functions tha...

Templates permit to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd