Pointers into Arrays C++ MCQ

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

Answer:b


2. What is size of generic pointer in c?
a) 0
b) 1
c) 2
d) Null

Answer:c


3. What is the output of this program?
  1.    #include <iostream>
  2.    using namespace std;
  3.    int main()
  4.    {
  5.        int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
  6.        cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
  7.        return 0;
  8.    }
a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error

Answer:b


4. What is the output of this program?
  1.    #include <iostream>
  2.    using namespace std;
  3.    int main()
  4.    {
  5.        int i;
  6.        char *arr[] = {"C", "C++", "Java", "VBA"};
  7.        char *(*ptr)[4] = &arr;
  8.        cout << ++(*ptr)[2];
  9.        return 0;
  10.    }
a) ava
b) java
c) c++
d) compile time error

Answer:a


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

Answer:b


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

Answer:c


7. What is the output of this program?
  1.    #include <iostream>
  2.    using namespace std;
  3.    int main ()
  4.    {
  5.        int numbers[5];
  6.        int * p;
  7.        p = numbers;  *p = 10;
  8.        p++;  *p = 20;
  9.        p = &numbers[2];  *p = 30;
  10.        p = numbers + 3;  *p = 40;
  11.        p = numbers;  *(p + 4) = 50;
  12.        for (int n = 0; n < 5; n++)
  13.            cout << numbers[n] << ",";
  14.        return 0;
  15.    }
a) 10, 20, 30, 40, 50
b) 1020304050
c) compile error
d) runtime error

Answer:a


8. What is the output of this program?
  1.    #include <iostream>
  2.    using namespace std;
  3.    int main()
  4.    {
  5.         int arr[] = {4, 5, 6, 7};
  6.         int *p = (arr + 1);
  7.         cout << *arr + 9;
  8.         return 0;
  9.    }
a) 12
b) 5
c) 13
d) error

Answer:c
Tags

Post a Comment

1Comments

Post a Comment

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

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