Saturday, 18 May 2013

Challenging C Interview Objective Questions



1. void main()

{

char s[ ]="man";

int i;

for(i=0;s[ i ];i++)

printf("\n %c", i[s] );

}//What is o/p?

(A)man (B) nam

(C)mmm (D)compilation error



2. main( ){

static int var = 5;

if(--var)

main();

printf("%d ",var++);

}//What is o/p?

A)0 1 2 3 4 B)1 2 3 4 5

C) compile error D)0 0 0 0 0

3. main() {

printf("\rbba");

printf("\baab");

printf("\raa");

}//What is o/p?

A) aa B)aaaab

C)aabab D)bbaaa



4. void main()

{

char str[] = "Hello World";

display(str);

}

void display(char *string)

{

printf("%s",string);

}//What is o/p?

(A)Hello World (B) Hello

(C)H (D)Compilation Error

5. void main()

{

int a[3][2][2] = { {1,2,3,4}, {5,6,7,8},{9,10,11,12} };

int *p,*q;

p=&a[3][2][2];

*q=***a;

printf("%d-%d",*p,*q);

}//What is o/p?

(A)12-1 (C)9-1

(C)1-12 (D)None of these

6. #define f(a,b) a/b

void main() {

int x=5,y=6;

printf("\n%d",f(x*6,y*x));

}//What is o/p?

(A)1 (B)25

(C)30 (D)None of these

7. void main( ) {

char *ch="Computer ";

while(*ch!='\0') {

++*ch;

printf("%c ",*ch); ch ++; }

}//What is o/p?

(A)Dpnqvufs (B)Donpvtfr

(C)Cpmquues (D)None of these

8. void main( ) {

static char names[5][7]={"pascal","java","cobol","fortran","perl"};

int i;

char *ch;

ch=names[3];

names[3]=names[4];

names[4]=ch;

printf("%s",names[4]);

}

(A)Compilation Error : Array index out of Bound

(B)Compilation Error: char Array is constant Pointer

(C)fortran

(D)perl



