Friday

C Programming MCQs and Answers

Download C programming Multiple Choice Questions and Answers. C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie. It is an excellent language to learn to program for beginners. 

Sample C Programming Questions & Answers

1. Comment on the output of following code:

  1. #include <stdio.h>

  2. main()

  3. {

  4. char *p = 0;

  5. *p = 'a';

  6. printf("value in pointer p is %c\n", *p);

  7. }

a) It will print a
b) It will print 0
c) Compile time error
d) Run time error

Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)

2. What is the output of this C code?

  1. #include <stdio.h>

  2. main()

  3. {

  4. if (sizeof(int) > -1)

  5. printf("True");

  6. else

  7. printf("False");

  8. }

a) True
b) False

Answer:b
Output:
$ cc pgm.c
$ a.out
False

3. What is the output of this C code?

  1. #include <stdio.h>

  2. main()

  3. {

  4. char *p = "Sanfoundry C-Test";

  5. p[0] = 'a';

  6. p[1] = 'b';

  7. printf("%s", p);

  8. }

a) abnfoundry C-Test
b) Sanfoundry C-Test
c) Compile time error
d) Run time error

Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)

4. What is the output of this C code?

  1. #include <stdio.h>

  2. int main()

  3. {

  4. float f = 0.1;

  5. if (f == 0.1)

  6. printf("True");

  7. else

  8. printf("False");

  9. }

a) True
b) False

Answer:a
Output:
$ cc pgm.c
$ a.out
False

5. What is the output of this C code?

  1. #include <stdio.h>

  2. main()

  3. {

  4. int n = 0, m = 0;

  5. if (n > 0)

  6. if (m > 0)

  7. printf("True");

  8. else

  9. printf("False");

  10. }

a) True
b) False
c) No Output will be printed
d) Run Time Error

Answer:c
Output:
$ cc pgm.c
$ a.out
$


No comments:

Post a Comment