TEST YOUR C++ SKILLS

TEST YOUR KNOWLEDGE...

1) What is the output of the following program? 
    int main()
    {
    int a = 5; 
    float b;    
    cout << sizeof(++a + b);   
    cout << a;      
    return 0;
    } 
    
a) 2 6 
b) 4 6   
c) 2 5   
d) 4 5 

Answer:d  

2) What is meaning of following declaration?    
                     int(*ptr[5])(); 

a) ptr is pointer to function. 
b) ptr is array of pointer to function.
c) ptr is pointer to such function which return type is array.
d) ptr is pointer to array of function.

Answer:b   

3) What will happen when the handler is not found for exception? 

a) Calls the standard library function terminate()  
b) raise an error 
c) executes the remaining block 
d) none of the mentioned  

Answer:a  

4)  Which one is used to refer to program elements in any translation units? 

a) internal linkage 
b) external linkage  
c) no linkage 
d) none of the mentioned 

Answer:b   

5) What is the use of no linkage?

a) make the entity visible to other programs 
b) make the entity visible to other blocks in the same program.  
c) make the entity visible only to that block
d) none of the mentioned 

Answer:c  

6) What is the output of this program?    

    int main()
   { 
          int a = 5, b = 10, c = 15;      
          int *arr[ ] = {&a, &b, &c};    
          cout << arr[1]; 
          return 0;
   }

  a)   5        b) 10      c) 15       d) it will return some random number 

Answer:d  

7) When struct is used instead of the keyword class means, what will happen in the program?  

a) access is public by default
b) access is private by default
c) access is protected by default 
d) none of the mentioned 

Answer:a   

8) Pick out the correct statement.  

a) A derived class’s constructor cannot explicitly invokes its base class’s constructor. 
b) A derived class’s destructor cannot invoke its base class’s destructor. 
c) A derived class’s destructor can invoke its base class’s destructor. 
d) None of the mentioned 

Answer:b  

9) Which constructor will initialize the base class data member?

a) derived class
b) base class
c) class
d) None of the mentioned

Answer:b

10)  Which is also called as abstract class?

a) virtual function
b) pure virtual function
c) derived class
d) None of the mentioned

Answer:b

11) What is the output of this program?
     int main ()
    {
        string str ("Test string");
        for ( string :: iterator it = str.begin(); it != 5; ++it)
        cout << *it;  
        return 0;
    }
 a) Test      b) string      c) Test string       d) Error

Answer:d

12) What do 1024UL and 4Lu represent?

a) unsigned long and long respectively
b) long and unsigned long respectively
c) both unsigned long
d) both long

Answer:c

13) The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is

a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)

Answer:c  

14) What is the output of this program?
     int main()
    {
      int a = 5, b = 10, c = 15;
      int *arr[ ] = {&a, &b, &c};  
      cout << arr[1];
      return 0;
    }

a) 5     b) 10     c) 15     d) it will return some random number

Answer:d

15) What is size of generic pointer in c?

a) 0 b) 1 c) 2 d) Null

Answer:c

16) What are the parts of the literal constants?

a) integer numerals
b) floating-point numerals
c) strings and boolean values
d) all of the mentioned

Answer:d

17) Regarding following statement which of the statements is true?
                                     const int a = 100;
a) Declares a variable a with 100 as its initial value
b) Declares a construction a with 100 as its initial value
c) Declares a constant a whose value will be 100
d) Constructs an integer type variable with a as identifier and 100 as value

Answer:c

18) When does the void pointer can be dereferenced?

a) when it doesn’t point to any value
b) when it cast to another type of object
c) using delete keyword
d) none of the mentioned

Answer:b

19) What is the output of this program?
     int func(void *Ptr);
     int main()
     {
          char *Str = "abcdefghij";
          func(Str);  
          return 0;
     }
     int func(void *Ptr)
    {
         cout << Ptr;
         return 0;
    }

a) abcdef  b) abcdefghij  c) compile time error  d) runtime error

Answer:c

20) A void pointer cannot point to which of these?

a) methods in c++   b) class member in c++   c) both a & b    d) none of the mentioned

Answer:b

21) What will happen when the structure is declared?
a) it will not allocate any memory
b) it will allocate the memory
c) it will be declared and initialized
d) none of the mentioned

Answer:a

22) Which of the following is a properly defined structure?

a) struct {int a;}
b) struct a_struct {int a;}
c) struct a_struct int a;
d) struct a_struct {int a;};

Answer:d

23) Comment on the following C code?
       printf("%d", sizeof(strlen("HELLOWORLD")));

a) Output, 4           b) Output, 10           c) Output, 16           d) Error, sizeof cannot evaluate size of a function.

Answer: a

24) The standard header _______ is used for variable list arguments (…) in C.

a) <stdio.h >            b) <stdlib.h>            c) <math.h>            d) <stdarg.h>

Answer: d

25) What is the output of this program?
      int main()
      {
          string s = "a long string";  
          s.insert(s.size() / 2, " * ");
          cout << s << endl;
          return 0;
      }

a) a long* string   b) a long st*ring  c) Depends on compiler   d) None of the mentioned

Answer:c  

Comments