No. 1 Fresher Jobs Website in India.
Are you employer? Register to Post Jobs Login
Search Jobs

Hyderabad ,7 June 2010 by KPIT

Details of Hyderabad ,7 June 2010 by KPIT conducted by KPIT for job interview.
Share Us With Others
Hi friends,
i was given the sasken written exam on 6th june in hyderabad...Totally it contains three sections,each section has again three parts like C advanced,C basic,C expert..All are C questions only ,all the question from "TEST YOUR C SKILLS" yashwant kanetkar.....It was an online exam.....




#include

int main()

{



enum Peoplevar1 {Alex=0, Tracy, Kristian} Girls;

enum Peoplevar2 {William=0, Martin } Boys;

switch (Boys)

{

case William:

puts("William");

break;



case Martin:

puts("Martin");

break;



default:

break;

}

return 0;

}







Martin



Compiler error





Runtime error





William







#include

union u

{

int var;

unsigned char str[4];

};

int main()

{

unsigned char tmp;

union u uObj;uObj.var = 3;

tmp = uObj.str[1];

uObj.str[1] = uObj.str[0];

uObj.str[0] = tmp;

printf("%d", uObj.var);

return 0;

}







3





768





Runtime crash





876













An entire structure variable can be assigned to another structure variable if __________





the two variables have the same composition





the two variables are of same type





assignment of one structure variable to another is not possible





None of these















What will be the output of the following program?



#include

#define size 3

enum{a,b,c,d,e};

int main()

{

const cValue[2];

long lValue[size];

signed sValue[e];

printf("%d",sizeof cValue+sizeof lValue+sizeof sValue);

return 0;

}







Compiler error





45





36





20







What will be the output of the following program?



#include

enum myEnum { AB, BC };

int main()

{

enum myEnum a =10;

printf("%d", a);

return 0;

}







Compiler error





1





10





0











#include

int main( )

{

struct a

{

category : 5 ;

scheme : 4 ;

} ;

printf ( "size = %d", sizeof ( struct a ) ) ;

return 0;

}







size = 0





size = 1





size = 4





Compiler error







#include

int main()

{



enum Peoplevar1 {Alex=0, Tracy, Kristian} Girls;

enum Peoplevar2 {William=0, Martin } Boys;

switch (Boys)

{

case William:

puts("William");

break;



case Martin:

puts("Martin");

break;



default:

break;

}

return 0;

}







Martin





Compiler error





Runtime error





William











What will be the output of the following program?



#include

union u

{

int var;

unsigned char str[4];

};

int main()

{

unsigned char tmp;

union u uObj;uObj.var = 3;

tmp = uObj.str[1];

uObj.str[1] = uObj.str[0];

uObj.str[0] = tmp;

printf("%d", uObj.var);

return 0;

}











3





768





Runtime crash





876





An entire structure variable can be assigned to another structure variable if __________





the two variables have the same composition





the two variables are of same type





assignment of one structure variable to another is not possible





None of these









Consider following code snippet:



#include

int main( )

{

int i = 5 , j = 2 ;

fun ( &i, &j ) ;

printf ( "\n%d %d", i, j ) ;

return 0;

}



Which of the following option is correct about function fun( ) so that value of i and j becomes 25 & 4?





void fun ( int i , int j )

{

i = i * i ;

j = j * j ;

}







void fun ( int &i , int &j )

{

i = i * i ;

j = j * j ;

}







void fun ( int *i , int *j )

{

*i = *i * *i ;

*j = *j * *j ;

}







void fun ( int *i , int *j )

{

i = i * i ;

j = j * j ;

}











What will be the output of the following program?



#include

int function(int i)

