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.

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?

  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.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.