C Programming Questions and Answers – Pointers and Addresses – 2

«
»

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

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

advertisement

1. Which is an indirection operator among the following?
a) &
b) *
c) ->
d) .
View Answer

Answer: b
Explanation: None.

2. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;)?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

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

a) Same address
b) Different address
c) Compile time error
d) Varies
View Answer

Answer: a
Explanation: None.
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     int x = 0;
  3.     void main()
  4.     {
  5.         int *const ptr = &x;
  6.         printf("%p\n", ptr);
  7.         ptr++;
  8.         printf("%p\n ", ptr);
  9.     }

a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8
View Answer

Answer: b
Explanation: None.
advertisement

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

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

a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
View Answer

Answer: a
Explanation: None.

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

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

a) 5
b) Address of 5
c) Nothing
d) Compile time error
View Answer

Answer: d
Explanation: None.

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

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

a) Address of x
b) Junk value
c) 0
d) Run time error
View Answer

Answer: c
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.