Assignment 123
Assignment 123
1) main()
{
100;
printf("%d\n");
}
a) No out put
b) Error
c) 100
d) Garbage value
2) void main()
{
int i=5;
printf("%d",i++ + ++i);
}
a) 7
b) Error
c) Can not predictable
d)5
3) #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
a) GOOD
b) BAD
c) NO out put
d) Error
4) main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
a) I=0 +I=1
b) I=-1 +I = -1
c) I=1 +I = -1
d) I =-1 +I = 1
5)What would be the output of the following program?
#include<stdio.h>
void main()
{
int i,d1,d2,d3,d4;
float f;
char c;
void v;
d1=sizeof(i);
d2=sizeof(f);
d3=sizeof(c);
d4=sizeof(v);
printf("d1 = %d, d2 = %d, d3 = %d, d4 = %d ",d1,d2,d3,d4);
}
A. d1 = 2, d2 = 2, d3 = 1, d3 = 0
B. d1 = 2, d2 = 4, d3 = 2, d3 = 1
C. Compiler Error.
D. d1 = 2, d2 = 4, d3 = 1, d3 = 0
6) 6) What is the output of the following program?
#include<stdio.h>
void main()
{
float t,i = 11;
float f = 4.8;
t =(int)i + (int)f;
printf("%f",t);
}
A. 0.00
B. 15
C. 15.000000
1. 0
7) What will be the output of the following program?
C
A. hello
B. bye
C. NO OUTPUT
D. compiler error
8)What will be the output of the following program?
C
A. bye
B. error
C. hi
D. goodbye
9) what will be the value of i?
#include<stdio.h>
void main()
{
int i ;
for(i=1;i<=25;i++);
/* what will be the value of i here? */
}
A. 2
B. 26
C. 25
D. 1
10) What is the difference between #include<stdio.h> and #includestdio.h
A. < > this option will include file from specified directory and option will include directory from
current working directory.
B. both are same
C. < > option is to include header files and is to include other files like c.
D. < > is to include library files and is to include user defined files.
11)what will the following program do?
#include<stdio.h>
void main()
{
main();
}
e) a) compilation error
f) b) infinite loop
g) c) Itll not do anything.
h) d) Syntax not allowed.
12) #include<stdio.h>
void main()
{
printf("good\b\r");
printf(morning);
}
a) goodbmorning
b) morning
c) goomorning
d) goodorning
13) #include<stdio.h>
void main( )
{
int i = 4;
float j = 12.8,k;
k = j + i;
printf( %f,k);
}
output of the program?
a) 16
b) 16.799999
c) Error : int must be converted to float for any operation.
d) 17.8
14) Indicate the error:
#include<stdio.h>
void main( )
{
int x = 10;
while(!x)
{
printf(%u,10) // indicate error
}
}
a) digit can not be used here.
b) Syntax error
c) %d must be used instead of %u
d) insufficient argument to printf( )
15) #include<stdio.h>
void main()
{
int d;
d = printf(how is the paper?);
printf(%d,d);
}
A. 1
B. 0
C. 17
D. syntax error
16) #include<stdio.h>
#define sqr( a) = (a*a);
void main()
{
float i= 12.5,f;
f = sqr(i);
printf(%f,f);
}
b. a)156.250000
c. b)(12.5 * 12.5)
d. c)syntax error
e. d) undefined function sqr()
17) #include<stdio.h>
void main( )
{
int i;
for(i=0;i<=5;i++);
{
printf(oasis );
}
}
a) oasis
b) syntax error
c) oasis oasis oasis oasis oasis oasis
d) no output
18) #include<stdio.h>
void main()
{
int i = 10,j=10,k;
i = i %10;
j = j % 2;
k = j * 5;
printf(%d %d %d,i,j,k);
}
i. 1 0 0
ii. 0 0 0
iii. 0 1 5
iv. 1 1 5
19) #include<stdio.h>
void main( )
{
int i = 100, j=50, k=200;
if( i > k && k > j || j < i) printf( i is the greatest);
elseif( k> i || j < i && k > 150) printf(k is the greatest);
else printf(j is the greatest);
}
i. i) i is the greatest
j. ii) k is the greatest
k. iii) i is the greatest
l. iv) error
m.
20) main()
{
char not;
not=!2;
printf("%d",not);
}
A. 0
B. 1
C. 2
Err D. Error
21) #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
A. Error
B. 4 5.0
C. 5 4.0
D. 4 4.0
22) #include<stdio.h>
void main( )
{
int i = 100, j=50, k=200;
if( i > k && k > j || j < i) printf( i is the greatest);
elseif( k> i || j < i && k > 150) printf(k is the greatest);
else printf(j is the greatest);
}
a) i is the greatest
b) k is the greatest
c) j is the greatest
er d) Error
23)What will be the output of the following program?
#include<stdio.h>
void main()
{
int i = 0;
if( i++ )printf(hello);
else printf(bye);
}
A. hello
B. bye
C. NO OUTPUT
compiler error
24) main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
A. 44555
B. 45545
C. 44545
D. 45554
25) main()
{
int i = 3;
for (;i++=0;) printf(%d,i);
}
e) 3
f) 0
g) Error
h) 0 1 2 3
26) void main()
{
int i=7;
printf("%d",i++*i++);
}
A. 49
B. 56
C. 64
1. Errr
27) How many times is the for loop executed
for(i=0;i<10;i++);
A. 1
B. 10
C. compiler error
D. Not executed
2!) "#i$# f t#% f&&'in( i) %*%$+t%d 1r)t,
i .-- ii... iii./
A. i
B. ii
C. iii
D. a&& ar% %0+a&
29) main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
A. 1,5,2,13,14
B. 5,2,13,14
C. 12,14,22
D. 15,21
30) main()
{char c=-64;
int i=-32
unsigned int u =-16;
if(c>i)
{printf("pass1,");
if(c<u)
printf("pass2");
else
printf("Fail2");
}
else
printf("Fail1);
if(i<u)
printf("pass2");
else
printf("Fail2")
}
A. 6a))1,6a))2
B. 6a))1,7ai&2
C. 7ai&1,6a))2
D. 7ai&1,7ai&2
31) main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
A. 57 94
B. 56 94
C. 57 93
D. 56 97
32) main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
A. 5 25 0
B. 5 21 1
C 5 20 1
D 5 25 1
33) int i;
i=1;
i=i+2*i++;
printf(%d,i);
A. 4
B. 2
C. 3
D. 5.
34) %n+m $&r) {B8AC9,B8:E,;<EE=}
main()
{
printf("%d..%d..%d",B8AC9,B8:E,;<EE=);
r%t+rn(1);
}
35) void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
E. Errr
7. >? #%r%
;. 7r(%t it
@. = +tp+t
36) main()
{
int i=400,j=300;
printf("%d..%d");
}
7. Errr
;. 1 1
@. 411 311
A. 311 411
37) main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
A. Error
B. 10
C. 0
D. 1
38) #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
A. 100
B. Error
C. Garbage
D. 0
39) main()
{
char not;
not=!2;
printf("%d",not);
}
A. 1
B. 2
C. 0
D. -1
40) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
A.12
B 11
C. Error
D.13
45554