C Programming Questions and Answers – Character Pointers and Functions – 1

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

Pre-requisite for C Character Pointers and Functions 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.         char *str = "hello, world\n";
  5.         char *strc = "good morning\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }

a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strc[] = "good morning india\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }

a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello, world!!\n";
  5.         char strc[] = "good morning\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }

a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
View Answer

Answer: c
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello, world\n";
  5.         str[5] = '.';
  6.         printf("%s\n", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char str[] = "hello, world";
  5.         str[5] = '.';
  6.         printf("%s\n", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %d\n", sizeof(str), sizeof(strary));
  7.         return 0;
  8.     }

a) 11 11
b) 12 12
c) 4 12
d) 4 11
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.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %d\n", strlen(str), strlen(strary));
  7.         return 0;
  8.     }

a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void f(char *k)
  3.     {
  4.         k++;
  5.         k[2] = 'm';
  6.         printf("%c\n", *k);
  7.     }
  8.     void main()
  9.     {
  10.         char s[] = "hello";
  11.         f(s);
  12.     }

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

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void fun(char *k)
  3.     {
  4.         printf("%s", k);
  5.     }
  6.     void main()
  7.     {
  8.         char s[] = "hello";
  9.         fun(s);
  10.     }

a) hello
b) Run time error
c) Nothing
d) h
View Answer

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