C Programming Questions and Answers – Pointers and Arrays – 1

«
»

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

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

advertisement

1. 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.         printf("%p\t%p", p, a);
  7.     }

a) Same address is printed
b) Different address is printed
c) Compile time error
d) Nothing
View Answer

Answer: a
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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

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

a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
View Answer

Answer: b
Explanation: None.
advertisement

3. 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[0], s[1]);
  7.     }

a) Run time error
b) h h
c) h e
d) h l
View Answer

Answer: c
Explanation: None.
advertisement

4. 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 + 3),  s[1]);
  7.     }

a) h e
b) l l
c) l o
d) l e
View Answer

Answer: d
Explanation: None.

5. 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", 1[p], s[1]);
  7.     }

a) h h
b) Run time error
c) l l
d) e e
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void foo( int[] );
  3.     int main()
  4.     {
  5.         int ary[4] = {1, 2, 3, 4};
  6.         foo(ary);
  7.         printf("%d ", ary[0]);
  8.     }
  9.     void foo(int p[4])
  10.     {
  11.         int i = 10;
  12.         p = &i;
  13.         printf("%d ", p[0]);
  14.     }

a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%d\n", p[-2]);
  7.     }

a) 1
b) 2
c) Compile time error
d) Some garbage value
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%d %d\n", p[-2], ary[*p]);
  7.     }

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

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

advertisement
advertisement

Leave a Comment

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 & technical discussions at Telegram SanfoundryClasses.