9. void main( ) {

int x=10,y=10,*p1,*p2,k;

p1=&x;

p2=&y;

k=5 + *p1 /*p2;

printf(“%d”,k);

}

A)6 B)5 c)Compile Error d)None of these

10. main( ) {

char *q;

int j;

for (j=0; j<3; j++) scanf(“%s” ,(q+j));

printf(“%s” ,(q));

}//Input are:ASPIRE,JAVA,OCJP

(A)AJOCJP (B)ASPIRE

(C)OCJP (D)None of these

11. void main ( ) {

static char *ch[ ] = {"black", "white", "yellow", "violet"};

char **ptr[ ] = {ch+3, ch+2, ch+1, ch}, ***p;

p = ptr;

**++p;

printf(" %s",(*--*--p + 4));

}

(A)ow (B)et

(B)k (D)e

12. f2(a,b)

int a;

float b; {

return( a = !(a==b) );

}

void main() {

int p1(), f2();

printf("The value is %d \n ",p1(f2,6,6.0));

}

p1(f2,val1,val2)

int (*f2) ();

int val1;

float val2;

{

return((*f2) (val1,val2));

}

(A) The value is 0 (B) The value is 1

(C) The value is 0.0 (D)Compilation Error



13. f(int n) {

If(n>0) return (n + f(n-1));

}

void main() {

printf(“%d”,f(10));

}

(A)55 (B)110

(C)45 (D)compilation error

14. void main() {

Char *ch = “hello”;

printf(ch);

}

(A) hello (B) compilation error

(C)run time error (D) None of these

15. void main(){

int x=1,y=0;

if (++x > 2)

if(++y<5)

y=100;

else

x=100;

printf(“ %d %d”, x,y);

}

A)100 0 B)100 100 C)100 2 D)None of these





16. what is the output of following?

void main(){ printf("%d",1||2); }

a. error b .1 c. 3 d. None of these

17. What is the output of following ?

void main(){

int i=100, j=200 , k=300;

printf("%d ,%d" ) ; }

a. 200,300 b. 300,200 c. 100,200 d .error

18.What is the output of following ?

abc(int i){

printf("%d",i); }

void main(){

abc((200,100)); }

a. 200 b . 100 c . compile time error d. run time error

19.What is the output of following ?

void main() {

abc() ; }

abc(){

printf("Hello");}

a. error of no prototype b. warning c . Hello d. Both b & c

20. What is the output of following code ?

void main(){

printf("ab\b"); printf("ab\r"); printf("a"); }

a. aaa b. abb c. aba d.None

21.What is the output of following code ?

void main(){

int far *p,*q;

int c;

c=sizeof(p)*sizeof(q)*sizeof(4); printf("%d",c);}

a. 4 b. 32 c. 8 d. 16

22.What is output ?

void main(){

int i=5;

printf("%d",(i++ + ++i) || (++i + ++i));

printf(" %d",i);}

a. 1 9 b. 1 6 c. 1 7 d. compiler dependent

23.What is the output?

#define fun(x,y) (x##y)

void main(){int i

;i=fun(200+5,5+200);

printf("%d",i); }

a. run time error b. 1 c. 455 d. 205205

24.What is output ?

void main (){int x ; printf("%d",x=10);}

a. Error b. 10 c. 1 d. garbage value

25.What is the output ?

void main()

{ int a,b=0;

if( a=b=0 )

printf (" Hello ");

else

printf ("World"); }

a. Hello b. World c. compile error d. Runtime error

26.Waht is the output ?

void main(){

int i,j,k;

printf("%d",printf("%d",scanf("%d", &j)*scanf("%d",&i))); }// input is i=10 j=10

a. 100 b. 11 c. 1 d. 0

27-What is output of following ?

void main(){

static int i;

for( ; i++ ; printf("%d ", i) );

printf("%d",i); }

a. infinite loop b. error c. 0 d. 1

28-int testarray [3] [2] [2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

What value does testarray [2][1][0] in the sample code above contain?

a. 3 b. 5 c. 7 d. 11

29-void myFunc (int x) {

if (x > 0)

myFunc(--x);

printf("%d, ", x); }

int main() { myFunc(5); return 0; }

What will the above sample code produce when executed?

a. 1, 2, 3, 4, 5, 5, b. 4, 3, 2, 1, 0, 0 c. 5, 4, 3, 2, 1, 0, d. 0, 0, 1, 2, 3, 4,

30-11 ^ 5

What does the operation shown above produce?

a. 1 b. error c. 5th power of 11 d. 14

31-What is the output of following

#define man(x,y) x>y?x:y;

void main(){

int i=10 , j ,k;j=5;k=0;

k=man ( i++ , ++j );

printf("%d %d %d",i,j,k);}

a. 12 6 11 b. 11 6 10 c. 11 6 11 d. 12 6 10

32-What is the output of following ?

#define mess junk

void main(){ printf("mess"); }

a. mess b. junk c. meshjunk d. error that mess cant be used in printf

33-Wha is the output of following ?

void main() { int g=300*300/300; printf("%d",g); }

a. 300 b. 81 c. error d. 1

34-#define square(x) x*x

void main(){ int i=10, j=5 ,k=0; k=square(i-j); printf("%d",k); }

a. 25 b. 45 c. 75 d. 0

35-What is the output of following?

void main(){ int i=024; printf("%d",i); }

a. 24 b. 024 c. 20 d. None

33-What is the output of following ?

void main(){

char *p; p="He"LL"o"; printf("%s",p); }

a. he"LL"o b. HeLLo c. error d. He

34-What is output ?

abc(){

int a;

if(1>0)

return 1;

a=100;

a++;

return ++a;}

void main(){

int i ; i=abc(); printf("%d",i);}

a. 1 & 1 warning b. 1 & 2 warning c. 1 & 3 warning d. 111

35- What is the output ?

abc(int i){ return i; }

void main(){

int i; i=abc(printf("Hello World")); printf("%d",i); }

a. 11 b. error c. 12 d. None

//36-What is the output ?

void main(){

char far* near* str; printf("%d",sizeof(str)); }

a. 2 b. 4 c. error d. 1

37-What is the output ?

void main(){

const int i; int k=10; i=100; k=++k + i; printf("%d",k); }

a. 111 b. error c. 112 d. None

38-What is the output ?

#define printifless(x,y) if(x<y) printf("%d",x)

void main(){

int i=2,k=1;

if(i>0 && k>0)

printifless(i,k);

else

printf("A"); }

a. A b. nothing c. error d. 2

39-What is the output ?

void main(){

int a=10,b=20,c=30,d=40;

if(a,b,c,d)

printf("Hello"); }

a. Hello b. error c. warning d. Hello10203040

40-What is the output?

main(){

int i=100,j=10,k;

int *p=&j; k=i/*p;

printf("%d",k);}

a. 10 b. error c. warning d. 1

41-What is the output?

main(){

extern int i ; i=20; printf("%d",i);}

a. compile error b. runtime error c. linker error d. 20

42-What is the output ?

main(){

int i=-1 ,j=-1,k=0,l=2,m;

m=i++ && j++ && k++ || l++;

printf("%d %d %d %d %d",i,j,k,l,m);}

a. error b. 0 0 1 3 1 c. 0 0 1 3 2 d. warning

43- main(){

static int i;

switch(i) {

default:printf("garbage");

case 0: printf("Zero"); break;

case 1:printf("one"); break;

case 2: printf("two"); break; } }

a. error b. zero c. garbage zero d. zero grabage

44-What is output ?

main(){

printf("%x",-1<<4);}

a. ff00 b. ffff c. 240 d. None

//45-What is output ?

main(){int i=5; printf("%d%d%d%d%d",i++,i--,++i,--i,i); }

a. 54554 b. 45545 c. 54454 d. 45445

46-.What is the output ?

#define square(x) x*x

main(){

int i;

i = 64/square(4);

printf("%d",i);}

a. 16 b. 64 c. 4 d. error

47-Size of structure can be determined by

1-sizeof(variablename) 2-sizeof(struct tag)

a. only 1 b. only 2 c. both 1 & 2 d. none

48-What is the output ?

main(){

printf("%p",main);}

a. some address b. undefined symbol error c. 0xfa d. None

49-#define int char

main(){

int i=65;

printf("%d",sizeof(i));}

a. error b. 1 c. 2 d. 0

50-What is the output ?

main(){

char string[]="Hello World";

display(string);}

void display(char *string){

printf("%s",string);}

a. "Hello World" b. Hellow World c. error d. warning & Hello World



3. main( ) {

float c[]={1,2.2,3.2};

float i,*p=c,*q=c;

for( i =0; i<3;i++,*q++;)

printf("%2.1f ",*c);

for(i=0 ; i<3 ; i++,(*p)++)

printf("%2.1f ",*p);

}//What is o/p?

A)1.0 2.2 3.2 1.0 2.2 3.2 B)1.0 1.0 1.0 1.0 2.2 3.2

C)1 2 3 1 2 3 D)1 1 1 1 2 3

14. void main() {

void f1();

void f2();

f1();

}

void f1() {

f2();

printf(“in f1”);

}

void f2() {

printf(“in f2”);

}//what is o/p?

(A) Compilation Error (B)in f2

(C) in f2in f1 (D)None of these

16. void main() {

char *p; int *q; long *r;

p=q=r=0;

p++; q++; r++;

printf("%p...%p...%p",p,q++,r++);

}

A)0001...0004...0008 B)0001...0002...0004

C)0001...0002...0002 D)0002...0004...0008

17-What is a difference between a declaration and a definition of a variable?

a. Both can occur multiple times, but a declaration must occur first.

b. A definition occurs once, but a declaration may occur many times.

c. A declaration occurs once, but a definition may occur many times.

d. Both can occur multiple times, but a definition must occur first.

28-What is the output ?

void main() { char *s="\12345s\n"; printf("%d",sizeof(s)) }

a. 7 b. 6 c. 8 d. 5







































No comments:

Post a Comment