github

Made bySaurav Hathi

MCQ Test C/C++: Pointers

Q1:

Below some C++ statements are given. Which of the statements is wrong?

int var = 10;
int *ptr = &(var + 1); //statement 1
int *ptr2 = &var; //statement 2
&var = 40; //statement 3

Tags:
Section:
Core Programming
Options:
Q2:

If we execute the following 2 statements in C++, then what type of variables are p and q?
typedef char* CHAR;
CHAR p,q

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this C code?

#include <stdio.h>

int main()

{

char *p = NULL;

char *q = 0;

if (p)

printf(" p ");

else

printf("nullp");

if (q)

printf("q\n");

else

printf(" nullq\n");

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 10;

void *p = &i;

printf("%d\n", (int)*p);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q5:

Which statement is correct about the following declaration in C/C++?

int *ptr, p;

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this C code?

#include <stdio.h>

int main()

{

int *ptr, a = 10;

ptr = &a;

*ptr += 1;

printf("%d,%d\n", *ptr, a);

}

Tags:
Section:
Core Programming
Options:
Q7:

Which statement is correct about the following declaration in C/C++?

const int *ptr;

Tags:
Section:
Core Programming
Options:
Q8:

Which operator is indirection operator in C/C++?

Tags:
Section:
Core Programming
Options:
Q9:

In C/C++, which statement doesn’t assign null value into ptr if a=0?

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this C code?

#include <stdio.h>

int x = 0;

int main()

{

int *ptr = &x;

printf("%p\n", ptr);

x++;

printf("%p\n ", ptr);

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this C code?

#include <stdio.h>

int x = 0;

int main()

{

int *const ptr = &x;

printf("%p\n", ptr);

ptr++;

printf("%p\n ", ptr);

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this C code?

#include <stdio.h>

int main()

{

int x = 0;

int *ptr = &5;

printf("%p\n", ptr);

}

Tags:
Section:
Core Programming
Options: