You are on page 1of 31

TCS Ninja Prep.

C Technical MCQs
What is the output of the following code.?
main()
{
int x = 10;
{
int x = 0;
printf("%d",x);
}
}

A. 10
B. Compiler Error
C. 0
D. Undefined
What is the output of the following code.?
int x = 10;

int main()
{
int x = 0;
printf("%d",x);
return 0;
}

A. 10
B. Compiler Error
C. 0
D. Undefined
What is the output of the following code.?
//This program is compiled on 32 bit DEV-C++
int main()
{

char *ptr1, *ptr2;


printf("%d %d", sizeof(ptr1), sizeof(ptr2));

return 0;
}

A. 11
B. 22
C. 44
D. Undefined
Which programming language is more faster among these?

A. Java
B. PHP
C. C
D. Visual Basic
void main()
{
int a = printf (“Top Freshers");
printf("%d", a);
}

A. Compilation Error
B. Top Freshers
C. 0
D. Top Freshers12
What is the output of the following Code?
int main()
{
int a = 5;
int b = 10;
int c = a+b;
printf("%i",c);
}

A. 0
B. 15
C. Undefined i
D. Any other Compiler Error
What is the output of the following Code?
int main()
{
int x;
x=10,20,30;
printf("%d",x);
return 0;
}

A. 10
B. 20
C. 30
D. Compiler Error
What is the output of the following Code?
void main()
{
int a = 0;
while(++a++);
{
printf(“Top Freshers");
}
}

A. 1 time
B. 0 time
C. Infinite Times
D. Compiler Error: L value Required
What is the output of the following Code?
#include
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf(―%d, %d, %d‖, i, j, m);
return 0;
}

A. 2, 1, 15
B. 1, 2, 5
C. 3, 2, 15
D. 2, 3, 20
Is there any difference in the following declarations of the function?

int function (int arr[]);

int function (int arr[2]);

A. Yes
B. No
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
What is 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
Which of the following is invalid header file in C?

A. Math.h
B. Mathio.h
C. Ctype.h
D. String.h
Libray function getch() belongs to which header file?

A. stdio.h
B. stdlib.h
C. conio.h
D. iostream.h
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
Can we declare function inside
structure of C Programming?

A. Yes
B. No
C. Depends On Compiler
D. Runtime error
#include<stdio.h>
int a = 20;
int main()
{
int a = 10;
printf("%d", ::a);
return 0;
}
A. 10
B. 20
C. ::10
D. ::20
#include<stdio.h>
int a = 20;
int main()
{
int a = 10;
printf("%d", ::a);
return 0;
}
A. 10
B. 20
C. ::10
D. ::20
#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 code
#include <stdio.h>
int main()
{
int a = 0;
if(a = printf("How old are you?"))
printf(" %d - too young", a);
return 0;
}

A. 0 – too young
B. Compilation Error
C. Nothing is printed
D. How old are you?16 – too young
Which gcc flag is used to enable
all Compiler warnings?

A. gcc –W
B. gcc –w
C. gcc –Wall
D. gcc -wall
#include<stdio.h>
int main()
{
int i=10;
if(i>0)
printf(“Hi”);
else if(i>0)
printf(“Hello”);
return 0;
}
A. Compiler error
B. Hi
C. Hello
D. HiHello
#include<stdio.h>
int main()
{
int i=10;
if(i==0)
if(i>0)
printf(“Hi”);
else
printf(“Hello”);
}
A. Nothing is printed
B. Hi
C. Hello
D. HiHello
#include<stdio.h>
void fun(const int* x)
{
*x=100
}
int main()
{
int i=10;
fun(&i);
printf(“%d”, i);
}
A. 10
B. 100
C. Garbage value
D. Error
Will the following code run?
#include<stdio.h>
int main()
{
for(int i=10;i<10;i++)
return i;
}

A. Yes
B. No
C. Depends on the C
standard implemented by compilers
D. None of the above
Which of the following format identifier can never be used for the
variable var?

#include<stdio.h>
int main()
{
char *var=“Top Freshers!!!”;
return 0;
}

A. %d
B. %f
C. %s
D. %c
E. %i
#include<stdio.h>
int main()
{
int i=-20;
int k = i%3;
printf(“%d” ,k);
return 0;
}

A. 2
B. -2
C. Compiler error
D. Runtime Error
#include<stdio.h>
int main()
{
int i=-8;
int k = i%3;
int x = i/3;
printf(“%d %d” ,x,k);
return 0;
}

A. 2 -2
B. -2 2
C. Compiler error
D. Runtime Error
#include<stdio.h>
int main()
{
int i=8;
float k = i/3;
printf(“%f” ,k);
return 0;
}

A. 2.666666
B. 2.000000
C. 2
D. 0
#include<stdio.h>
int main()
{
int i=5.3%2;
printf(“%d” ,i);
return 0;
}

A. 2
B. 2.000000
C. Compiler Error
D. Runtime Error

You might also like