You are on page 1of 9

1.

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.

Which one is valid statement in c?


expression 1?expression 2: expression 3
expression 1|
expression 2: expression 3
expression 1|
expression 2, expression 3
expression 1?expression 2, expression 3
Output: expression 1?expression 2: expression 3

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.

What is the outcome of the following, assuming


a=3, b=4 , c=5
a*=b+c;
Options
1. 26
2. 60
3. 17
4. 27
Output: 27

6.

What is the output of the following program


main()
{
static int arr[]={97,98,99,100};
int *ptr=arr+1;
printf("%d %d %d",*ptr++,*ptr--,*++ptr);
}
Options
1. 97,98,99
2. 98,97,98
3. 98,99,99
4. Runtime error
Output: 98,99,99

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.

To print a % character in printf format string using


1. %+
2. %%
3. cannot print
4. %
Output: %%
9.

10.

Identify the C Keyword


Options
1. default
2. volatile
3. auto
4. all of the above
Output: all of the above
what is the output of the following program
int a=100;
main()

{
int a=10;
{
int a=1;
}
printf("%d",a);
}
Options
1. unpredictable
2. 100
3. 10
4. 1
Output: 10
11.

What is the output value


main()
{
int i=23,j;
if(i>25)
if(i%2==0)
j=111;
else
j=222;
printf("\n %d",j);
}
Options
1. Compile Error
2. Garbage value
3. 111
4. 222
Output : Garbage value

12.

Can you perform pointer arithmetic on a void pointer?


Answer: No

13.

A piece of code checks a string to see if it matches with a particular value


What will be the status of if condition?
char *string;
-------if(string = = value)
{
/* String matches value*/
}
Options
1. Compiler Error
2. False
3. True
4. Run Time Error
Output : False

14.

const char *p and char * const p are same


1. True
2. False
Output : False

15.

16.

17.

How to declare an array of N pointers to functions returning pointers to functions returning


pointers to characters
Options
1. char *(*(a[N]*)())()
2. char((a[N]*)()*)()*
3. char *(*(*a[N])())()
4. None of the above
Output : char *(*(*a[N])())()
What is the output of the following program
#define INTPTR int *
main()
{
INTPTR pa,pb;
int a=10,b=20;
pa=&a;
pb=&b;
printf("\n %d %d %d %d",a,*pa,b,*pb);
}
Options
1. 10 10 20 20
2. compiler error
3. unpredictable
4. None of the above
Output : compiler error
What is the output of the following program
main()
{
int a=10;
switch(a)
{
default: printf("default");
case 1: printf("one");
case 2:printf("two");
case 3:printf("three");
}
}
Options
1. Default one two three
2. no output
3. compiler error
4. default
Output : Default one two three

18.

What is the output of the following program


main()
{
int a=0;
while(a<5);
{
printf("%d",a);
a++;
}
}
Options

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.

What is the output of the following program


main()
{
int a[2]={1,2};
if(a[2]= =2[a])
printf("Equal");
else
printf("Not equal");
}
Options
1. Compiler error
2. Equal
3. Run time error
4. Not equal
Output: Equal

20.

What is the output of the following program


struct a
{
char city[3][20];
char state[3][20];
};
main()
{
struct a arr={{"Mysore","Bangalore","Mangalore"},
{"Karnataka","Karnataka","Karnataka"}};
char **c=arr.city+1;
printf("%s %s",c,arr.state+2);
}
Options
1. Karnataka
2. Bangalore Karnataka
3. Runtime error
4. Mysore Karnataka
Output : Bangalore Karnataka

21.

What is the output of the following program


main()
{
int *iptr1,*iptr2;
int *iptr,iptr3;
int i=10;
iptr1=iptr2=iptr;
iptr=iptr1-iptr2;
iptr=iptr1+iptr2;
printf("%x %x",iptr,iptr3);

}
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.

What is the output of the following program


main()
{
int p=-2,q=0,r=0,s;
s=++p&&++q||++r;
printf("%d %d %d %d\n",p,q,r,s);
}
Options
1. -1 1 1 0
2. -1 1 0 1
3. -3 1 1 0
4. -3 1 0 1
Output : -1 1 0 1

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.

How to declare an array of N pointers to functions returning pointers to functions returning


pointers to characters
Options
1. char *(*(*a[N])())()
2. typedef char *pc;
typedef pc fpc();
typedef pfpc fpfpc();
typedef fpfpc * pfpfpc;
pfpfpc a[N];
3. both a and b
4. None of the above

Solution: both a and b


26.

What is the output of the following code


main()
{
printf("%d %d %d",sizeof(3.14f),sizeof(3.14),sizeof(3.14l));
}
Solution: 4 8
12 ( 4 8 10 on tc)

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.

In the following code in which order the function would be called


A=(f1(23,14)*f2(12/4))+f3()
Options
1. f1,f2,f3
2. f3,f2,f1
3. The order may vary from compiler to compiler
4. None of these
Solution: The order may vary from compiler to compiler
Explanation
The statement A=(f1(23,14)*f2(12/4))+f3() calls the function in the order f1,f2,f3. Suppose if
the statement is A=f1(23,14) + f2(12/4) * f3()
on a TC compiler the order of function invocation is f2,f3,f1 whereas on a ANSI C compiler
the order is f1,f2 ,f3.
Egs Program
#include<stdio.h>
int f1(int,int);
int f2(int);
int f3();
main()
{
int a;
a=f1(23,14)*f2(12/4)+f3();
//a=f1(23,14)+f2(12/4)*f3();
printf("%d\n",a);
}
int f1(int a,int b)
{
printf("f1\n");
return a-b;
}

int f2(int a)
{
printf("f2\n");
return a;
}
int f3()
{
printf("f3\n");
return 1;
}
29.

If the binary equivalent of 5.375 in the normalized form is


0100 0000 1010 1100 0000 0000 0000 0000 , what would be the output of the following
program?
#include<stdio.h>
main()
{
float a=5.375;
char *p;
int i;
p=(char *)&a;
for(i=0;i<=3;i++)
printf("%x",(unsigned char)p[i]);}
Solution : 00 00 AC 40

30.

What would be the output of the following program


main()
{
printf(%c,abcdefgh[4]);
}
Solution : e

31.

In the following code


#include<stdio.h>
main()
{
FILE *fp;
fp=fopen(Trial,r);
}
Options
fp points to
1. The first char in the file
2. A structure which contains a char pointer which points to the first char in the file
3. The name of the file
4. None of the above
Solution: None of the above

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)

You might also like