Declaration C++ MCQ

Errorlogger
0
1. Choose the correct option.
    extern int i;
    int i;
a) both 1 and 2 declare i
b) 1 declares the variable i and 2 defines i
c) 1 declares and defines i, 2 declares i
d) 1 declares i,2 declares and defines i

Answer:d


2. Pick the right option
    Statement 1:A definition is also a declaration.
    Statement 2:An identifier can be declared just once.
a) Statement 1 is true, Statement 2 is false.
b) Statement 2 is true, Statement 1 is false.
c) Both are false.
d) Both are true.

Answer: b


3. Which of the given statements are false.
1. extern int func;
2. extern int func2(int,int);
3. int func2(int,int);
4. extern class foo;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4

Answer:c


4. Pick the right option
    Statement 1:Global values are not initialized by the stream.
    Statement 2:Local values are implicitly initialised to 0.
a) Statement 1 is true, Statement 2 is false.
b) Statement 2 is true, Statement 1 is false.
c) Both are false.
d) Both are true.

Answer:c


5. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int g = 100;
  4.     int main()
  5.     {
  6.         int a;
  7.         {
  8.             int b;
  9.             b = 20;
  10.             a = 35;
  11.             g = 65;
  12.            cout << b << a << g;
  13.         }
  14.         a = 50;
  15.         cout << a << g;
  16.         return 0;
  17.     }
a) 2035655065
b) 2035655035
c) 2035635065
d) none of the mentioned

Answer:a


6. Can two functions declare variables(non static) with the same name.
a) No
b) Yes
c) Yes, but not a very efficient way to write programs.
d) No, it gives a runtime error.

Answer:c


7. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     void addprint()
  4.     {
  5.         static int s = 1;
  6.         s++;
  7.         cout << s;
  8.     }
  9.     int main()
  10.     {
  11.         addprint();
  12.         addprint();
  13.         addprint();
  14.         return 0;
  15.     }
a) 234
b) 111
c) 123
d) 235

Answer:a


8. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 10;
  6.         if (a < 10) {
  7.             for (i = 0; i < 10; i++)
  8.                cout << i;
  9.         }
  10.         else {
  11.             cout << i;
  12.         }
  13.         return 0;
  14.     }
a) 0123456789
b) 123456789
c) 0
d) error

Answer:d


9. Identify the incorrect statements.
    int var = 10;
    int *ptr = &(var + 1); //statement 1
    int *ptr2 = &var; //statement 2
    &var = 40; //statement 3
a) Statement 1 and 2 are wrong
b) Statement 2 and 3 are wrong
c) Statement 1 and 3 are wrong
d) All the three are wrong

Answer:c


10. Identify the type of the variables.
    typedef char* CHAR;
    CHAR p,q;
a) char*
b) char
c) CHAR
d) unknown

Answer:a
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !