Paper 4

Practice: Paper 1   Paper 2  Paper 3    Paper 4 



1.What is the output of the following code ? 
int main( ) 
{
int j,i;
i=9;j=10;
for(i=1;i<=10;i++);
printf("%d ",i);
printf("%d",i);
return 0;
}
a)9 10
b)10 11
c)11 11
d)nothing will be printed.

Ans: c


2. What is the output of the following code ? 
int main( ) 

for( ; ;); 
printf("Hello"); 
return 0; 

a. give compilation error 
b. prints Hello infinite times 
c. Runs in an infinite loop without printing anything. 
d. prints Hello once. 

Ans: c 

2.        What is the output of the following code ? 
int main( ) 

for( ; ;); 
printf("Hello"); 
return 0; 

a. give compilation error 
b. prints Hello infinite times 
c. Runs in an infinite loop without printing anything. 
d. prints Hello once. 



Ans: c 
3. Output of the code? 
 int main( ) 

int j,i; i=1;j=10;
for( ;++i< --j ;)
continue; 
printf("%d %d ",i,j); 
return 0; 

a)6  5
b)1  10
c)error
d)10 9

Ans:a
4. Output of the code? 
int main( ) 

int j,i; i=1;j=10;
for( ;++i< --j ;);
continue; 
printf("%d %d ",i,j); 
return 0; 

a)6  5    
b)1  10
c) error
d)10 9

Ans:c
5.Output of the code? 
int main( )  

int j,i; i=1;j=10;
for( ;++i< --j ;);
printf("%d %d ",i,j); 
return 0; 

a)6  5
b)1  10
c)error
d)10 9

Ans:a
6.What is the output
int main()
{
int k=100;
const int *p=&k;
*p=200;
Printf(“\n%d”,k);
}
a)Compiler error
b)100
c)200
d)0

Ans: a
7. What is the output
int main(int argc,char **argv)
{
int  k;
for(k=0;k<argc;k++)
printf(“%s”,argv[++k]);
}
In command line  ./exe  1 2 3 4
a)2   4
b)1  3
c) 1  2 3 4
d)compile time error

Ans: b

8. main(int argc,char *argv[]) 

printf((argc > 1 ? "%c" : "%c",*++argv)); 

If the i/p string is "GESL Bangalore". 
a. G 
b. E 
c. B 
d. GESL 

Answer: d
9. What is the output
int main()
{
int  a=1;
switch(a)
{
int b=20;
case 1: printf(“b=%d\n”,b);
break;
default:printf(“b=%d\n”,b);
break;
}
return 0;
}
a)b=20
b)b=1
c)Compile time error
d) b=Garbage value

Ans:d
10.main() 

nt i=10; 
switch(i) 

case 10: printf("Hello ");

case 1 : printf("World "); 

case 5: printf("Hello World "); 


a) Hello 
b) Hello 
c) Hello World Hello World 
d) Syntax Error. 

Ans : c
11.output of the code? 
FUNC (int *p) 

p = (int *)malloc(100); 
printf("p:%x",p); 

int main( ) 

int *ptr; 
FUNC(ptr); 
printf("Ptr:%x",ptr); 
return 0;  
}
a. Both printf statements prints same values. 
b. Both print different values. 
c. Gives compile time error. 
d. Gives run time error. 

Ans: b.  First Fun is called with unassigned pointer, In function Fun malloc allocates 100 locations and its starting address is assigned in p.
When p is printed a first address of memory block is printed and the function is void function so returns nothing. Hence in main function still the pointer is unassigned.
so both print statements prints different values 

12. Output of the code? 
int main() 

char a[ 20] = "world"; 
printf("%d %d",strlen(a),sizeof(a)); 
return 0; 

a. 5,5 
b. 6,5 
c. 5,20 
d. 5,6 

Ans: c
13. What is the output of the following code in 32-bit compiler 
#include<stdio.h>
void  foo(int arr[])
{
printf(“%d”,*arr);
prinf(“%d”,sizeof(arr));
}
int main()
{
int  arr[5]={1,2,3,4,5};
printf(“%d ” ,sizeof(arr));
foo(arr);
return 0;
}
a)20 1  20 
b)20 1  4
c)5  1  5
d)20  1  8

Ans:d  
20 1 8

14. The output of following code is:
#include<stdio.h>
#define SIZE 10
void  size(int arr[10])
{
printf(“size of array is:%d\n”,sizeof(arr));
}
int main()
{
int  arr[10];
size(arr);
return 0;
}
a) size of array is:40               
b) size of array is:4
c) size of array is:10           
d)None

