CPP

CPP

Veriable Declaration has 10 Questions
Choose the correct option.
    extern int i;
    int i;

both 1 and 2 declare i
1 declares the variable i and 2 defines i
1 declares and defines i, 2 declares i
1 declares i,2 declares and defines i

Pick the right option

Statement 1:A definition is also a declaration.

Statement 2:An identifier can be declared just once


Statement 1 is true, Statement 2 is false.
Statement 2 is true, Statement 1 is false.
Both are false.
Both are true.
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;

3 and 4 only
2 and 3 only
only 4
2, 3 and 4

Pick the right option

Statement 1:Global values are not initialized by the stream.

 Statement 2:Local values are implicitly initialised to 0.


Statement 1 is true, Statement 2 is false.
Statement 2 is true, Statement 1 is false.
Both are false.
Both are true.
What is the output of this program?
  1.     #include 
  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.     }

2035655065
2035655035
2035635065
none of the mentioned
Can two functions declare variables(non static) with the same name.

No
Yes
Yes, but not a very efficient way to write programs.
No, it gives a runtime error.
What is the output of this program?
  1.     #include 
  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.     }

234
111
123
235
What is the output of this program?
  1.     #include 
  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.     }

0123456789
123456789
0
error

Identify the incorrect statements.

int var = 10;

int *ptr = &(var + 1); //statement 1

int *ptr2 = &var; //statement 2

&var = 40; //statement 3


Statement 1 and 2 are wrong
Statement 2 and 3 are wrong
Statement 1 and 3 are wrong
All the three are wrong

Identify the type of the variables.

 typedef char* CHAR;

 CHAR p,q;


char*
char
CHAR
unknown