Professional Documents
Culture Documents
main()
{
static int a[]={0,1,2,3,4};
static int *p[]={a,a+2,a+3};
int **ptr;
ptr=p;
**++ptr;
printf("%d %d",**ptr,*ptr-a);
}
Output: 2 2
2.
3.
main()
{
int i;
char *str ="123four";
i=atoi(str);
printf("%d",i);
}
Output: 123
4.
main()
{
int i,j;
printf("%d\n",2);
for(i=3;i<=100;i=i+1)
{
for(j=2;j<i;j=j+1)
{
if(i%j==0)
break;
if(j>sqrt(i))
{
printf("%d\n",i);
break;
}
}
}
}
Options
1. Compiler error
2. Even numbers
3. 0
4. Prime numbers
Output: Prints Prime numbers
5.
6.
7.
main()
{
int loop;
for(loop='A';loop<='Z';loop++)
printf("%c",loop);
}
Options
1. A to Z characters
2. Error
3. a-z characters
4. A and Z characters
Output: A to Z characters
8.
10.
{
int a=10;
{
int a=1;
}
printf("%d",a);
}
Options
1. unpredictable
2. 100
3. 10
4. 1
Output: 10
11.
12.
13.
14.
15.
16.
17.
18.
1. Compiler Error
2. Infinite loop printing values 01234
3. Infinite loop without printing any values
4. print 0 infinite times
Output : Infinite loop without printing any values
19.
20.
21.
}
Options
1. {Unknown value}
2. {Unkown value } {Unkown value}
3. Run time error
4. Compile time error
5. 0 { unkown value}
Output : Compile time error
22.
23.
char str1[]=Hello;
char str2[]=Hello;
The conditional test(str1= =str2) returns FALSE
Options
1. True
2. False
Output :- False
24.
char strbuf[]=Hello;
char *strptr=World;
--strbuf=World; // Expression A
strptr=Hello; // Expression B
Options
1. expression B is invalid
2. both are invalid
3. expression A is invalid
4. Both are valid
Output :- expression A is invalid
Note : strcpy(strbuf,World) should be used instead of strbuf=World;
25.
27.
How many times will the following program print hello world
main()
{
printf(hello world);
main();
}
Options
1. 65535 times
2. Till the stack doesnt overflow
3. 632769 times
4. Infinite number of times
Solution: Till the stack doesnt overflow
28.
int f2(int a)
{
printf("f2\n");
return a;
}
int f3()
{
printf("f3\n");
return 1;
}
29.
30.
31.
32.
To print out a and b given below which printf() statement would you use
float a=3.14;
double=3.14
Options
1. printf(%f %lf,a,b)
2. printf(%lf %f,a,b)
3. printf(%lf %lf,a,b)
4. printf(%f %f,a,b)
Solution: printf(%f %lf,a,b)