My Report

C++ Pointer Test – 1


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 happen in the following C++ code snippet?

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

2. The operator used for dereferencing or indirection is ____

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

    #include <iostream>
    using namespace std;
    int main()
    {
        char arr[20];
        int i;
        for(i = 0; i < 10; i++)
            *(arr + i) = 65 + i;
        *(arr + i) = '\0';
        cout << arr;
        return(0);
    } 

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

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

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

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

7. What does the following statement mean?

int (*fp)(char*)

8. Which of the following is illegal?

9. Choose the right option.

string* x, y;

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

    #include <iostream>
    using namespace std;
    int main()
    {
        int a = 5, b = 10, c = 15;
        int *arr[ ] = {&a, &b, &c};
        cout << arr[1];
        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.