Explore topic-wise MCQs in C Programming.

This section includes 18 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

In the following C program everytime program is run different numbers are generated.
#include <stdio.h>
int main()
{
srand(time(NULL));
printf("%d n", rand());
return 0;
}

A. Depends on the platform
B. Depends on the compiler
C. True
D. False
E. None of these
Answer» D. False
2.

In the below program everytime program is run different numbers are generated.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d n", rand());
return 0;
}

A. Depends on the platform
B. True
C. False
D. Depends on the compiler
E. None of these
Answer» D. Depends on the compiler
3.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
srand(time(NULL));
printf("%d n", rand());
return 0;
}

A. A double in the range 0 to 1
B. A float in the range 0 to 1
C. Compilation Error
D. An integer in the range 0 to RAND_MAX
E. None of these
Answer» E. None of these
4.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf("%d n", srand(12000))
return 0;
}

A. A double in the range 0 to 12000
B. Compilation Error
C. An integer in the range 0 to 12000
D. A float in the range 0 to 1
E. None of these
Answer» C. An integer in the range 0 to 12000
5.

What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
srand(1000);
printf("%d n", rand());
return 0;
}

A. A double in the range 0 to 1
B. Compilation Error
C. A float in the range 0 to 1
D. An integer in the range 0 to RAND_MAX
E. None of these
Answer» E. None of these
6.

What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d n", rand() % 500);
return 0;
}

A. 500
B. Compilation Error
C. Garbage value
D. An integer between 0-499 including 0 and 499
E. None of these
Answer» E. None of these
7.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
int num;
scanf("%d", &num);
ungetc(num, stdin);
scanf("%d", &num);
printf("%d n", num);
return 0;
}

A. Whatever is typed by the user first time
B. Undefined behaviour
C. Compilation Error
D. Whatever is typed by the user second time
E. None of these
Answer» C. Compilation Error
8.

Which of the following is the correct syntax for calling function ungetc?
Assume int c and FILE *fp

A. ungetc(*fp,c);
B. ungetc(c,*fp);
C. ungetc(c, fp);
D. ungetc(fp, c);
E. None of these
Answer» D. ungetc(fp, c);
9.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
int main()
{
unsigned int num = 15;
printf("%f n", fabs(num));
return 0;
}

A. Compilation Error
B. Undefined behaviour
C. 15
D. 15.000000
E. None of these
Answer» E. None of these
10.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
int main()
{
int n = 90;
printf("%f n", sin(n));
return 0;
}

A. Undefined behaviour
B. 1.000000
C. Compilation Error
D. 0.893997
E. None of these
Answer» E. None of these
11.

What will be the output of the following C statement?
int ungetc(int c, FILE *fp)

A. file
B. fp
C. Nothing
D. Either c or EOF for an error
E. None of these
Answer» E. None of these
12.

What does the ungetc function return for the following C expression?
ungetc(c, fp);//where declarations are int c and FILE *fp

A. Either returns character c or returns EOF for an error
B. It returns EOF for an error
C. It returns character c
D. Both returns EOF for an error and returns character c
E. None of these
Answer» B. It returns EOF for an error
13.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
void main()
{
int n = sqrt(16);
printf("%d n", n);
}

A. Compilation Error
B. 16
C. 4
D. Garbage value
E. None of these
Answer» D. Garbage value
14.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
void main()
{
int n = fabs(-65);
printf("%d n", n);
}

A. -65
B. Compilation Error
C. Garbage value
D. 65
E. None of these
Answer» E. None of these
15.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
int main()
{
int n = 10;
printf("%f n", log10(n));
return 0;
}

A. 10
B. Compilation Error
C. 2.302585
D. 1.000000
E. None of these
Answer» E. None of these
16.

What will be the output of the following C code considering user typed ajit?
#include <stdio.h>
int main()
{
char num[26];
fgets(num, 25, stdin);
ungetc(num[0], stdin);
printf("%s n", num);
return 0;
}

A. Undefined behaviour
B. jit
C. Compilation Error
D. ajit
E. None of these
Answer» E. None of these
17.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char num[25];
fgets(num, 24, stdin);
ungetc(num[0], stdin);
scanf("%s", num);
printf("%s n", num);
return 0;
}

A. First character of whatever user types first time and whatever user types second time
B. Whatever string user types first time
C. Whatever string user types second time
D. Compilation Error
E. None of these
Answer» B. Whatever string user types first time
18.

What will be the output of the following C code?
#include <stdio.h>
#include <math.h>
void main()
{
int num = pow(4, 2);
printf("%d n", num);
}

A. 4
B. 2
C. 16
D. Garbage value
E. None of these
Answer» D. Garbage value