C++ Programming Multiple Choice Question - Pointers

This section focuses on the "Pointers" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which of the following is the correct way to declare a pointer ?

A. int *ptr
B. int ptr
C. int &ptr
D. All of the above

View Answer


2. Which of the following gives the [value] stored at the address pointed to by the pointer : ptr?

A. Value(ptr)
B. ptr
C. &ptr
D. *ptr

View Answer


3. A pointer can be initialized with

A. Null
B. Zero
C. Address of an object of same type
D. All of the above

View Answer


4. Choose the right option string* x, y;

A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. Both x and y are pointers to string types
D. none of the above

View Answer


5. Generic pointers can be declared with__________ .

A. auto
B. void
C. asm
D. None of the above

View Answer


6. What is size of generic pointer in c?

A. 0
B. 1
C. 2
D. Null

View Answer


7. Which from the following is not a correct way to pass a pointer to a function?

A. Non-constant pointer to non-constant data
B. A non-constant pointer to constant data
C. A constant pointer to non-constant data
D. All of the above

View Answer


8. What does the following statement mean?

 int (*fp)(char*)

A. Pointer to a pointer
B. Pointer to an array of chars
C. Pointer to function taking a char* argument and returns an int
D. Function taking a char* argument and returning a pointer to int

View Answer


9. 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 above

View Answer


10. Referencing a value through a pointer is called

A. Direct calling
B. Indirection
C. Pointer referencing
D. All of the above

View Answer


11. What is the output of this program?

#include <iostream>
using namespace std;

int main()
    {
        int x = 1, y = 3, z = 5;
        int *lfc[ ] = {&x, &y, &z};
        cout << lfc[1];
        return 0;
    }

A. 1
B. 3
C. 5
D. it will return some random number

View Answer


12. What is the output of this program?

#include <iostream>

using namespace std;
int main()
{
    char lfc[20];
    int i;
    for(i = 0; i < 10; i++)
        *(lfc + i) = 65 + i;
    *(lfc + i) = ' ';
    cout << lfc;
    return(0);   
} 

A. ABCDEFGHIJ
B. AAAAAAAAAA
C. JJJJJJJJ
D. None of the mentioned

View Answer


13. What is the output of this program?

#include <iostream>

using namespace std;
int main()
{
    char *ptr;
    char Str[] = "abcdefg";
    ptr = Str;
    ptr += 5;
    cout << ptr;
    return 0;

}  

A. fg
B. cdef
C. defg
D. abcd

View Answer


14. Which of the following statement is correct about the program given below?

        
Note:Includes all required header files

 using namespace std;
   int main()
   {
       int a[2][4] = {1, 2, 3, 4, 5, 6, 7, 8};
       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
       return 0;
   }  

A. 5 6 7
B. 7 7 7
C. 8 8 8
D. Compile time error

View Answer


15. Which of the following is true about the following program

#include <iostream>

using namespace std;
int main()
{
   int i;
   char *lfc[] = {"C", "C++", "Java", "VBA"};
   char *(*ptr)[4] = &lfc;
   cout << ++(*ptr)[2];
   return 0;
}  

A. ava
B. java
C. c++
D. compile time error

View Answer


16. What will be the output of this program?

        
Note:Includes all required header files

using namespace std;
   int main()
   {
       int find[] = {1, 2, 3, 4};
       int *p = (find + 1);
       cout << *p;
       return 0;
   }

A. 1
B. 2
C. 3
D. 4

View Answer


17. What will be the output of this program?

        
Note:Includes all required header files
using namespace std;
   int main()
   {
       int find[] = {1, 2, 3, 4};
       int *p = (find + 1);
       cout << find;
       return 0;
   }  

A. 1
B. 2
C. address of find
D. 4

View Answer


18. What will be the output of the following program?

       
Note:Includes all required header files

using namespace std;
   int main()
   {
        int find[] = {1, 2, 3, 4};
        int *p = (find + 1);
        cout << *find + 9;
        return 0;
   } 

A. 9
B. 10
C. 11
D. error

View Answer


19. What will be the output of the following program?

        
Note:Includes all required header files

using namespace std; 

   int main ()
   {
       int find[5];
       int * p;
       p = find;  *p = 1;
       p++;  *p = 2;
       p = &find[2];  *p = 3;
       p = find + 3;  *p = 4;
       p = find;  *(p + 4) = 5;
       for (int n = 0; n < 5; n++)
           cout << find[n] << ",";
       return 0;
   }    

A. 1,2,3,4,5,
B. 12345
C. compile error
D. runtime error

View Answer


20. 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)

View Answer


21. The pointer can point to any variable that is not declared with which of these?

A. Const
B. Volatile
C. Both A & B
D. Static

View Answer


22. Which operator returns the address of unallocated blocks in memory?

A. The delete operator
B. The empty operator
C. The new operator
D. All of them

View Answer


23. Which of the following is illegal?

A. int *ip;
B. string s, *sp = 0;
C. int i; double* dp = &i
D. int *pi = 0;

View Answer


24. Which one of the following is not a possible state for a pointer?

A. Hold the address of the specific object
B. Point one past the end of an object
C. Zero
D. Point to a type

View Answer


25. A pointer contains __________.

A. Address of a variable
B. Name of the variable
C. Value of the variable
D. None of the above

View Answer


26. Which of the following are not a member dereferencing operators in CPP? 1. * 2. :: 3. ->* 4. ::* 5. ->

A. Only 1, 2, 4
B. Only 1 and 5
C. Only 2 and 5
D. Only 3,4,5

View Answer


27. What is meaning of following declaration?

int(*p[5])();

A. p is pointer to function.
B. p is array of pointer to function
C. p is pointer to such function which return type is array.
D. p is pointer to array of function.

View Answer


28. What will happen in this code?

int a = 100, b = 200;
int *p = &a, *q = &b
p = q;

A. b is assigned to a
B. p now points to b
C. a is assigned to b
D. q now points to a

View Answer


29. Choose the right option

string* x, y;

A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. Both x and y are pointer to string types
D. None of the above

View Answer


30. Which is true for b, if b is defined as "int *b[10];"?

A. The definition only allocates 10 pointers and does not initialize them
B. Initialization must be done explicitly
C. The definition only allocates 10 pointers and does not initialize them & Initialization must be done explicitly
D. Error

View Answer





Also check :


Discussion



* You must be logged in to add comment.