C Programming MCQ
C Programming MCQ
Ans: A
2.)What is sizeof() in C?
a)Operator
b)Function
c)Macro
d)None of these
Ans: A
Ans: A
return 0;
}
a)0 0
b)2 2
c)4 4
d)Undefined
Ans: C
Ans:C
a)3.33
b)3.0
c)3
d)0
Ans: C
a)10.5
b)10
c)0
d)Compilation Error
Ans: B
Ans: D
a)0
b)16
c)Undefined i
d)Any other Compilation Error
Ans: B
a)320
b)60
c)160
d)64
Ans: D
Ans: A
Ans: A
Ans: C
Ans: C
void main()
{
for(; ;);
for(; ;);
printf("Hello");
Ans: C
void main()
{
for(; ;)
for(; ;)
printf("Hello");
}
a.) Compilation Error
b.) Runtime Error
c.) Hello is printed one time
d.) Hello is printed infinite times
Ans: D
Ans: B
19)
What is the meaning of below lines?
void sum (int, int);
Ans: B
(A) math.h
(B) mathio.h
(C) string.h
(D) ctype.h
Ans: B
Ans: B
22.)What is storage class for variable A in below code?
void main()
{
int A;
A = 10;
printf("%d", A);
}
(A) extern
(B) auto
(C) register
(D) static
Ans: B
Ans: B
Ans: D
25.)#include<stdio.h>
int main()
{
int a = 10;
printf("%d", a);
int a = 20;
printf("%d",a);
return 0;
}
(A) 1020
(B) 1010
(C) 2020
(D) Error: Redeclartion of a
Ans: D
26.)#include<stdio.h>
int a = 20;
int main()
{
int a = 10;
printf("%d", ::a);
return 0;
}
(A) 10
(B) 20
(C) ::20
(D) ::10
Ans: B
27.)#include<stdio.h>
int a = 20;
int main()
{
int a = 10;
printf("%d", a);
return 0;
}
(A) 20
(B) Ambiguity Error
(C) 10
(D) 0
Ans: C
28.)#include<stdio.h>
int main()
{
int __a = 10;
printf("%d",__a);
return 0;
}
(A) Compilation Error
(B) 10
(C) __10
(D) __a
Ans: B
29.)
#include<stdio.h>
int main()
{
int 2a = 10;
printf("%d",2a);
return 0;
}
(A) 10
(B) 20
(C) 2a
(D) Compilation Error
Ans: D
30.)#include<stdio.h>
int main()
{
int @a = 10;
printf("%d",@a);
return 0;
}
(A) 10
(B) @10
(C) 10@
(D) Compilation Error
Ans: D
31.)#include <stdio.h>
int main()
{
int a = 10, b = 20;
if(a=b)
{
printf("Easy");
}
else
{
printf("Hard");
}
return 0;
}
(A) Easy
(B) Hard
(C) EasyHard
(D) Error in program
Ans: A
32.)Which gcc flag is used to generate debug information for any binary file?
(A) gcc -g
(B) gcc -a
(C) gcc -e
(D) gcc -b
Ans: A
Ans: B
34.)What is the job of Assembler in C programming?
Ans: B
35.)
What should be the output of below program ?
##include<stdio.h>
int main()
{
printf("tcs_codeninja");
return 0;
}
(A) tcs_codeninja
(B) No output
(C) Compilation Error in preprocessing
(D) None of above
Ans: C
Ans: D
#include <stdio.h>
void main()
{
char *str = "";
do
printf("hello");
} while (str);
a) Nothing
c) Varies
Ans: D
#include <stdio.h>
void main()
int i = 0;
i++;
printf("hi\n");
while (i < 8)
i++;
printf("hello\n");
Ans: D
a) for
b) while
c) do-while
Ans: D
40.) How many times while loop condition is tested in the following C code snippets, if i is
initialized to 0 in both the cases?
while (i < n)
i++;
————-
do
i++;
b) n, n+1
c) n+1, n
d) n+1, n+1
Ans: D
#include <stdio.h>
int main()
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
c) False
d) Compiler dependent
Ans: C
#include <stdio.h>
int main()
int i = 0, j = 0;
i++;
j++;
a) 5, 5
b) 5, 10
c) 10, 10
d) Syntax error
Ans: C
43.) Which loop is most suitable to first perform the operation and then test the condition?
a) for loop
b) while loop
c) do-while loop
Ans: C
44.) What will be the output of the following C code?
#include <stdio.h>
int main()
goto l1;
l1:goto l2;
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Ans: A
#include <stdio.h>
int main()
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
Ans: B
#include <stdio.h>
int main()
goto l1;
void foo()
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
Ans: D
#include <stdio.h>
int main()
int i = 0, j = 0;
while (i < 2)
l1 : i++;
while (j < 3)
printf("Loop\n");
goto l1;
a) Loop Loop
b) Compilation error
d) Infinite Loop
Ans: D
48.) What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0, j = 0;
i++;
while (j < 3)
printf("loop\n");
goto l1;
a) loop loop
b) Compilation error
d) Infinite loop
Ans: B
int main()
int i = 0, j = 0;
i++;
while (j < 3)
printf("loop\n");
goto l1;
a) loop loop
b) compilation error
d) infinite loop
Ans: A
#include <stdio.h>
void main()
{
int i = 0;
if (i == 0)
goto label;
label: printf("Hello");
a) Nothing
b) Error
c) Infinite Hello
d) Hello
Ans: D
#include <stdio.h>
void main()
int i = 0, k;
if (i == 0)
goto label;
printf("hi\n");
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
Ans: A
#include <stdio.h>
void main()
int i = 0, k;
if (i == 0)
goto label;
a) 0
b) Infinite 0
c) Nothing
d) Error
Ans: B
#include <stdio.h>
void main()
m();
void m()
printf("hi");
a) hi
c) Nothing
d) Varies
Ans: B
#include <stdio.h>
void main()
m();
}
void m()
printf("hi");
m();
b) hi
c) Infinite hi
d) Nothing
Ans: C
#include <stdio.h>
void main()
static int x = 3;
x++;
if (x <= 5)
printf("hi");
main();
}
}
b) hi
c) Infinite hi
d) hi hi
Ans: D
Ans: A
a) int 1bhk(int);
Ans: D
b)
{return (a + b);}
c)
int sum(a, b)
return (a + b);
Ans: B
59.) Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ].
b) Yes, but we call the function again to get the value, not as convenient as in using variable
Ans: C
60.) The value obtained in the function is given back to main by using ________ keyword.
a) return
b) static
c) new
d) volatile
Ans: A
61.)Which of the following ways are correct to include header file in C program?
a.) #include<stdio.h>
b.) #include"stdio.h"
d)None of these
Ans: C
a.) .h
b.) .exe
c.) .i
d.) .asm
Ans: C
63.)Which compilation unit is responsible for adding header files content in the source code?
a)Linker
b)Compiler
c)Assembler
d)Preprocessor
Ans: D
b)2
c)3
d)4
Ans: A
a)C11
b)C99
c)C95
d)C89
Ans: A
Ans: A
a) int
b) float
c) double
Ans: C
a)
double func();
int main(){}
double func(){}
b)
double func(){};
int main(){}
c)
int main()
double func();
double func(){//statements}
Ans: D
69.) What will be the output of the following C code having void return-type function?
#include <stdio.h>
void foo()
return 1;
void main()
int x = 0;
x = foo();
printf("%d", x);
a) 1
b) 0
c) Runtime error
Ans: D
70.) What will be the data type returned for the following C function?
#include <stdio.h>
int func()
return (double)(char)5.0;
a) char
b) int
c) double
Ans: B
int func(int);
double func(int);
int func(float);
c) A function with the same name cannot have different number of parameters
Ans: D
#include <stdio.h>
void main()
int k = m();
printf("%d", k);
void m()
{
printf("hello");
a) hello 5
b) Error
c) Nothing
d) Junk value
Ans: A
#include <stdio.h>
int *m()
int *p = 5;
return p;
void main()
int *k = m();
printf("%d", k);
a) 5
b) Junk value
c) 0
d) Error
Ans: A
#include <stdio.h>
int *m();
void main()
int *k = m();
printf("hello ");
printf("%d", k[0]);
int *m()
return a;
a) hello 5 8
b) hello 5
d) Compilation error
Ans: C
75.)What will be the output of the following C code?
#include <stdio.h>
char * f();
char a = 'a';
printf("%s", temp);
return 0;
char *f()
{ return &a;
(A) a
(B) "a"
(C) nothing
Ans: A
76.) What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
char temp[20];
gcvt(23.45,2, temp);
printf("%s", temp);
return 0;
(A) .4
(B) 23
(C) 23.45
(D) 23
Ans: B
#include <stdio.h>
#include <stdlib.h>
char temp[20];
gcvt(23.45, 3, temp);
printf("%s", temp);
return 0;
(A) 0
(B) 23.5
(C) 23.450000
(D) 23.4
Ans: D
#include <stdio.h>
#include <stdlib.h>
char buffer[4];
printf("%s", buffer);
return 0;
(A) 1234
(B) 12340
(C) 123
(D) 0
Ans: C
#include <stdio.h>
#include <stdlib.h>
int a = atoi("100");
printf("%d",a);
return 0;
(A) 0
(B) 1
(C) 100
(D) 3
Ans: C
#include <stdio.h>
double i;
int main()
printf("%g\n",i);
return 0;
a) 0
b) 0.000000
c) Garbage value
Ans: A
81.) Which part of the program address space is p stored in the following C code?
#include <stdio.h>
int *p = NULL;
int main()
int i = 0;
p = &i;
return 0;
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Ans: B
82). Which part of the program address space is p stored in the following C code?
#include <stdio.h>
int *p;
int main()
int i = 0;
p = &i;
return 0;
a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
Ans: C
#include <stdio.h>
int i;
int main()
{
printf("%d\n", i);
a) Yes
b) No
Ans: A
84.) Property of the external variable to be accessed by any source file is called by the C90
standard as __________
a) external linkage
b) external scope
c) global scope
d) global linkage
Ans: A
#include <stdio.h>
int *i;
int main()
{
if (i == NULL)
printf("true\n");
return 0;
a) true
d) Nothing
Ans: A
#include <stdio.h>
int *i;
int main()
if (i == 0)
printf("true\n");
return 0;
a) true
Ans: B
#include <stdio.h>
static int x = 5;
void main()
x = 9;
int x = 4;
printf("%d", x);
a) 9
b) 4
c) 5
d) 0
Ans: A
void main()
m();
m();
void m()
static int x = 5;
x++;
printf("%d", x);
a) 6 7
b) 6 6
c) 5 5
d) 5 6
Ans: A
#include <stdio.h>
void main()
{
static int x;
a) 0
b) 1
c) Junk value
Ans: A
#include <stdio.h>
static int x;
void main()
int x;
a) 0
b) Junk value
d) Nothing
Ans: B
#include <stdio.h>
void main()
static double x;
int x;
a) Nothing
b) 0
d) Junk value
Ans: C
#include <stdio.h>
void main()
{
static int x;
if (x++ < 2)
main();
c) Varies
Ans: D
Ans: C
a) Variables
b) Functions
c) Structures
a) %s
b) %d
c) %f
Ans: b
Ans: b
#include <stdio.h>
void func();
int main()
func();
}
void func()
static int b;
printf("%d", b);
a) Output will be 0
b) Output will be 20
Ans: A
a) True
b) False
Ans: B
#include <stdio.h>
int main()
{
register auto int i = 10;
i = 11;
printf("%d\n", i);
a) 10
c) Undefined behaviour
d) 11
Ans: B
#include <stdio.h>
int main()
i = 11;
printf("%d\n", i);
a) 10
c) Undefined behaviour
d) 11
Ans: B
101.) Register storage class can be specified to global variables.
a) True
b) False
Ans: B