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:
#include <stdio.h>
main()
{
char *p = 0;
*p = 'a';
printf("value in pointer p is %c\n", *p);
}
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?
#include <stdio.h>
main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}
a) True
b) False
Answer:b
Output:
$ cc pgm.c
$ a.out
False
3. What is the output of this C code?
#include <stdio.h>
main()
{
char *p = "Sanfoundry C-Test";
p[0] = 'a';
p[1] = 'b';
printf("%s", p);
}
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?
#include <stdio.h>
int main()
{
float f = 0.1;
if (f == 0.1)
printf("True");
else
printf("False");
}
a) True
b) False
Answer:a
Output:
$ cc pgm.c
$ a.out
False
5. What is the output of this C code?
#include <stdio.h>
main()
{
int n = 0, m = 0;
if (n > 0)
if (m > 0)
printf("True");
else
printf("False");
}
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