Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Pointers to Pointers

C Programming Questions and Answers – Pointers to Pointers

 

1.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

printf(“%d%d%d\n”, k, *p, **m);

}

a) 5 5 5

b) 5 5 junk value

c) 5 junk junk

d) Run time error

View Answer

Answer:a

 

2.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

printf(“%d%d%d\n”, k, *p, **p);

}

a) 5 5 5

b) 5 5 junk value

c) 5 junk junk

d) Compile time error

View Answer

Answer:d

 

3.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

**m = 6;

printf(“%d\n”, k);

}

a) 5

b) Compile time error

c) 6

d) Junk

View Answer

Answer:c

 

 

4.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int a[3] = {1, 2, 3};

int *p = a;

int *r = &p;

printf(“%d”, (**r));

}

a) 1

b) Compile time error

c) Address of a

d) Junk value

View Answer

Answer:b

 

5.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int a[3] = {1, 2, 3};

int *p = a;

int **r = &p;

printf(“%p %p”, *r, a);

}

a) Different address is printed

b) 1 2

c) Same address is printed.

d) 1 1

View Answer

Answer:c

 

6.How many number of pointer (*) does C have against a pointer variable declaration?

a) 7

b) 127

c) 255

d) No limits.

View Answer

Answer:d

 

7.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int a = 1, b = 2, c = 3;

int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;

int **sptr = &ptr1; //-Ref

*sptr = ptr2;

}

a) ptr1 points to a

b) ptr1 points to b

c) sptr points to ptr2

d) None of the mentioned

View Answer

Answer:b

 

8.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int a[3] = {1, 2, 3};

int *p = a;

int **r = &p;

printf(“%p %p”, *r, a);

}

a) Different address is printed

b) 1 2

c) Same address is printed.

d) 1 1

View Answer

Answer:c

 

9.What substitution should be made to //-Ref such that ptr1 points to variable C?

 

#include <stdio.h>

int main()

{

int a = 1, b = 2, c = 3;

int *ptr1 = &a;

int **sptr = &ptr1;

//-Ref

}

a) *sptr = &c;

b) **sptr = &c;

c) *ptr1 = &c;

d) None of the mentioned.

View Answer

Answer:a

 

10.Which of the following declaration throw run-time error?

a) int **c = &c;

b) int **c = &*c;

c) int **c = **c;

d) None of the mentioned

View Answer

Answer:d

 

11.Comment on the output of this C code?

 

#include <stdio.h>

int main()

{

int a = 10;

int **c -= &&a;

}

a) You cannot apply any arithmetic operand to a pointer.

b) We don’t have address of an address operator

c) Both (a) and (b)

d) None of the mentioned.

View Answer

Answer:b

 

 

12.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

printf(“%d%d%d\n”, k, *p, **m);

}

a) 5 5 5

b) 5 5 junk value

c) 5 junk junk

d) Compile time error

View Answer

Answer:a

 

13.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

printf(“%d%d%d\n”, k, *p, **p);

}

a) 5 5 5

b) 5 5 junk value

c) 5 junk junk

d) Compile time error

View Answer

Answer:d

 

14.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 5;

int *p = &k;

int **m  = &p;

**m = 6;

printf(“%d\n”, k);

}

a) 5

b) Run time error

c) 6

d) Junk

View Answer

Answer:c

 

15.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int a[3] = {1, 2, 3};

int *p = a;

int *r = &p;

printf(“%d”, (**r));

}

a) 1

b) Compile time error

c) Address of a

d) Junk value

View Answer

Answer:b

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button