You are on page 1of 11

1. What is the output of the following C program?

#inlcude <stdio.h>
int main()
{
int i = 0;
if ( i = 0 )
{
printf(Hello, World);
}
else
{
printf(How are you?);
}
return 0;
}
A) Hello, World
B) How are you?
C) No Output
D) Syntax Error

2. What is the output of the following C program?


#include <stdio.h>
int main()
{
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
if(printf(%d,i))
{
printf(j);
}
}
}
}
A) 11122122
B) 1122
C) Syntax Error
D) None of the above

3. Which of the following ways is/are the correct way(s) to print


HelloWorld in C.
I) printf(HelloWorld);
II) printf(HelloWorld);
III) char str[]=HelloWorld;printf(%s,str);
A) Only II
B) Only III
C) Both II and III
D) All of them
4.
#include <stdio.h>
int fact(int i)
{
if(i <= 1)
return i;
return i + fact(i-1);
}
int main()
{
int ans;
ans = fact(5);
print(%d,ans);
}
What does fact(int i) calculates, and what is the output of the
program.
A) Factorial of i, 120
B) Sum till i, 15
C) Sum till i + 1, 16
D) None of the above

5. Which of the following is not a keyword in C ?


A) printf
B) if
C) char
D) sizeof
6. Which of the following is not an operator in C ?
A) <<=
B) <=
C) sizeof
D) None of the above
7. Exp: x && 1 || y || 0
For which of the following value of x and y the above expression
evaluates to true?
I) x=1, y=1
II) x=0, y=0
III) x=-1, y=0
A) Only I
B) Both I and III
C) Only II
D) I, II and II

8. Match the expression from Col A to their equivalent expression


in Col B.
A
B
I) X>>2
i)X X % 2
II) X>>1 + X>>1
ii) X * 4
III) X<<2
iii) X * 5
IV) X<<2 + X<<1
iv) X / 4
A) I=>iv,II=>i,III=>iii,IV=>ii
B) I=>iv,II=>i,III=>ii,IV=>iii
C) I=>i,II=>iv,III=>ii,IV=>iii
D) I=>i,II=>iv,III=>ii,IV=>iii
9. Which of the following is true for the following statement:
int **i;
A) i is a pointer to a pointer of int.
B) the statement is invalid.
C) Both A and B.
D) None of the above.
10.For the array declared using the following statement, which of
the following is an invalid way to print the value of a[4].
int a[5]={1,2,3,4,5};
A) printf(%d,a[4]);
B) printf(%d,a+4);
C) printf(%d,a[8-4]);
D) None of the above.

11. What will be output if you will compile and execute the
following c code?
#define x 5+2
void main(){
int i;
i=x*x*x;
printf("%d",i);
}
A)
B)
C)
D)
E)

343
27
133
Compiler error
None of above

12. What will be output if you will compile and execute the
following c code?
void main(){
char c=125;
c=c+10;
printf("%d",c);
}
A)
B)
C)
D)
E)

135
+INF
-121
-8
Compiler error

13. What will be output if you will compile and execute the
following c code?
void main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else{
break;
}
}
A)
B)
C)
D)
E)

It will print nothing.


-3
-2
1
Compiler error

14. What will be output if you will compile and execute the
following c code?
void main(){
int a=10;
printf("%d %d %d",a,a++,++a);
}
A)
B)
C)

12 11 11
12 10 10
11 11 12

D)
E)

10 10 12
Compiler error

15.
#include "stdio.h"
#include "string.h"
void main(){
int i=0;
for(;i<=2;)
printf(" %d",++i);
}
A)
B)
C)
D)
E)

012
0123
123
Compiler error
Infinite loop

16.
What will be output if you will compile and execute the following
c code?
void main(){
int x;
for(x=1;x<=5;x++);
printf("%d",x);
}
A)
B)
C)

4
5
6

D)
E)

Compiler error
None of above

17. What will be output if you will compile and execute the
following c code?

int * call();
void main(){
int *ptr;
ptr=call();
clrscr();
printf("%d",*ptr);
}
int * call(){
int a=25;
a++;
return &a;
}
A)
B)
C)
D)
E)

25
26
Any address
Garbage value
Compiler error

18.
#define max 5;
void main(){
int i=0;
i=max++;
printf("%d",i++);
}
A)
B)
C)
D)
E)

5
6
7
0
Compiler error

19.
#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

20.
#include <stdio.h>
int main()
{
int c = 2 ^ 3;
printf("%d\n", c);
}
a) 1
b) 8
c) 9
d) 0

You might also like