C Programming Questions and Answers – Pointers to Pointers – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Pointers to Pointers – 2”.

Pre-requisite for C Pointers to Pointers MCQ set: Video Tutorial on C Pointers.

advertisement

1. What substitution should be made to //-Ref such that ptr1 points to variable c in the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1, b = 2, c = 3;
  5.         int *ptr1 = &a;
  6.         int **sptr = &ptr1;
  7.         //-Ref
  8.     }

a) *sptr = &c;
b) **sptr = &c;
c) *ptr1 = &c;
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

2. Which of the following declaration will result in run-time error?
a) int **c = &c;
b) int **c = &*c;
c) int **c = **c;
d) none of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

3. Comment on the output of the following C code.

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 10;
  5.         int **c -= &&a;
  6.     }

a) You cannot apply any arithmetic operand to a pointer
b) We don’t have address of an address operator
c) We have address of an address operator
d) None of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 5;
  5.         int *p = &k;
  6.         int **m  = &p;
  7.         printf("%d%d%d\n", k, *p, **m);
  8.     }

a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
View Answer

Answer: a
Explanation: None.

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 5;
  5.         int *p = &k;
  6.         int **m  = &p;
  7.         printf("%d%d%d\n", k, *p, **p);
  8.     }

a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 5;
  5.         int *p = &k;
  6.         int **m  = &p;
  7.         **m = 6;
  8.         printf("%d\n", k);
  9.     }

a) 5
b) Run time error
c) 6
d) Junk
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int a[3] = {1, 2, 3};
  5.         int *p = a;
  6.         int *r = &p;
  7.         printf("%d", (**r));
  8.     }

a) 1
b) Compile time error
c) Address of a
d) Junk value
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.