C Mcq Questions:
1.)How many main() function we can have in our project?
a)1
b)2
c)No Limit
d)Depends on Compiler
Ans: A
2.)What is sizeof() in C?
a)Operator
b)Function
c)Macro
d)None of these
Ans: A
3.)Is the following statement a declaration or definition.
extern int i;
a)Declaration
b)Definition
c)Both A and B
d)None of these
Ans: A
4.)What is the output of the C program?
//This program is compiled on 32 bit DEV-C++
int main()
{
char *ptr1,*ptr2;
printf(“%d %d”,sizeof(ptr1),sizeof(ptr2));
return 0;
}
a)0 0
b)2 2
c)4 4
d)Undefined
Ans: C
5.)Which programming language is more faster among these?
a)Java
b)PHP
c)C
d)Visual Basic
Ans:C
6.)What should be the output :
void main()
{
int a=10/3;
printf(“%d”,a);
}
a)3.33
b)3.0
c)3
d)0
Ans: C
7.)Which of the following is executed by preprocess?
a)#include<stdio.h>
b)return 0;
c)void main(int argc,char **argv)
d)None of these
Ans: A
8.)What is the output of the following C code?
int main()
{
int a=10.5;
printf(“%d”,a);
}
a)10.5
b)10
c)0
d)Compilation Error
Ans: B
9.)What is the output of the following C code?
int main()
{
int _=10;
Int __=20;
int ___=_+__;
printf(“__%d”,___);
}
a)Compilation Error
b)Runtime Error
c)__0
d)__30
Ans: D
10.)What is the output of the following C code?
int main()
{
int a=6;
Int b=10;
int c=a+b;
printf(“%i”,c);
}
a)0
b)16
c)Undefined i
d)Any other Compilation Error
Ans: B
11.)What will be the output of the following C code?
int main()
{
int a=320;
char *ptr;
ptr=(char *)&a;
printf(“%d”,*ptr);
return 0;
}
a)320
b)60
c)160
d)64
Ans: D
12.)What will be the output of the following C code?
a)10
b)20
c)30
d)Compilation Error
Ans: A
13.)How many times Hello is printed on console?
void main()
{
int a=0;
while(a++)
{
printf(“Hello”);
}
}
a)Nothing is printed on screen
b)0 time
c)1 time
d)Infinite times(untill Stack overflow)
Ans: A
14.)How many times tcs_ninja is printed?
a)1 time
b)Compilation Error
c)Infinite times
d)Runtime Error
Ans: C
15.)What will be the output of following C code ?
void main()
{
int i;
for(i=0; i<5; i++);
{
printf("tcs_ninja");
}
}
a.) tcs_ninja is printed 5 times
b.) Compilation Error
c.) tcs_ninja is printed 1 times
d.) Nothing is printed
Ans: C
16.)What is output of below program?
void main()
{
for(; ;);
for(; ;);
printf("Hello");
a.) Compilation Error
b.) Runtime Error
c.) Nothing is printed
d.) Hello is printed infinite times
Ans: C
17.)What is the output of below program?
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
18.)How many loops are there in C?
a)2
b)3
c)4
d)1
Ans: B
19)
What is the meaning of below lines?
void sum (int, int);
a.) sum is function which takes int arguments
b.) sum is a function which takes two int arguments and returns void
c.) it will produce compilation error
d.) Can't comment
Ans: B
20.)What is the following is invalid header file in C?
(A) math.h
(B) mathio.h
(C) string.h
(D) ctype.h
Ans: B
21.)Library function getch() belongs to which header file?
a.) stdio.h
b.) conio.h
c.) stdlib.h
d.) stdlibio.h
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
23.)Can we declare function inside structure of C Programming?
(A) Yes
(B) No
(C) Depends on Compiler
(D) Yes but run time error
Ans: B
24.)What will be the output of the following C code?
#include<stdio.h>
int main()
{
int a@ = 10;
printf("%d", a@);
return 0;
}
(A) 10
(B) 10@
(C) @
(D) [Error] stray '@' in program
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
33.)Which command is to compile C code without linking using gcc compiler?
(A) gcc -o cppbuzz.c
(B) gcc -c cppbuzz.c
(C) gcc -e cppbuzz.c
(D) gcc cppbuzz.c
Ans: B
34.)What is the job of Assembler in C programming?
(A) It converts source code into assembly code
(B) It converts an assembly language program into machine language
(C) It convert code generated by preprocessor to assembly code
(D) None of the above
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
36.)Which one of the following is invalid macro in C programming?
(A) #pragma
(B) #error
(C) #ifndef
(D) #elseif
Ans: D
37.) What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *str = "";
do
printf("hello");
} while (str);
a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times
Ans: D
38.) What will be the output of the following C code?
#include <stdio.h>
void main()
int i = 0;
while (i < 10)
i++;
printf("hi\n");
while (i < 8)
i++;
printf("hello\n");
a) Hi is printed 8 times, hello 7 times and then hi 2 times
b) Hi is printed 10 times, hello 7 times
c) Hi is printed once, hello 7 times
d) Hi is printed once, hello 7 times and then hi 2 times
Ans: D
39.) What is an example of iteration in C?
a) for
b) while
c) do-while
d) all of the mentioned
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++;
while (i <= n);
a) n, n
b) n, n+1
c) n+1, n
d) n+1, n+1
Ans: D
41.) What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
a) True (infinite time)
b) True (1 time) False
c) False
d) Compiler dependent
Ans: C
42.) What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0, j = 0;
while (i < 5, j < 10)
i++;
j++;
printf("%d, %d\n", 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
d) none of the mentioned
Ans: C
44.) What will be the output of the following C code?
#include <stdio.h>
int main()
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Ans: A
45.) What will be the output of the following C code?
#include <stdio.h>
int main()
printf("%d ", 1);
l1:l2:
printf("%d ", 2);
printf("%d\n", 3);
a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
Ans: B
46.) What will be the output of the following C code?
#include <stdio.h>
int main()
printf("%d ", 1);
goto l1;
printf("%d ", 2);
void foo()
l1 : printf("3 ", 3);
a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
Ans: D
47.) What will be the output of the following C code?
#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
c) Loop Loop Loop Loop
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;
while (l1: i < 2)
i++;
while (j < 3)
printf("loop\n");
goto l1;
a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop
Ans: B
49.) What will be the output of the following C code?
#include <stdio.h>
int main()
int i = 0, j = 0;
l1: while (i < 2)
i++;
while (j < 3)
printf("loop\n");
goto l1;
a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop
Ans: A
50.) What will be the output of the following C code?
#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
51.) What will be the output of the following C code?
#include <stdio.h>
void main()
int i = 0, k;
if (i == 0)
goto label;
for (k = 0;k < 3; k++)
{
printf("hi\n");
label: k = printf("%03d", i);
a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0
Ans: A
52.) What will be the output of the following C code?
#include <stdio.h>
void main()
int i = 0, k;
label: printf("%d", i);
if (i == 0)
goto label;
a) 0
b) Infinite 0
c) Nothing
d) Error
Ans: B
53.) What will be the output of the following C code?
#include <stdio.h>
void main()
m();
void m()
printf("hi");
a) hi
b) Compile time error
c) Nothing
d) Varies
Ans: B
54.) What will be the output of the following C code?
#include <stdio.h>
void main()
m();
}
void m()
printf("hi");
m();
a) Compile time error
b) hi
c) Infinite hi
d) Nothing
Ans: C
55.) What will be the output of the following C code?
#include <stdio.h>
void main()
static int x = 3;
x++;
if (x <= 5)
printf("hi");
main();
}
}
a) Run time error
b) hi
c) Infinite hi
d) hi hi
Ans: D
56.) Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned
Ans: A
57.) Which of the following function declaration is illegal?
a) int 1bhk(int);
b) int 1bhk(int a);
c) int 2bhk(int*, int []);
d) all of the mentioned
Ans: D
58.) Which function definition will run correctly?
a)int sum(int a, int b)
return (a + b);
b)
int sum(int a, int b)
{return (a + b);}
c)
int sum(a, b)
return (a + b);
d) none of the mentioned
Ans: B
59.) Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ].
a) Yes, and we can use the function value conveniently
b) Yes, but we call the function again to get the value, not as convenient as in using variable
c) No, C does not support it
d) This case is compiler dependent
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"
c.) Both A & B
d)None of these
Ans: C
62.)What is the extension of output file produced by Preprocessor?
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
64.)In compilation process at what sequence preprocessor comes into picture?
a)1
b)2
c)3
d)4
Ans: A
65.)What is the latest version of C language?
a)C11
b)C99
c)C95
d)C89
Ans: A
66.)Numbers are stored and transmitted inside a computer in which format?
(A) binary form
(B) ASCII code form
(C) decimal form
(D) alphanumeric form
Ans: A
67.) What is the return-type of the function sqrt()?
a) int
b) float
c) double
d) depends on the data type of the parameter
Ans: C
68.) Which of the following function declaration is illegal?
a)
double func();
int main(){}
double func(){}
b)
double func(){};
int main(){}
c)
int main()
double func();
double func(){//statements}
d) None of the mentioned
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
d) Compile time 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
d) multiple type-casting in return is illegal
Ans: B
71.) What is the problem in the following C declarations?
int func(int);
double func(int);
int func(float);
a) A function with same name cannot have different signatures
b) A function with same name cannot have different return types
c) A function with the same name cannot have different number of parameters
d) All of the mentioned
Ans: D
72.) What will be the output of the following C code?
#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
73.) What will be the output of the following C code?
#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
74.) What will be the output of the following C code?
#include <stdio.h>
int *m();
void main()
int *k = m();
printf("hello ");
printf("%d", k[0]);
int *m()
int a[2] = {5, 8};
return a;
a) hello 5 8
b) hello 5
c) hello followed by garbage value
d) Compilation error
Ans: C
75.)What will be the output of the following C code?
#include <stdio.h>
char * f();
char a = 'a';
int main(int argc, char *argv[])
char *temp = f();
printf("%s", temp);
return 0;
char *f()
{ return &a;
(A) a
(B) "a"
(C) nothing
(D) Compilation Error
Ans: A
76.) What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char temp[20];
gcvt(23.45,2, temp);
printf("%s", temp);
return 0;
(A) .4
(B) 23
(C) 23.45
(D) 23
Ans: B
77.) What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
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
78.)What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char buffer[4];
itoa(123, buffer, 10);
printf("%s", buffer);
return 0;
(A) 1234
(B) 12340
(C) 123
(D) 0
Ans: C
79.)What will be the output of the following C code?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a = atoi("100");
printf("%d",a);
return 0;
(A) 0
(B) 1
(C) 100
(D) 3
Ans: C
80.) What will be the output of the following C code?
#include <stdio.h>
double i;
int main()
printf("%g\n",i);
return 0;
a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
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
83.) Can variable i be accessed by functions in another source file?
#include <stdio.h>
int i;
int main()
{
printf("%d\n", i);
a) Yes
b) No
c) Only if static keyword is used
d) Depends on the type of the variable
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
85.) What will be the output of the following C code?
#include <stdio.h>
int *i;
int main()
{
if (i == NULL)
printf("true\n");
return 0;
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Ans: A
86.) What will be the output of the following C code?
#include <stdio.h>
int *i;
int main()
if (i == 0)
printf("true\n");
return 0;
a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
Ans: B
87.) What will be the output of the following C code?
#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
88.) What will be the output of the following C code?
#include <stdio.h>
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
89.) What will be the output of the following C code?
#include <stdio.h>
void main()
{
static int x;
printf("x is %d", x);
a) 0
b) 1
c) Junk value
d) Run time error
Ans: A
90.) What will be the output of the following C code?
#include <stdio.h>
static int x;
void main()
int x;
printf("x is %d", x);
a) 0
b) Junk value
c) Run time error
d) Nothing
Ans: B
91.) What will be the output of the following C code?
#include <stdio.h>
void main()
static double x;
int x;
printf("x is %d", x);
a) Nothing
b) 0
c) Compile time error
d) Junk value
Ans: C
92.) What will be the output of the following C code?
#include <stdio.h>
void main()
{
static int x;
if (x++ < 2)
main();
a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice
Ans: D
93.) Which of the following is not accepted in C?
a) static a = 10; //static as
b) static int func (int); //parameter as static
c) static static int a; //a static variable prefixed with static
d) all of the mentioned
Ans: C
94.) Which of the following cannot be static in C?
a) Variables
b) Functions
c) Structures
d) None of the mentioned
Ans: D
95.)6. What is the format identifier for “static a = 20.5;”?
a) %s
b) %d
c) %f
d) Illegal declaration due to absence of data type
Ans: b
96.) Which of the following is true for static variable?
a) It can be called from another function
b) It exists even after the function ends
c) It can be modified in another function by sending it as a parameter
d) All of the mentioned
Ans: b
97.) What will be the output of the following C code?
#include <stdio.h>
void func();
int main()
static int b = 20;
func();
}
void func()
static int b;
printf("%d", b);
a) Output will be 0
b) Output will be 20
c) Output will be a garbage value
d) Compile time error due to redeclaration of static variable
Ans: A
98.) register keyword mandates compiler to place it in machine register.
a) True
b) False
c) Depends on the standard
d) None of the mentioned
Ans: B
99.) What will be the output of the following C code?
#include <stdio.h>
int main()
{
register auto int i = 10;
i = 11;
printf("%d\n", i);
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
Ans: B
100.) What will be the output of the following C code?
#include <stdio.h>
int main()
register const int i = 10;
i = 11;
printf("%d\n", i);
a) 10
b) Compile time error
c) Undefined behaviour
d) 11
Ans: B
101.) Register storage class can be specified to global variables.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Ans: B