Ans: b
The function prints sizeof pointer not sizeof array
so answer is either 4 or 8 bytes.
15. what is the o/p ? 
void main() 

char *mess[]={"Have","a","nice","day","Bye"); 
printf("%d %d",sizeof(mess),sizeof(mess[1])); 

a. 16 4 
b. 5 4 
c. 20 2
d. Error 

Answer: c 
sizeof(mess) is size of all strings=5+2+5+4+4=20
sizeof(mess[1]) =sizeof("a")=1+1(null character)=2
16. what is the output of the following code
#include<stdio.h>
int main( ) 
{
printf(“Hello, world\n”);
return 0; 
}
#include<stdlib.h>
int   a;
a)Compiler error       
b)Runtime error
c)Hello, World             
d)None      

Ans: c
17.  what is the output of the following code
void main()
{
int a;
char *p;
a = sizeof(int) * p;
printf("%d\n",a);
}
a)compile error
b)run time error
c)4
d) Compiler dependent

ans:a
18) what is the output of the following code
#define SIZE sizeof(int)
void main()

int i=-1;
if( i < SIZE )
printf("True\n");
else
printf("False\n");
}
a) True
b) False
c) can't predict
d) None of these

ans:b
19)what is the output of the following code
void main() 

# include<stdio.h> 
int i = 10 ; 
printf("%d", i/2 ); 

a)10 
b)5 
c)error 
d) warning. 

ans : b

20. alloca() allocates memory from 
a. Heap. 
b. Reserved memory. 
c. Data segment. 
d. Stack. 

Ans: d 
21. What is the octal equivalent of decimal (5468). 
a. 12360. 
b. 12560. 
c. None of these. 
d. 12650. 

Ans : c
22. what is the output of the following code
void main() 

int a=2; 
a=(3,5); 
printf("%d",a); 

a)2        b)3        c) 5        d)error. 

Ans: c)5
23.what is the output of the following code 
void main() 

int i; 
i=(3,2); 
printf("%d",i); 

a)2 b)3 c)Compiler error d)Syntax error. 

Ans : a)2 
24. what is the output of the following code
void main()

char str[]="GESL"; 
printf("%d %d",sizeof(str),strlen(str)); 

a)5,5        b)4,4           c)5,4           d)4,5 

Ans:c) 5, 4 
25. what is the output of the following code
#include<stdio.h>
#define STYLE1  char
int main( )

typedef char STYLE2;
STYLE1 x;
STYLE2 y;
x=255;
y=255;
printf("%d %d",x,y);
}
The output is
a)255  255   
b)-1   -1 
c)Compile error
d)Runtime error

Ans: b 
26. what is the output of the following code
void main()
{
int i;
for(i=1;i++;i<100) 
printf("hello world");

a)100 times 
b)0 times 
c)Infinite loop 
d)None of the above. 

Ans: c   infinite loop 

27. What will be the output
printf(“%d %d”,printf(“hai”),printf(“Hello”));              
a)5 3 hai Hello
b)hai 0 Hello 0 0
c)hai 4 Hello 4 0
d)Hello hai 3 5

Ans:d
28. what is the output of the following code
#include<stdio.h>
int main( )
{
int a=10;
int i=2;
a=a<< i ;
printf("%d  %d",a, i);
return 0;
}
The output is 
a)2 2  
b)5 2 
c)20 2
d) 40  2

Ans: d
29.what is the output of the following code
#include<stdio.h>
int main() 
{
int *ptr=NULL;
ptr++; 
printf("%d \n",ptr);
return 0; 
}
a)Segmentation error    
b)compile error
c)Runtime error              
d)4

Ans:d
Since int size is 4 bytes P++ shifts pointer forward by one position whose address is 0004

30.what is the output of the following code
#include<stdio.h>
int main()
{
char x=0x80;
int y=x;
printf("%d\n",y);
return 0;
}
a)0
b) 128
c)-128
d)80

Ans: c
here x=0x80=128 which cannot be fitted in 1 byte memory of char.
so it is adjusted withing -128 to +127 as follows
x=128%256(1 byte max value)=128

x=x-256=128-256=-128

No comments:

Post a Comment

CTS Written test results of Vijayawada, Guntur, Ongole, Godarvari Districts were out.  Tentative dates of TR and HR are 24th and 25th Nov...