C++ Programming MCQ - Pointers

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





Also check :


Discussion


* You must be logged in to add comment.