Pointers C++ MCQ

Errorlogger
0
1. 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

Answer:c


2. The operator used for dereferencing or indirection is ____
a) *
b) &
c) ->
d) –>>

Answer:a


3. 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 mentioned

Answer:a


4. 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 tye

Answer:d


5. Which of the following is illegal?
a) int *ip;
b) string s, *sp = 0;
c) int i; double* dp = &i;
d) int *pi = 0;

Answer:c


6. 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

Answer:b


7. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5, b = 10, c = 15;
  6.         int *arr[ ] = {&a, &b, &c};
  7.         cout << arr[1];
  8.         return 0;
  9.     }
a) 5
b) 10
c) 15
d) it will return some random number

Answer:d


8. 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


9. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         char arr[20];
  6.         int i;
  7.         for(i = 0; i < 10; i++)
  8.             *(arr + i) = 65 + i;
  9.         *(arr + i) = '\0';
  10.         cout << arr;
  11.         return(0);
  12.     }
a) ABCDEFGHIJ
b) AAAAAAAAAA
c) JJJJJJJJ
d) none of the mentioned

Answer:a


10. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         char *ptr;
  6.         char Str[] = "abcdefg";
  7.         ptr = Str;
  8.         ptr += 5;
  9.         cout << ptr;
  10.         return 0;
  11.     }
a) fg
b) cdef
c) defg
d) abcd

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 !