{

if(i s ) ;





free ( s, p ) ;





free ( p ) ;





free ( p -> s ) ; free ( p ) ;







#include

int main()

{

unsigned int i = -1;

printf("%s","Welcome");

if(i>-5)

main();

return 0;

}



Infinite loop





Stack overflow





Calling main inside main is illegal





Welcome











#include

int main()

{

int a[5] = {1,2,3,4,5};

int *ptr = (int*)(&a+1);

printf("%d %d",*(a+1),*(ptr-1));

return 0;

}





2 1





2 2





2 5





None of these











What will be the output of the following program?



#include

int main()

{

FILE * fp = NULL;

char str[100]="abcdefghij";

fp = fopen("MyFile.txt","w");

while(!feof(fp))

{

fscanf(fp,"%s",str);

fprintf (fp, "[%-10.10s]\n",str);

}

fclose(fp);

return 0;

}







MyFile.txt will contain abcdefghij







Infinite loop





Compiler error





Runtime error









#include

int bags[5]={20,5,20,3,20};

int main()

{

int pos=5,*next();

*next()=pos;

printf("%d %d %d", pos, *next(), bags[0]);

}

int *next()

{

int i;

for(i=0;iy[0]=,a,;

sobj1->y[0]=,b,;sobj2=sobj1;

printf("%d%c%c",sobj2->x, sobj2->y[0],sobj2->y[1]);

return 0;

}









Compiler warning





10ab





Runtime error





Compiler error









#include

int main( )

{

int x , y , z ;

x = y = z = 1;

z = ++x || ++y && ++z ;

printf ( "x = %d y = %d z = %d \n", x , y , z ) ;

return 0;

}









x = 2 y = 1 z = 1





x = 1 y = 2 z = 1





x = 2 y = 2 z = 2





x = 2 y = 2 z = 1







What will be the output of the following program?



#include

int main();

int printf(const char*,Ave);

int main()

{

int i=100,j=10,k=20;

int sum;

float ave;

char myformat[]="ave=%.2f";

sum=i+j+k;

ave=sum/3.0;

printf(myformat,ave);

return 0;

}









Prints nothing





Runtime error





ave=43.33





Compiler error









#include

int main()

{

char *svar[]={ "Fruits","Vegetables","Meat","Fish"};

char **pvar;

pvar=svar;

printf("%s",++*pvar);

printf("%s",*pvar++);

printf("%s",++*pvar);

return 0;

}









Fruits Vegetables Meat Fish





ruitsruitsegetables





Fruits, Vegetables





Compiler error







#include

int main()

{

union Test_union

{

int a; float b; long c;

}

u;

struct Test_struct

{

int a; float b; long c;

}

s;

u.a = 1;

u.b = 2;

u.c = 3;

s.a = u.a;

s.b = u.b;

s.c = u.c;

printf("%d\t%f\t%d",s.a,s.b, s.c);

return 0;

}







Which one of the following statements is TRUE about a function?





Each function except main function shares the same stack





Other functions share the same stack as the main function





In case of a buffer overflow the saved registers are affected





None of these









If we don�t specify any return type for a function, then the function returns __________.







float





double





integer





void









#include

int main()

{

int itype = 2;

float type=(int)itype;

switch(itype)

{

default:printf("zero");

case 2:printf("2.3f");break;

case 3:printf("3.4f");break;

case 4:printf("4.4f");break;

}

return 0;

}







zero2.3f





4.4f





2.3f





zero









#include

void print(int i);

int main()

{

static int i;

print(i++);

getch();

}

void print(int i)

{

if(i==5)

{

return;

}

print(i++);

printf("%d", i);

}





Stack overflow





5 4 3 2 1





Compiler error





4 3 2 1 0







#include

#define macIntFunc(n) func(n)

int func(int n)

{

return (! ( n & ( n-1 )));

}

int main()

{

printf("%d", macIntFunc(8));

return 0;

}







Compiler error





1





Compiler warning





None of these







Consider test1, test2, test3 as three functions. In which order will the functions be called in the following expression?



a = test1() * test2() / test3() + test3;







Compiler dependent





test3, test2, test1





test2, test3, test1





test1, test2, test3











#include

int main()

{

int i=1;

while (i2)

goto here;

i++;

}

return 0;

}

fun()

{

here:

printf("PP");

}









Compiles successfully





Runtime error





Compiler error





None of these









From the following statements, select the correct way of declaring a function pointer which accepts two integer arguments and returns an integer value?







int (*fp)(int, int);





int *fp(int, int)





(int*) fp(int, int)





(int *fp) (int, int)









What will be the output of the following program?



#include

int main( )

{

int i ;

i = fun( ) ;

printf ( " %d ", i ) ;

return 0;

}

int fun( )

{

int _AX = 1990 ;

return _AX;

}











19





Runtime error





Compiler error





1990







Consider the following variable declarations:



float var1;

double var2;



Which one of the following is the correct way to scan the above two variables?











scanf("%f %f ", &var1,&var2);





scanf("%Lf %Lf ", &var1,&var2);





scanf("%f %Lf ", &var1,&var2);





scanf("%Lf %f ", &var1,&var2);









Which one of the following is the correct option that substitutes // deallocate memory in the following program?





#include

int main( )

{

struct ex

{

int i ;

float j ;

char *s ;

} ;



struct ex *p ;

p = ( struct ex * )

malloc ( sizeof ( struct ex ) ) ;

p -> s = ( char * ) malloc ( 20 ) ;

// deallocate memory

return 0;

}







free ( p ) ;





free ( s, p ) ;





free ( p -> s ) ;





free ( p -> s ) ; free ( p ) ;







What is TRUE about the code written below?



char *s1 = "Clueless";

char s2[] ="Clueless";

char *s3 = "Clueless";



1. s1 and s3 may share the same memory area

2. s1,s2 and s3 may share the same memory area

3. s1,s2 and s3 do not share the same memory area











1





2





3





4











What will be the output of the following program ?



#include

int main()

{

char *str1="abcd";

char str2[]="abcd";

printf("%d %d", sizeof(str1), sizeof(str2));

return 0;

}









1 4





1 1





1 5





4 5











#include

int main()

{

int aaddr[]={5,4,3,2,1};

int xaddr,yaddr;

int *paddr=&aaddr[2];

*paddr++;

xaddr=++*paddr;

yaddr=*(paddr++);

printf("%d %d",xaddr,yaddr);

return 0;

}







Compiler error





2 2





1 1





3 3









Question Number 8



What will be the output of the program below, if MyFile.txt contains abcdefghij?





#include

int main()

{

FILE* fp = NULL;

unsigned char c;

fp = fopen("MyFile.txt","r");

while((c = getc(fp)) != EOF)

putchar(c);

fclose(fp);

return 0;

}







abcdefghij followed by infinite loop





Stack overflow





Infinite loop





Runtime error











What will be the output of the following program?



#include

int main()

{

int *cptr, c;

int *vptr, v;

c=10; v=0;

cptr=&c; vptr=&v;

printf("%d %d ", c, v);

return 0;

}







10 10





Compiler error





10 0





Runtime error











The function unlink(filename) is used to __________.







remove link between file and buffer





remove the existing file from the directory





remove the contents of file only





None of these







What will be the output of the following program?



#include

int main( )

{

int a [ ] = {2, 4, 6, 8, 10 } ;

int i ;

for ( i = 0 ; i