My Report

C++ Array Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C++ code?

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

2. What will be the output of the following C++ code?

  
   #include <iostream>
   using namespace std;
   int main()
   {
       int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
       return 0;
   }

3. What will be the output of the following C++ code?

   #include <iostream>
   using namespace std;
   int main()
   {
       int arr[] = {4, 5, 6, 7};
       int *p = (arr + 1);
       cout << arr;
       return 0;
   }

4. What will be the output of the following C++ code?

  
   #include <iostream>
   using namespace std;
   int main()
   {
       int arr[] = {4, 5, 6, 7};
       int *p = (arr + 1);
       cout << *p;
       return 0;
   }

5. What is the meaning of the following declaration?

int(*p[5])();

6. What is size of generic pointer in C++ (in 32-bit platform)?

7. What will be the output of the following C++ code?

  
   #include <iostream>
   using namespace std;
   int main()
   {
        int arr[] = {4, 5, 6, 7};
        int *p = (arr + 1);
        cout << *arr + 9;
        return 0;
   }

8. What will be the output of the following C++ code?

  
   #include <iostream>
   using namespace std;
   int main ()
   {
       int numbers[5];
       int * p;
       p = numbers;  *p = 10;
       p++;  *p = 20;
       p = &numbers[2];  *p = 30;
       p = numbers + 3;  *p = 40;
       p = numbers;  *(p + 4) = 50;
       for (int n = 0; n < 5; n++)
           cout << numbers[n] << ",";
       return 0;
   }

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.