C Programming Questions and Answers – Address Arithmetic – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Address Arithmetic – 1”.

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

advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         double *ptr = (double *)100;
  5.         ptr = ptr + 2;
  6.         printf("%u", ptr);
  7.     }

a) 102
b) 104
c) 108
d) 116
View Answer

Answer: d
Explanation:None
advertisement
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int *p = (int *)2;
  5.         int *q = (int *)3;
  6.         printf("%d", p + q);
  7.     }

a) 2
b) 3
c) 5
d) Compile time error
View Answer

Answer: d
Explanation: None.
advertisement

3. Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a – b
c) a * b
d) a / b
View Answer

Answer: b
Explanation: None.

4. What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
View Answer

Answer: c
Explanation: None.
advertisement

5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
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.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%c\t%c", *(p + 1), s[1]);
  7.     }

a) h e
b) e l
c) h h
d) e e
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.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%c\t%c", *p, s[1]);
  7.     }

a) e h
b) Compile time error
c) h h
d) h e
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *n = "cjn";
  6.         char *p = s + n;
  7.         printf("%c\t%c", *p, s[1]);
  8.     }

a) h e
b) Compile time error
c) c o
d) h n
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.