Tuesday, November 16, 2010

C Objective Sample Paper

C Questions

1.What is the output of the following program-
void main()
{
extern int i;
i=20;
printf(“%d”,sizeof(i));
}
a)2                                b)4
c)vary from compiler to compiler   d)error,i undefined


2.What is the output of the following-
void main(){
int x=10,y=20,z=5,i;
i=x<y<z;
printf(“%d”,i);
}
a)0                               b)1
c)Error                          d)none of the above


3.What is the output of the following-
void main(){
enum status{pass,fail,atkt};
enum status stud1,stud2,stud3;
stud1=pass;
stud2= atkt;
stud3=fail;
printf(“%d %d %d”,stud1,stud2,stud3);
}
a)012          b)123
c)021          d)132

4. What is the output of the following-
void main(){
int k,num=30;
k=num>5?num<=10?100:200:500;
printf(“%d”,num);
}
a)200          b)30
c)100          d)500

5. What is the output of the following-
void main(){
float a=0.7;
if(a<0.7)
printf(“C”);
printf(“C++”);
}
a)C                     b)C++
d)Error                 d)none

6. What is the output of the following-
void main()
{               printf(“%d%d%d”,sizeof(3.14f),sizeof(3.14),sizeof(3.14L));
}
a)4 4 4                    b)4 8 8
c)4 8 10                  d)4 8 12

7.What will be the value of i for the following expression-
int i=3,f=11;
i+=(f>3)?i&2:5;
a)2                   b)5
c)13                  d)12

8.int arr[]={1,2,3,4}
int count;
incr(){return ++count;}
main()
{
arr[count++]=incr();
printf(“arr[count]=%d”,arr[count]);
}
a)1                       b)2
c)3                       d)4

9. What will be output when you will execute following c code?
#include<stdio.h>
void main(){
char *str="ONE"
str++;
switch(str){
case "ONE":printf("ONE");
break;
case "NE": printf("NE");
break;
case "N":  printf("N");
break;
case "E":  printf("E");
}
}
a)ONE                          b)NE
c)N                            d)E

10.What is the output?
main(){
inc();inc();inc();
}
inc(){
static int x;
printf(“%d”,++x);
}
a)012                 b)123
c)3 consecutively     d)111

11.Preprocessing is typically done
a)either before or at the beginning of compilation process.
b)after compilation but before execution
c)after loading
d)none of the above.

12.The statement printf(“%d”,10?0?5:11:12);
prints
a)10     b)0
c)12     d)11

13.The statement printf(“%d”,sizeof(“”));prints
a)an error message   b)0
c)garbage            d)1

14.calloc(m,n); is equivalent to
a)malloc(m*n,0);
b)memset(0,m*n);
c)ptr=malloc(m*n);memset(p,0,m*n);
d)ptr=malloc(m*n);strcpy(p,0);

15.Which of the following comment about union is not true?
a)Union is a structure whose members share the same storage area.
b)The compiler will keep track of what type of information is currently stored.
c)Only one of the members of the union can be assigned a value at a particular time.
d)Size allocate for union is the size of its members needing the maximum storage.

16.Consider the following program segment-
char *a,*b,c[20],d[20];
a=b;
b=c;
c=d;
d=a;
Choose the statements having errors-
a)no error         b)a=b;b=c;
c)c=d;d=a;          d)a=b;d=a;

17.The output of the following program
main(){
int a=1,b=2,c=3;
printf(“%d”,a+=(a+=3,5,a));
}
a)8     b)12
c)9     d)6

18.The declaration int(*p)[5];
Means
a)p is one dimensional array of size 5,of pointers to integers
b)p is a pointer to a 5 element integer array
c)the same as int *p[5];
d)none.

19.What will be the output of the following program if its executed from the command line as follows
Myprog one two three
void main(int argc,char *argv[])
int i;
for(i=1;i<=3;i++)
printf(“%c”,*argv[i]);
}
a)one two three          b)ott
c)Myprog one two         c)none

20. What will be the output of the following program if its executed from the command line as follows
Myprog 1 2 3
void main(int argc,char*argv[])
{
int j;
j=argv[1]+argv[2]+argv[3];
printf(“%d”,j);
}
a)6                b)runtime error
c)compiler error   d)123

21.printf(“%d”,printf(“game”));
a)results in a syntax error
b)outputs game4
c)outputs garbage
d)prints game and terminates abruptly.

22.If abc is the input,then the following program fragment
Char x,y,z;
Printf(“%d”,scanf(“%c %c %c”,&x,&y,&z));results in
a)a syntax error         b)a fatal error
c)segmentation violation d)printing of 3

0 comments:

Post a Comment

visitors count

Blog Ads