documentc

102
C and C++: HCL 1.enum day = { jan = 1 ,feb=4, april, may} what is the value of may? a)4 b)5 c)6 d)11 e)none of the above ans:c 2.main { int x,j,k; j=k=6;x=2; ans x=36 x=j*k; printf("%d", x); } 3. fn f(x) { if(x<=0) return; ans fn(5) ....? else f(x-1)+x; } 4. i=20,k=0; for(j=1;j<i;j=1+4*(i/j)) { k+=j<10?4:3; } printf("%d", k); ans k=4 5. int i =10 main() { int i =20,n; for(n=0;n<=i;) { int i=10

Upload: takiisc

Post on 22-Nov-2014

169 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Documentc

C and C++:

HCL

1.enum day = { jan = 1 ,feb=4, april, may}what is the value of may?a)4 b)5 c)6 d)11e)none of the aboveans:c2.main{int x,j,k;j=k=6;x=2; ans x=36x=j*k;printf("%d", x);}3. fn f(x) { if(x<=0) return; ans fn(5) ....?else f(x-1)+x;}

4. i=20,k=0;for(j=1;j<i;j=1+4*(i/j)){k+=j<10?4:3;}

printf("%d", k); ans k=4

5. int i =10main(){int i =20,n;for(n=0;n<=i;){int i=10 i++;}printf("%d", i); ans i=20

6. int x=5; y= x&y( MULTIPLE CHOICE QS)

Page 2: Documentc

ans : c

7. Y=10; if( Y++>9 && Y++!=10 && Y++>10)printf("........ Y);else printf("".... )ans : 13

8. f=(x>y)?x:ya) f points to max of x and yb) f points to min of x and yc)errord) ........

ans : a

9. if x is even, then(x%2)=0x &1 !=1x! ( some stuff is there)

a)only two are correctb) three are correctc), d) ....ans : all are correct

10. which of the function operator cannot be over loadeda) <=b)?:c)==d)*

ans: b and d

11.macros and function are related in what aspect? (HCL)a)recursion b)varying no of argumentsc)hypochecking d)type declaration

12.preproconia.. does not do one of the following (HCL)a)macro ...... b)conditional compliclationc)in type checking d)including load file

Page 3: Documentc

13) struct doublelist { double clinked int det; list void struct previous; be given and a procedure to delete struct new; an element will be given } delete(struct node) { node-prev-next node-next; node-next-prev node-prev; if(node==head) node } in what case the prev was (a) all cases (b) it does not work for last element (c) it does not work for-----Ans:b(14) similar type question ans: all don't work for non null value

(15) void function(int kk) { kk+=20; } void function (int k) int mm,n=&m kn = k kn+-=10; }

16) main(){ int var=25,varp; varp=&var; varp p = 10; fnc(varp) printf("%d%d,var,varp);} (a) 20,55(b) 35,35(c) 25,25(d)55,55

17) What are the differences between Pascal and C.Ans) Pascal is a strongly typed language.

Page 4: Documentc

18) int a=1,b=2,c=3; printf("%d,%d",a,b,c);

What is the output?19) The feature C++ have and c donot have

Variables can be declared inside also.20) Floating point representation

2's complementHUGHES

21) It is recommended to use which type of variables in a recursive module.Ans. static variables.

22) proc() {

static i=10;printf("%d",i);}

If this proc() is called second time, what is the o/p Ans. 11

23. int arr[] = {1,2,3,4} int *ptr=arr; *(arr+3) = *++ptr + *ptr++; Final contents of arr[] Ans. {1,2,3,4}

24. c programs func() { static int i = 10; printf("%d",i); i++; }

what is the value of i if the function is called twice ?Ans : 1125) f(char *p){ p[0]? f(++p):1;printf("%c",*p);}if call that fuction with f(Aabcd) what is the output??ans:dcbaA (Just reversing the string

26) f(char *p) { p=(char *)malloc(sizeof(6));strcpy(p,"HELLO");}main()

Page 5: Documentc

{ char *p="BYE"; f(p)printf("%s",p);}what is the o/p???ans:HELLO

27)Strings in Javaa)Mutableb)variable length stringc)...d)....

28)If "AaBbCc" is passed to the charchar x(*a){a[0]?x(a+1):1;printf("%c",a[0]);return 1;}what will be the output?

29. f(*p) { p=(char *)malloc(6); p="hello"; return; } main() { char *p="bye"; f(p); printf("%s",p); } what is the o/p? ans:bye

30) which is related to threada. separate switching regb. " stackc. " address space31) in global static variable , declartion in a filea. localization of scopeb. persistance of the value through out the file32) about subroutine, precondition is false. what about post condition

Page 6: Documentc

a. post condition is not definedb. post condition is always true

33) in product of x and y, if(x=0|y=0) y=1; else y=0; (not cleared)what is cyclometric complexity? a. 3 b. 2 c. 1 d. 0

35)global variables in different files area:at compiletimeb) loading timec) linking timed)execution time

36)size of(int)a) always 2 bytesb) depends on compiler that is being usedc) always 32 bitsd) can't tell

37)which one will over flow given two programs2prog 1: prog2:

main() main(){ {int fact; int fact=0long int x; for(i=1;i<=n;i++)fact=factoral(x); fact=fact*i;

} }

int factorial(long int x){

if(x>1) return(x*factorial(x-1);}

Page 7: Documentc

a) program 1;b) program 2;c) both 1 &2d) none

}

37) variables of fuction call are allocated ina) registers and stackb) registers and heapc) stack and heapd)

38) main(){char str[5]="hello";if(str==NULL) printf("string null");else printf("string not null");}what is out put of the program?a) string is null b) string is not null c) error in program d) it executes but print nothing

39) void f(int value){for (i=0;i<16;i++){if(value &0x8000>>1) printf("1")else printf("0");}}what is printed?a) bineray value of argument b)bcd value c) hex value d) octal value

40)void f(int *p){static val=100;val=&p;}main(){int a=10;printf("%d ",a);f(&a);printf("%d ",a);}what will be out put?a)10,10

41)

Page 8: Documentc

struck a{int x;float y;char c[10];}union b{int x;float y;char c[10];}which is true?a) size of(a)!=sizeof(b);b)c)d)

42)# define f(a,b) a+b#defiune g(c,d) c*d

find valueof f(4,g(5,6))a)26 b)51 c) d)

43)main(){char a[10]="hello";strcpy(a,'\0');printf("%s",a);}out put of the program?a) string is null b) string is not null c) program error d)

44) char a[5][15];int b[5][15];address of a 0x1000 and b is 0x2000 find address of a[3][4] and b[3][4]assume char is 8 bits and int is 32 bits

a) b) c) d)45) main() { fork();fork();fork();printf("\n hello");}

Page 9: Documentc

How many times print command is executed?

46)main(){ int i,*j; i=5;j=&i;printf("\ni= %d",i); f(j);

printf("\n i= %d",i);}

void f(int*j){int k=10; j= &k;}

output isa 5 10b 10 5c 5 5d none

47) main(){ int *s = "\0";

if(strcmp(s,NULL)== 0) printf("\n s is null")p else printf("\n s is not null");}

48) size of integer is a. 2 bytes b 4 bytes c. machine dependant d compiler dependent.

49) int a[5][4] int is 2 bytes base address for array is 4000(Hexa) what will be addr for a[3][4]? int is 4 bytes same question.

Page 10: Documentc

IBM

50)what will be the result of executing following program main { char *x="new"; char *y="dictonary"; char *t; void swap (char * , char *); swap (x,y); printf("(%s, %s)",x,y);

char *t; t=x; x=y; y=t; printf("-(%s, %s)",x,y); } void swap (char *x,char *y) { char *t; y=x; x=y; y=t; }

a).(New,Dictionary)-(New,Dictionary) b).(Dictionary,New)-(New,Dictionary) c).(New,Dictionary)-(Dictionary,New) d).(Dictionary,New)-(Dictionary,New) e).None of the above (Ans will be b or e) check

51).If a directory contains public files (can be valied and used by any one ) which should not be altered ,the most liberal permissions that can be given to the directory is a)755 b)777 c)757 d)775 e)None of the above (Ans a)

52) what would the following program results in main()

Page 11: Documentc

{ char p[]="string"; char t; int i,j; for(i=0,j=strlen(p);i> { t=p[i]; p[i]=p[j-i]; p[j-i]=t; } printf("%s",p); } a)will print:string b)will not print anything since p will be pointing to a null string c)will print:gnirtS d)will result in a complication error e)will print invallid characters(junk) (Ans will be b ) check

53) After the following command is executed $ ln old new a listing is performed with the following output $ ls -li

total 3 15768 -rw-rw-rw- 2 you 29 Sep 27 12:07 old 15768 " " " " " " " " new 15274 " " 1 " 40 " " 09:34 veryold

which of the following is true a)old and new have same i-node number,2 b) " " " " " " " , 15768 c)old and new have nothing yo do with each other d)very old and new are linked e)very old and old are linked (Ans is b)

54) What will be the result of executing the following statement int i=10; printf("%d %d %d",i,++i,i++); a).10 11 12 b).12 11 10 c).10 11 11 d).result is OS dependent e).result is compiler dependent (Ans is e)

Page 12: Documentc

55) What does extern means in a function declaration a)the funct has global scope b)the funct need not be defined\ c)nothing really d)the funct has local scope only to the file it is defined in e)none of the above (Ans will be c)

56) What will be result of the following program main() { void f(int,int); int i=10; f(i,i++); } void f(int i,int j) { if(i>50) return; i+=j; f(i,j); printf("%d,",i); } a).85,53,32,21 b)10,11,21,32,53 c)21,32,53,85 d)32,21,11,10 e)none of the above (Ans is e)

57)What will be the result of the following program main() { char *x="String"; char y[] = "add"; char *z; z=(char *) malloc(sizeof(x)+sizeof(y)=1); strcpy(z,y); strcat(z,y); printf("%s+%s=%s",y,x,z); } a)Add+string=Add string b)syntax error during compilation c)run time error/core dump d)add+string= e)none

Page 13: Documentc

(Ans will be e consider cap&small leters)

58)What does the following expression means? char *(*(*a[N])())(); a) a pointer to a function returning array of n pointers to function returning character pointers b) a function return array of N pointers to funcions returning pointers to characters c) an array of n pointers to function returning pointers to characters d)an arrey of n pointers to function returning pointers to functions returning pointers to characters e) none of the above (ANS IS d)

59)enum number { a=-1, b= 4,c,d,e} what is the value of e ? 7,4,5,15,3 (ans is 7 ) check again

60) Result of the following program is main() { int i=0; for(i=0;i> { switch(i) case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error (Ans is d )

61) What is the result main() { char c=-64; int i=-32 unsigned int u =-16;

Page 14: Documentc

if(c>i){ printf("pass1,"); if(c> printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i> printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none (Ans is c)

63) what will the following program do? void main() { int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15//

a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1 Ans) b

64) In the following code segment what will be the result of the function, value of x , value of y

{

Page 15: Documentc

unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); }

a) same, MAXINT, -1 b) not same, MAXINT, -MAXINT c) same , MAXUNIT, -1 d) same, MAXUNIT, MAXUNIT e) not same, MAXINT, MAXUNIT Ans) a

65) what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; }

main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these Ans) b

66) What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() {

Page 16: Documentc

char *g="String"; myalloc(g,20); strcpy(g,"Oldstring"); printf("The string is %s",g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these Ans) c ( check it )

67) What will be the result of the following program? main() { char p[]="String"; int x=0;

if(p=="String") { printf("Pass 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } }

a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation

68) Which of the choices is true for the mentioned declaration ? const char *p; and char * const p;

Page 17: Documentc

a) You can't change the character in both b) First : You can't change the characterr & Second : You can;t change the pointer c) You can't change the pointer in both d) First : You can't change the pointer & Second : You can't chanage the character e) NoneAns) b ( check it)

69) what will be the result of executing following program main { char *x="new"; char *y="dictonary"; char *t; void swap (char * , char *); swap (x,y); printf("(%s, %s)",x,y); char *t; t=x; x=y; y=t; printf("-(%s, %s)",x,y); } void swap (char *x,char *y) { char *t; y=x; x=y; y=t; } a).(New,Dictionary)-(New,Dictionary) b).(Dictionary,New)-(New,Dictionary) c).(New,Dictionary)-(Dictionary,New) d).(Dictionary,New)-(Dictionary,New) e).None of the above (Ans will be b or e) check

70) what would the following program results in main() { char p[]="string"; char t; int i,j;

Page 18: Documentc

for(i=0,j=strlen(p);i> { t=p[i]; p[i]=p[j-i]; p[j-i]=t; } printf("%s",p); } a)will print:string b)will not print anything since p will be pointing to a null string c)will print:gnirtS d)will result in a complication error e)will print invallid characters(junk) (Ans will be b ) check

71) What will be the result of executing the following statement int i=10; printf("%d %d %d",i,++i,i++); a).10 11 12 b).12 11 10 c).10 11 11 d).result is OS dependent e).result is compiler dependent (Ans is e)

72) What does extern means in a function declarationa)the funct has global scopeb)the funct need not be defined\

c)nothing really d)the funct has local scope only to the file it is defined in e)none of the above (Ans will be c)

73) What will be result of the following program main() { void f(int,int); int i=10; f(i,i++); } void f(int i,int j) { if(i>50) return; i+=j; f(i,j); printf("%d,",i);

Page 19: Documentc

} a).85,53,32,21 b)10,11,21,32,53 c)21,32,53,85 d)32,21,11,10 e)none of the above (Ans is e)

74) What will be the result of the following segment of the program main()

{ char *s="hello world"; int i=7; printf("%.*%s",s); } a)syntax error b)hello w c) Hello d) o world e) none (Ans is b)

75) What will be the result of the following programmain(){int a,b;printf("enter two numbers :");scanf("%d%d",a,b);printf("%d+%d=%d",a,b,a+b);}a) will print the sum of the numbers entered

b) syntax error during compilationc) will generate run time error /core dump

d) will print the string "a+b = a+b" on the screen e) none of these (Ans is c)

76) What is the size of 'q'in the following program? union{ int x; char y; struct { char x; char y; int xy;}p; }q;

Page 20: Documentc

a)11 b)6 c)4 d)5 e)none (Ans is b why because no of bytes for int =4 given in instructions)

77) What will be the result of the following program main() { char *x="String"; char y[] = "add"; char *z; z=(char *) malloc(sizeof(x)+sizeof(y)=1); strcpy(z,y); strcat(z,y); printf("%s+%s=%s",y,x,z); } a)Add+string=Add string b)syntax error during compilation c)run time error/core dump d)add+string= e)none (Ans will be e consider cap&small leters) 78)What does the following expression means? char *(*(*a[N])())();

a) a pointer to a function returning array of n pointers to function returning character pointers

b) a function return array of N pointers to funcions returning pointers to characters c) an array of n pointers to function returning pointers to characters d)an arrey of n pointers to function returning pointers to functions returning pointers to characters e) none of the above (ANS IS d)

79) enum number { a=-1, b= 4,c,d,e}what is the value of e ?

7,4,5,15,3 (ans is 7 ) check again

80) Q) Result of the following program is main() { int i=0; for(i=0;i> { switch(i)

Page 21: Documentc

case 0:i+=5; case 1:i+=2; case 5:i+=5; default i+=4; break;} printf("%d,",i); } } a)0,5,9,13,17 b)5,9,13,17 c)12,17,22 d)16,21 e)syntax error (Ans is d )

81) What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c> printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i> printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none (Ans is c) 82) In the process table entry for the kernel process, the process id value is a) 0 b) 1 c) 2 d) 255 e) it does not have a process table entry Ans) a

83) what will the following program do? void main() {

Page 22: Documentc

int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1 Ans) b 84) In the following code segment what will be the result of the function, value of x , value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); } a) same, MAXINT, -1 b) not same, MAXINT, -MAXINT c) same , MAXUNIT, -1 d) same, MAXUNIT, MAXUNIT e) not same, MAXINT, MAXUNIT Ans) a

85) What will be the result of the following program? main() { char p[]="String"; int x=0;

Page 23: Documentc

if(p=="String") { printf("Pass 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } } a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation 86) Which of the choices is true for the mentioned declaration ? const char *p; and char * const p; a) You can't change the character in both b) First : You can't change the characterr & Second : You can;t change the pointer c) You can't change the pointer in both d) First : You can't change the pointer & Second : You can't chanage the character e) None Ans) b ( check it) 87) The redirection operators > and >> a) do the same function b) differ : > overwrites, while >> appends c) differ : > is used for input while >> is used for output d) differ : > write to any file while >> write only to standard output e) None of these Ans) b

Page 24: Documentc

Optimize the below 1,2,3,4 questions for time:

1)int i;if i=0 then i:=1;if i=1 then i:=0;

2)int i;if i=0 then i:=1;if i=1 then i:=0;(given that i can take only two values (1,0))

3)int i;if i=0 then i:=1;else if i=1 then i:=0;(given that i can take only two values (1,0))

4)int m,j,i,n;for i:=1 to n dom:=m+j*n

92) In the following questions, answer A,B,C,D depending on when the errors are detected? A if no error is detected B if semantic and syntactic checking C if during Code genration & Symbol allocation D run time

a) Array overboundb) Undeclared identifierc) stack underflowd) Accessing an illegal memory location

93) A question on call by value, call by name, call by reference.

f(x,y,z){y := y+1;z := z+x;}main()

Page 25: Documentc

{int a,b;a := 2b := 2;f(a+b,a,a);print a;}what is the value of a printed for three different calls in main.

94) int i=0;int j=0;

loop: if(i = 0) i++; i++; j++; if(j<= 25) goto loopxxx: question1 : how many times is the loop entered A few questions of that sort. some count fundaes. Easy one )

95) Max number of nodes in a binary tree with height 3 is 20 : Ans: False

96) 10,20,30,40,50,60 : give the order when put in a queue and in a stack Ans : Queue : 10,20,30,40,50,60 stack : 60,50,40,30,20,10 97) Debugging is the process of finding Ans : logical and runtime errors 98) trace the error: void main(){ int &a; /* some other stuff here */ } Ans: syntax error 99)a problem with a function named 'myValue' will be given and asked to find the value of main() for an argument of 150, Ans : 150

100) ex:define max 10main()

Page 26: Documentc

{int a,b;int *p,*q;a=10;b=19;p=&(a+b);q=&max;} Q a)error in p=&(a+b) b)error in p=&max c)error in both d) no error

MBT101) #include <stdio.h> * What is wrong in the following problemmain() {int i,j;j = 10;i = j++ - j++;printf("%d %d", i,j);}ans: 0, 12

102)#include <stdio.h> * What is the output of the following problemmain() {int j;for(j=0;j<3;j++) foo();}foo() {static int i = 10;i+=10;printf("%d\n",i);}

/* Out put is (***since static int is used i value is retained between * 20 function calls ) * 30 * 40 */

103)#include <stdio.h>#include <stdio.h>#include <string.h>/* This is asked in PCS Bombay walk-in-interview * What is wrong in the following code

Page 27: Documentc

*/main(){ char *c; c = "Hello"; printf("%s\n", c);}/*ans:- Hello, The code is successfully running */

104) #include <stdio.h>/* This problem is given in PCS BOMBAY walk-in-interview. * What is the final value of i and how many times loop is * Executed ? */

main()

{ int i,j,k,l,lc=0; /* the input is given as 1234 567 */ printf("Enter the number string:<1234 567 >\n"); scanf("%2d%d%1d",&i,&j,&k); for(;k;k--,i++) for(l=0;l<j;l++) { lc++; printf("%d %d\n",i,l);}printf("LOOPS= %d\n", lc-1);}/* Ans: i = 16, and loop is executed for 169 times */

105)#include <stdio.h>/* This is given in PCS Bombay walk-in-interview *//* What is the output of the following program */

main() { union { int a; int b; int c; } u,v; u.a = 10; u.b = 20; printf("%d %d \n",u.a,u.b); }/* Ans : The latest value assigned to any of the union member

Page 28: Documentc

will be present in the union members so answer is 20 20*/

106)#include <stdio.h>main(){ float i, j; scanf("%f %f", &i, &j); printf("%.2f %.3f", i, j);}

/Ans:- 123.34 3. 234 */

107)#include <stdio.h>/* This is given in PCS Bombay walk-in-interview * What is the out put of the following problem ? */main(){ char *str = "12345"; printf("%c %c %c\n", *str, *(str++), *(str++));}/* Ans: It is not 1 2 3 * But it is 3 2 1 Why ?? */

108)#include <stdio.h>/* This problem is asked in PCS Bombay Walk-in-interview * Write a macro statement to find maximum of a,b */#define max(a,b) (a>b)?a:bmain(){ int a,b; a=3; b=4; printf("%d",max(a,b));}/* Ans is very simple the coding is just for testing it and output is 4 */

109)

Page 29: Documentc

#include <stdio.h>/* This problem is asked in PCS Bombay * What is the output of the following coding */

main(){ int len=4; char *st="12345678"; st = st -len; printf("%c\n",*st);}/* Ans : It will print some junk value */

110)#include <stdio.h>main(){ func(1);}func(int i){static char *str ={ "One","Two","Three","Four"};printf("%s\n",str[i++]);return;}/* Ans:- it will give warning because str is pointer to the char but it is initialized with more values if it is not considered then the answer is Two */

111) #include <stdio.h>main(){ int i; for (i=1;i<100; i++) printf("%d %0x\n",i,i);}/* Ans:- i is from 1 to 99 for the first format, for the second format 1to9, ato f, 10 to 19,1ato1f, 20 to 29, etc */

113)#include <stdio.h>/* This problem is asked in PCS Bombay walk-in-interview * In the following code please write the syntax for * assing a value of 10 to field x of s and id_no 101 of s */

Page 30: Documentc

struct { int x; int y; union { int id_no; char *name; }b; }s,*st;main(){ st = &s; st->x=10; st->b.id_no = 101; printf("%d %d\n",s..x,s.b.id_no);}/* Ans: The answer is st->x=10; * st->b.id_no=101; */

114)#include <stdio.h>/* This problem was asked in PCS Bombay in a walk-in-interview * Write a recursive function that calculates * n * (n-1) * (n-2) * ....... 2 * 1 */

main() {int factorial(int n);int i,ans;printf("\n Enter a Number:");scanf("%d",&i);ans = factorial(i);printf("\nFactorial by recursion = %d\n", ans);}int factorial(int n){ if (n <= 1) return (1); else return ( n * factorial(n-1));}

115)#include <stdio.h>/* This problem is asked in PCS Bombay walk-in-interview * What is the output of the following problem */

Page 31: Documentc

main(){int j,ans;j = 4;ans = count(4);printf("%d\n",ans);}int count(int i){ if ( i < 0) return(i); else return( count(i-2) + count(i-1));}

/* It is showing -18 as an answer */

116)#include<stdio.h>main(){ int i=4; if(i=0) printf("statement 1"); else printf("statement 2");}/* statement 2 */

This is pcsb paper.

117) #include <stdio.h> * What is wrong in the following problem

main() {int i,j;j = 10;i = j++ - j++;printf("%d %d", i,j);}ans: 0, 12

118)#include <stdio.h> * What is the output of the following problemmain() {

Page 32: Documentc

int j;for(j=0;j<3;j++) foo();}foo() {static int i = 10;i+=10;printf("%d\n",i);}

/* Out put is (***since static int is used i value is retained between * 20 function calls ) * 30 * 40 */

119)#include <stdio.h>#include <stdio.h>#include <string.h>/* This is asked in PCS Bombay walk-in-interview * What is wrong in the following code */main(){ char *c; c = "Hello"; printf("%s\n", c);}/*ans:- Hello, The code is successfully running */

120) #include <stdio.h>/* This problem is given in PCS BOMBAY walk-in-interview. * What is the final value of i and how many times loop is * Executed ? */main()

{ int i,j,k,l,lc=0; /* the input is given as 1234 567 */ printf("Enter the number string:<1234 567 >\n"); scanf("%2d%d%1d",&i,&j,&k); for(;k;k--,i++)

Page 33: Documentc

for(l=0;l<j;l++) { lc++; printf("%d %d\n",i,l);}printf("LOOPS= %d\n", lc-1);}/* Ans: i = 16, and loop is executed for 169 times */

121)#include <stdio.h>/* This is given in PCS Bombay walk-in-interview *//* What is the output of the following program */

main() { union { int a; int b; int c; } u,v; u.a = 10; u.b = 20; printf("%d %d \n",u.a,u.b); }/* Ans : The latest value assigned to any of the union member will be present in the union members so answer is 20 20*/122)#include <stdio.h>main(){ float i, j; scanf("%f %f", &i, &j); printf("%.2f %.3f", i, j);}

/Ans:- 123.34 3. 234 */

123)#include <stdio.h>/* This is given in PCS Bombay walk-in-interview * What is the out put of the following problem ? */

main(){ char *str = "12345"; printf("%c %c %c\n", *str, *(str++), *(str++));

Page 34: Documentc

}/* Ans: It is not 1 2 3 * But it is 3 2 1 Why ?? */

123)#include <stdio.h>/* This problem is asked in PCS Bombay Walk-in-interview * Write a macro statement to find maximum of a,b */#define max(a,b) (a>b)?a:bmain(){ int a,b; a=3; b=4; printf("%d",max(a,b));}/* Ans is very simple the coding is just for testing it and output is 4 */

124)#include <stdio.h>/* This problem is asked in PCS Bombay * What is the output of the following coding */main(){ int len=4; char *st="12345678"; for(i=0; i<6; i++) st = st -len; printf("%c\n",*st);}/* Ans : It will print some junk value */

125)#include <stdio.h>main(){ func(1);}func(int i){static char *str ={ "One","Two","Three","Four"};printf("%s\n",str[i++]);return;

Page 35: Documentc

}/* Ans:- it will give warning because str is pointer to the char but it is initialized with more values if it is not considered then the answer is Two */

126) #include <stdio.h>main(){ int i; for (i=1;i<100; i++) printf("%d %0x\n",i,i);}/* Ans:- i is from 1 to 99 for the first format, for the second format 1to9, ato f, 10 to 19,1ato1f, 20 to 29, etc */

127)#include <stdio.h>/* This problem is asked in PCS Bombay walk-in-interview * In the following code please write the syntax for * assing a value of 10 to field x of s and id_no 101 of s */struct { int x; int y; union { int id_no; char *name; }b; }s,*st;main(){ st = &s; st->x=10; st->b.id_no = 101; printf("%d %d\n",s.x,s.b.id_no);}/* Ans: The answer is st->x=10; * st->b.id_no=101; */128)#include <stdio.h>

Page 36: Documentc

/* This problem was asked in PCS Bombay in a walk-in-interview * Write a recursive function that calculates * n * (n-1) * (n-2) * ....... 2 * 1 */

main() {int factorial(int n);int i,ans;printf("\n Enter a Number:");scanf("%d",&i);ans = factorial(i);printf("\nFactorial by recursion = %d\n", ans);}int factorial(int n){ if (n <= 1) return (1); else return ( n * factorial(n-1));}

129)#include <stdio.h>/* This problem is asked in PCS Bombay walk-in-interview * What is the output of the following problem */main(){int j,ans;j = 4;ans = count(4);printf("%d\n",ans);}int count(int i){ if ( i < 0) return(i); else return( count(i-2) + count(i-1));}

/* It is showing -18 as an answer */

130)#include<stdio.h>main(){ int i=4; if(i=0)

Page 37: Documentc

printf("statement 1"); else printf("statement 2");}/* statement 2 */

131)Max value of SIGNED int a. b. c. d.

132) One questin is given, long one, to find the answer U should be femiliar with the operation as follows int *num={10,1,5,22,90}; main() { int *p,*q; int i; p=num; q=num+2; i=*p++; print the value of i, and q-p, and some other operations are there. } how the values will change?

133) One pointer diff is given like this: int *(*p[10])(char *, char*) asked to find the meaning.

134) char *a[4]={"jaya","mahe","chandra","buchi"}; what is the value of sizeof(a)/sizeof(char *) a. 4 b.bytes for char c-- d.--( we don't know the answer)

135) void fn(int *a, int *b) { int *t; t=a; a=b; b=t; } main() { int a=2; int b=3; fn(&a,&b);

Page 38: Documentc

print the values os a and b; } what is the output--- out put won't swap, the same values remain.

a. error at runtime b. compilation error c.2 3 d. 3 2

136) #define scanf "%s is a string"main(){ printf(scanf,scanf); } what is the output.

ANS : %s is string is string

137) i=2+3,4>3,1; printf("%d"i); ans is 5 only.

138) char *p="abc"; char *q="abc123"; while(*p=*q) { print("%c %c",*p,*q); } a. aabbcc b. aabbcc123 c. abcabc123 d. infinate loop ( this may be correct)

139) printf("%u",-1) what is the value? a. -1 b. 1 c. 65336 d. --

(maxint value-1 I think, check for the answer)

140) #define void int int i=300;

Page 39: Documentc

void main(void) { int i=200; { int i=100; print the value of i; } print the value of i } what is the output?

ans: may be 100 200

141)

int x=2; x=x<<2; printf("%d ",x); ANS=8;

142) int a[]={0,0X4,4,9}; /*some values are given*/ int i=2; printf("%d %d",a[i],i[a]); what is the value??? (may be error)

144) When the fn. is called where the return add. is stored? ans. stack

145) What is the nece. for compiler to support recursion? ans/ stack

146) swapping two variables x,y without using a temporary variable.

146) a program has been given asking to find the output ans. it is algorithm for finding G.C.D

147) write a program for reversing the given string.

148) the integers from 1 to n are stored in an array in a random fashion. but one integer is missing. write a program to find the missing integer. ans. idea. the sum of n natural numbers is = n(n+1)/2. if we subtract the above sum from the sum of all the

Page 40: Documentc

numbers in the array , the result is nothing but the missing number.149)some bit type of questions has been given on pointers asking to to find whether it is correct from syntax point of view. and if it is correct explain what it will do.(around 15 bits).

150) . typedef struct{ char *; nodeptr next; } * nodeptr;what does nodeptr stand for?

151) supposing thaty each integer occupies 4 bytes and each charactrer1 byte , what is the output of the following programme?#include<stdio.h>main(){ int a[] ={ 1,2,3,4,5,6,7};char c[] = {' a','x','h','o','k'};printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));}ans : 3 3

152) what is the output of the program?#include<stdio.h>main(){struct s1 {int i; };struct s2 {int i; };struct s1 st1;struct s2 st2;st1.i =5;st2 = st1;printf(" %d " , st2.i);}

ans: nothing (error)expl: diff struct variables should not assigned using "=" operator.

153) what is the output of the program?#include<stdio.h>main(){int i,j;int mat[3][3] ={1,2,3,4,5,6,7,8,9};for (i=2;i>=0;i--)

Page 41: Documentc

for ( j=2;j>=0;j--)printf("%d" , *(*(mat+j)+i));}

ans : 9 6 3 8 5 2 7 4 1

154)fun(n);}int fun( int n){int i;for(i=0;i<=n;i++)fun(n-i);printf(" well done");

} howmany times is the printf statement executed for n=10?ans: zeroexpl: Befire reaching to printf statement it will goes to infinite loop.

155) what is the output of the program?main(){struct emp{ char emp[]; int empno; float sal;};struct emp member = { "TIGER"};printf(" %d %f", member.empno,member.sal);

ans: error. In struct variable emp[], we have to give array size. If array size givenans is 0, 0.00

156) output of the program? # define infiniteloop while(1) main() { infiniteloop; printf("DONE");}ans: noneexpl: infiniteloop in main ends with ";" . so loop will not reach end;and the DONE also will not print.

Page 42: Documentc

157) output of the program? main(){int a=2, b=3;printf(" %d ", a+++b);}

ans:5expl: here it evaluates as a++ + b.

158) output of the program?

#define prn(a) printf("%d",a)#define print(a,b,c) prn(a), prn(b), prn(c)#define max(a,b) (a<b)? b:amain(){int x=1, y=2;print(max(x++,y),x,y);print(max(x++,y),x,y);}ans: 3 4 2

159) which of the following is the correct declaration for the function main() ?ans: main( int , char *[])

160) if ptr is defined as int *ptr[][100]; which of the following correctly allocates memory for ptr?

ans: ptr = (int *)(malloc(100* sizeof(int));

161) printf("%d%x\n",ox2,12);

162) int a=10; int b=20; a=a^b; b=a^b; a=a^b; printf("%d%d\n",a,b);

163)enum {ELLIPSE, TRIANGLE, RECTANGLE,

Page 43: Documentc

SQUARE=100, CIRCLE=5 } printf{"%d%d%d%d\n",TRIANGLE-RECTANGLE,SQUARE*CIRCLE-RECTANGLE};

164) define the following... a) pointer to a integer b) pointer to a char c) function pointer returning a pointer integer.

165) void a(void); main() { a(); } void a(void) { char a="HELLOW"; char *b="HELLOW"; char c[10]="HELLOW"; printf("%s%s%s\n",a,b,c); printf("%d%d%d\n",sizeof(a),sizeof(b),sizeof(c))); }

166) int a=15; int b=16; printf("%d %d \n",a&b,a/b); (bitwise operators) 167) int a[5],*p; for(p=a;p<&a[5];p++) { *p=p-a; printf("%d\n",*p); }

168) sscanf("xyz abc ABC 345" "% *[a-z A-Z]lf",&a); printf("lf",a);

170) main() { int i=10; printf("%d",i); { int i=20; printf("%d",i);

Page 44: Documentc

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

171)struct class { int i; float a; string[12]; } sizeof(class)=?

172) int *p; i=10; p=i; printf("%d",*p);

173) fact(5) int n; fact(n) { sum=n*fact(n-1); }

174)main(){char a[2];*a[0]=7;*a[1]=5;printf("%d",&a[1]-a)ANS: ans may be 1.(illegal initialization)

175)#include<stdio.h>main(){char a[]="hellow";char *b="hellow";char c[5]="hellow";printf("%s %s %s ",a,b,c);printf(" ",sizeof(a),sizeof(b),sizeof(c));}(ans is hellow,hellow,hellow 6,2,5 )176)#include<stdio.h>

Page 45: Documentc

main()

float value=10.00;printf("%g %0.2g %0.4g %f",value,value,value,value)}(ans is 10,10,10,10.000000)

177)#include<stdio.h>void function1;int i-value=100;main(){ i-value=50;function1;printf("i-value in the function=",i-value);printf("i-value after the function=",i-value);}printf("i-value at the end of main=",i-value);functioni()i-value=25;

178) main(){funct(int n);{switch(n) case1: m=2; break; case2: m=5; break; case3: m=7; break; default: m=0;}THIS IS ROUGH IDEA: (ANS:Out put is m=0)

179) 2.Java is a. compiled b. interpreted.

Page 46: Documentc

c. OOP d. mutithreaded. e. all ans e.

180) const char *char * constWhat is the differnce between the above tow?

181) n=7623 { temp=n/10; result=temp*10+ result; n=n/10 } Ans : 3267

182) C program code int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15 Ans: b

183) In scanf h is used for (short int)184) polymorphism(function &amp; operator overloading)185)inheritance is(all properties of existing class are derived)186) linked list is implemented by (referential structures)187) copy constructor ( constant reference )188) n=3 do while(n<=6) n=n-1; n=n*(n+1) end

189) if max() gives max of 3 nos, and min() min of 3 nos......ans : 3

190) there is a flow chart consisting n,sum, and count a condition is that : n > 10

Page 47: Documentc

ans: sum=45, n=11;

191)#define min((a),(b)) ((a)<(b))?(a):(b)main(){ int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);} Ans:5.

192)main(){char a[10]={1,2,3,4,5,6};int x;for(x=0;x<4;x++){ b[x]=x+'a';}printf("%s",b);} Ans:abcd56

193)Linked Lists are preffered than arrays to get advantage while a)Insertion b)Deletion c)Accessing Element d)None

4)question on Stack194)3 programs on recursion195)~(~0<<8)? Ans:Last 8 digits are 1's rest are 0's.196)int a,b=3,c=2;

a=b++*c;c=++b*a;Some thing like this. print a,b,c? Ans:6,4,24

197)Virtual Functions in C++(Refer to 13'th chapter first twoexamples of LAFORE Book)

198)Which of the following is not true regarding FRIEND functionAns:If y is friend of x and z is friend of y then z can accessprivate of x.

199)Given some program on "&" operator overloading.

200)class X{ public:X(){ cout<<"This is Base";} }; class Y:public X { public:Y(){cout<<"This is Derived";}}; what is printed when an object of Y is created?

201)main(){ int x=10,y=15; x=x++; y=++y;

Page 48: Documentc

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

202)int x;main(){ int x=0; { int x=10; x++; change_value(x); x++; Modify_value(); printf("First output: %d\n",x); } x++; change_value(x); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x);}

Modify_value(){ return (x+=10);}

change_value(){ return(x+=1);}

203)main(){ int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y);}

204)main(){ char *p1="Name";

Page 49: Documentc

char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2);}

205)main(){ int x=5; printf("%d %d %d\n",x,x<<2,x>>2);}

206)#define swap1(a,b) a=a+b;b=a-b;a=a-b;main(){ int x=5,y=10; swap1(x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y);}

207)int swap2(int a,int b){ int temp; temp=a; b=a; a=temp; return;}

208)main(){ char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr);}

209)#include<stdio.h>

Page 50: Documentc

main(){ char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1);}

210)#include<stdio.h>main(){ char *p1; char *p2; p1=(char *) malloc(25); p2=(char *) malloc(25); strcpy(p1,"Ramco"); strcpy(p2,"Systems"); strcat(p1,p2); printf("%s",p1);}

211)enum day = { jan = 1 ,feb=4, april, may}what is the value of may?a)4 b)5 c)6 d)11e)none of the above212)main{int x,j,k;j=k=6;x=2; ans x=1x=j*k;printf("%d", x);

212) fn f(x) { if(x<=0) return; ans fn(5) ....?else f(x-1)+x;}

213)i=20,k=0;for(j=1;j<i;j=1+4*(i/j))

Page 51: Documentc

{k+=j<10?4:3;}printf("%d", k); ans k=4

214) int i =10main(){int i =20,n;for(n=0;n<=i;){int i=10 i++;}printf("%d", i); ans i=20

215) int x=5; y= x&y( MULTIPLE CHOICE QS)ans : c

216) Y=10; if( Y++>9 && Y++!=10 && Y++>10)printf("........ Y);else printf("".... )ans : 13

217) f=(x>y)?x:ya) f points to max of x and yb) f points to min of x and yc)errord) ........

ans : a

218) if x is even, then(x%2)=0x &1 !=1x! ( some stuff is there)

a)only two are correctb) three are correct

Page 52: Documentc

c), d) ....ans : all are correct

219) which of the function operator cannot be over loaded

a) <=b)?:c)==d)*

ans: b and d

220) 2)#include<iostream.h> main(){printf("Hello World");}the program prints Hello World without changing main() the o/p shouldbe intialisation Hello World Desruct the changes should bea)iostream operator<<(iostream os, char*s)os<<'intialisation'<<(Hello World)<<Destructb) c) d)none of the above

221) swap(int x,y){int temp;temp=x;x=y;y=temp;}main(){int x=2;y=3;swap(x,y);}

222) static variable will be visible ina)fn. in which they are definedb)module " " " "c)all the programd)none

Page 53: Documentc

223)wrong statement about c++a)code removablyb)encapsulation of data and codec)program easy maintenanced)program runs faster

224)struct base {int a,b;base();int virtual function1();}struct derv1:base{int b,c,d;derv1()int virtual function1();}struct derv2 : base {int a,e;}base::base(){a=2;b=3;}derv1::derv1(){b=5;c=10;d=11;}base::function1(){return(100);}derv1::function1(){return(200);}main()base ba;derv1 d1,d2;printf("%d %d",d1.a,d1.b)o/p is a)a=2;b=3;b)a=3; b=2;c)a=5; b=10;d)none

225) for the above program answer the following q'smain()base da;

Page 54: Documentc

derv1 d1;derv2 d2;printf("%d %d %d",da.function1(),d1.function1(),d2.function1());o/p isa)100,200,200;b)200,100,200;c)200,200,100;d)none

226)struct {int x;int y;}abc;you can not access x by the following1)abc-->x;2)abc[0]-->x;abc.x;(abc)-->x;a)1,2,3b)2&3c)1&2d)1,3,4

227) automatic variables are destroyed after fn. ends becausea)stored in swapb)stored in stack and poped out after fn. returnsc)stored in data aread)stored in disk228) 1.main(argc,argv) { if(argc<1) printf("error"); else exit(0); }

229) What are the static variables...def

230) struct base {int a,b;base();int virtual function1();}struct derv1:base{int b,c,d;derv1()int virtual function1();

Page 55: Documentc

}struct derv2 : base{int a,e;}base::base(){a=2;b=3;}derv1::derv1(){b=5;c=10;d=11;}base::function1(){return(100);}derv1::function1(){return(200);}main()base ba;derv1 d1,d2;printf("%d %d",d1.a,d1.b)o/p is a)a=2;b=3;b)a=3; b=2;c)a=5; b=10;d)none

231) for the above program answer the following q'smain()base da;derv1 d1;derv2 d2;printf("%d %d %d",da.function1(),d1.function1(),d2.function1());o/p isa)100,200,200;b)200,100,200;c)200,200,100;d)none232)struct {int x;int y;}abc;you can not access x by the following1)abc-->x;2)abc[0]-->x;

Page 56: Documentc

abc.x;(abc)-->x;a)1,2,3b)2&3c)1&2d)1,3,4

233) automatic variables are destroyed after fn. ends becausea)stored in swapb)stored in stack and poped out after fn. returnsc)stored in data aread)stored in disk

234) if a row daminated two dimentional arry in the following which one is advantageand why?a) for(i=0;i<1000;i++) for(j=0;j<1000;j++) temp=temp+a[i][j];b) for(j=0;j<1000;j++) for(i=0;i<1000;i++) temp=temp+a[i][j]

235) what will be the result of executing following program main { char *x=&quot;new&quot;; char *y=&quot;dictonary&quot;; char *t; void swap (char * , char *); swap (x,y); printf(&quot;(%s, %s)&quot;,x,y);

char *t; t=x;

x=y; y=t; printf(&quot;-(%s, %s)&quot;,x,y); } void swap (char *x,char *y) { char *t; y=x; x=y; y=t; }

Page 57: Documentc

a).(New,Dictionary)-(New,Dictionary) b).(Dictionary,New)-(New,Dictionary) c).(New,Dictionary)-(Dictionary,New) d).(Dictionary,New)-(Dictionary,New) e).None of the above

(Ans will be b or e) check

236) what would the following program results in main() { char p[]=&quot;string&quot;; char t; int i,j; for(i=0,j=strlen(p);i&lt;j;i++) { t=p[i]; p[i]=p[j-i]; p[j-i]=t; } printf(&quot;%s&quot;,p); } a)will print:string b)will not print anything since p will be pointing to a null string c)will print:gnirtS

d)will result in a complication error e)will print invallid characters(junk) (Ans will be b ) check237.What does extern means in a function declaration a)the funct has global scope b)the funct need not be defined\ c)nothing really d)the funct has local scope only to the file it is defined in e)none of the above (Ans will be c)

237) What will be result of the following program main() { void f(int,int); int i=10; f(i,i++); } void f(int i,int j)

Page 58: Documentc

{ if(i&gt;50) return; i+=j; f(i,j); printf(&quot;%d,&quot;,i); } a).85,53,32,21 b)10,11,21,32,53 c)21,32,53,85 d)32,21,11,10 e)none of the above (Ans is e)

238) In the following code segment what will be the result of the function, valueof x , value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf(&quot;same&quot;); else printf(&quot;not same&quot;); }

a) same, MAXINT, -1 b) not same, MAXINT, -MAXINT c) same , MAXUNIT, -1 d) same, MAXUNIT, MAXUNIT e) not same, MAXINT, MAXUNIT Ans) a

239) what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g=&quot;string&quot;; strcpy(gxxx(),g); g = gxxx(); strcpy(g,&quot;oldstring&quot;); printf(&quot;The string is : %s&quot;,gxxx());

Page 59: Documentc

} a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these Ans) b

234) What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() { char *g=&quot;String&quot;; myalloc(g,20); strcpy(g,&quot;Oldstring&quot;); printf(&quot;The string is %s&quot;,g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these Ans) c ( check it )

241) What will be the result of the following program? main() { char p[]=&quot;String&quot;; int x=0; if(p==&quot;String&quot;) { printf(&quot;Pass 1&quot;); if(p[sizeof(p)-2]=='g') printf(&quot;Pass 2&quot;); else printf(&quot;Fail 2&quot;); } else

{ printf(&quot;Fail 1&quot;);

Page 60: Documentc

if(p[sizeof(p)-2]=='g') printf(&quot;Pass 2&quot;); else printf(&quot;Fail 2&quot;); } }

a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation

242) Which of the choices is true for the mentioned declaration ? const char *p; and char * const p; a) You can't change the character in both b) First : You can't change the characterr &amp; Second : You can;t change the pointer c) You can't change the pointer in both d) First : You can't change the pointer &amp; Second : You can't chanage the character e) None Ans) b ( check it)

243)The C language terminator is a.semicolon b.colon c.period d.exclamation mark

244)What is false about the following A compound statement is a.A set of simple statments b.Demarcated on either side by curly brackets c.Can be used in place of simple statement d.A C function is not a compound statement.

245) What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value.

Page 61: Documentc

246)Main must be written as a.the first function in the program b.Second function in the program c.Last function in the program d.any where in the program

247) Which of the following about automatic variables within a function is correct ? a.its type must be declared before using the variable b.they are local c.they are not initialised to zero d.they are global.

248) Write one statement equalent to the following two statements x=sqr(a); return(x); Choose from one of the alternatives a.return(sqr(a)); b.printf("sqr(a)"); c.return(a*a*a); d.printf("%d",sqr(a));

249)Which of the following about the C comments is incorrect ? a.commentscan go over multiple lines b.comments can start any where in the line c.a line can contain comments with out any language statements d.comments can occur within comments

250)What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1; a.7 b.0 c.1 d.6

251) Read the function conv() given below conv(int t) { int u; u=5/9 * (t-32); return(u0; }

Page 62: Documentc

What a.15 b.0 c.16.1 d.29

252) which of the following represents true statement either x is inthe range of 10 and 50 or y is zero a.x>=10 && x<=50 || y==0; b. c. d.

253) Which of the following is not an infinite loop ? a.while(1){ .... } b.for(;;){ ... } c.x=0; do{ /*x unaltered within theloop*/ ... }while(x==0); d.# define TRUE 0 ... while(TRUE){ .... }

254) what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);} a.3 b.1 c.0

Page 63: Documentc

d.2

255) how does the C compiler interpret the following two statements p=p+x; q=q+y; a.p=p+x; q=q+y b.p=p+xq=q+y c.p=p+xq; q=q+y d.p=p+x/q=q+y a.int b.char c.string d.float

256) read the folllowing code # define MAX 100 # define MIN 100 .... .... if(x>MAX) x=1; else if(x<MIN) x=-1; x=50; if the initial value of x=200,what is the vlaue after executing this code? a.200 b.1 c.-1 d.50

256)a memory of 20 bytes is allocated to a string declared as char *s then the following two statements are executed: s="Etrance" l=strlen(s); what is the value of l ? a.20 b.8 c.9 d.21

255) given the piece of code int a[50]; int *pa;

Page 64: Documentc

pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5)

256)consider the following structure: struct num nam{ int no; char name[25]; }; struct num nam n1[]={{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}}; ..... ..... printf("%d%d",n1[2],no,(*(n1 + 2),no) + 1); What does the above statement print? a.8,9 b.9,9 c.8,8 d.8,unpredictable value

257) identify the in correct expression a.a=b=3=4; b.a=b=c=d=0; float a=int b=3.5; d.int a; float b; a=b=3.5;

258) regarding the scope of the varibles;identify the incorrect statement: a.automatic variables are automatically initialised to 0 b.static variables are are automatically initialised to 0 c.the address of a register variable is not accessiable d.static variables cannot be initialised with any expression

259) cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4; is equivalent to which of the following? a.if cond 1 exp 1; else if cond 2 exp 2; else if cond 3 exp 3; else exp 4;

Page 65: Documentc

b.if cond 1 if cond 2 if cond 3 exp 1; else exp 2; else exp 3; else exp 4; c.if cond 1 && cond 2 && cond 3 exp 1 |exp 2|exp 3|exp 4; d.if cond 3 exp 1; else if cond 2

exp 2; else if cond 3

exp 3; else

exp 4;

260) the operator for exponencation is a.** b.^ c.% d.not available

261) .which of the following is invalid a.a+=b b.a*=b c.a>>=b d.a**=b

262)what is y value of the code if input x=10 y=5; if (x==10) else if(x==9) elae y=8; a.9 b.8 c.6 d.7

263) what does the following code do? fn(int n,int p,int r) {

Page 66: Documentc

static int a=p; switch(n){ case 4:a+=a*r;

case 3:a+=a*r;case 2:a+=a*r;case 1:a+=a*r;

} } a.computes simple interest for one year b.computes amount on compound interest for 1 to 4 years c.computes simple interest for four year d.computes compound interst for 1 year

264) a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6

265) how many times does the loop iterated ? for (i=0;i=10;i+=2) printf("Hi\n"); a.10 b.2 c.5 d.....

266) what is incorrect among teh following A recursive functiion a.calls itself b.is equivalent to a loop c.has a termination cond d.does not have a return value at all

267) which of the following go out of the loopo if expn 2 becoming false a.while(expn 1){...if(expn 2)continue;} b.while(!expn 1){if(expn 2)continue;...} c.do{..if(expn 1)continue;..}while(expn 2); d.while(!expn 2){if(expn 1)continue;..}

268)consider the following program_B_______ main()

Page 67: Documentc

_OB {unsigned int i=10; while(i>=0){ printf("%u",i) i--; } } how many times the loop wxecuted a.10 b.9 c.11 d.infinite

269) pick out the add one out a.malloc() b.calloc() c.free() d.realloc()

270)consider the following program main() { int a[5]={1,3,6,7,0}; int *b; b=&a[2]; } the value of b[-1] is a.1 b.3 c.-6 d.none

271) # define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none

272)consider the following program sigment

Page 68: Documentc

int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0;} if n=2, what is the value of sum a.0 b.6 c.3 d.none

273)identify the incorrect one 1.if(c=1) 2.if(c!=3) 3.if(a<b)then 4.if(c==1) a.1 only b.1&3 c.3 only d.all

274)teh format specified for hexa decimal is a.%d b.%o c.%x d.%u

275)find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); } a.5 b.6 c.0 d.none

276)consider the following C code main() { int i=3,x; while(i>0) {

Page 69: Documentc

x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is a.6 b.8 c.1 d.3

277)int *a[5] refers to a.array of pointers b.pointer to an array c.pointerto a pointer d......

278)which of the following statements is incorrect a.typedef struct new{

int n1;char n2;} DATA;

b.typedef struct { int n3; char *n4;

}ICE; c.typedef union {

int n5; float n6;

} UDT; d.#typedef union {

int n7;

float n8; } TUDAT;

279) CHAR A[10][15] AND INT B[10][15] IS DEFINED WHAT'S THE ADDRESS OF A[3][4] AND B[3][4] IF ADDRESS OD A IS OX1000 AND B IS 0X2000

A. 0X1030 AND 0X20C3 B. OX1031 AND OX20C4 AND SOME OTHERS..

Page 70: Documentc

280) int f(int *a) { int b=5; a=&b; }

main() { int i; printf("\n %d",i); f(&i); printf("\n %d",i); }

what's the output .

1.10,5 2,10,10 c.5,5 d. none

281) main() { int i; fork(); fork(); fork(); printf("----"); }

how many times the printf will be executed . a.3 b. 6 c.5 d. 8

6. void f(int i) { int j; for (j=0;j<16;j++) { if (i & (0x8000>>j)) printf("1");

Page 71: Documentc

else printf("0"); } } what's the purpose of the program

a. its output is hex representation of i b. bcd c. binary d. decimal

282)#define f(a,b) a+b#define g(a,b) a*b main() {

int m; m=2*f(3,g(4,5)); printf("\n m is %d",m); }

what's the value of m a.70 b.50 c.26 d. 69

283) main() { char a[10]; strcpy(a,"\0"); if (a==NULL) printf("\a is null"); else printf("\n a is not null");}

what happens with it . a. compile time error. b. run-time error. c. a is null d. a is not null.

284) char a[5]="hello"

Page 72: Documentc

a. in array we can't do the operation . b. size of a is too large c. size of a is too small d. nothing wrong with it .

285) local variables can be store by compiler a. in register or heap b. in register or stack c .in stack or heap . d. global memory.

286) global variable conflicts due to multiple file occurance is resolved during a. compile-time b. run-time c. link-time d. load-time287)two program is given of factorial. one with recursion and one without recursion . question was which program won't run for very big no. input becauseof stack overfow . a. i only (ans.) b. ii only c. i& ii both . c. none288) struct a { int a; char b; int c; }

union b { char a; int b; int c; }; which is correct . a. size of a is always diff. form size of b.(ans.) b. size of a is always same form size of b. c. we can't say anything because of not-homogeneous (not in ordered) d. size of a can be same if ...289)#define SUM(a,b) a+b

Page 73: Documentc

main() { a=2; b=3; x=SUM(a,b)*2; printf("x=%d\n",x); } Ans:8.

290)number(int i){number++;printf("%d\n",number);}main(){static int i=0;number(i);}Ans: I don't know

291) main(){ unsigned char i; int sum;

for(i=0; i<300; i++) sum+ = i; printf("\nSum = %d\n", sum);}Ans : infinite loop

292) void fn(int *p) { static int val = 100; p = &val; }

main(){ int i=10; printf("i=%d\n", i); fn(&i); printf("i=%d\n", i);}Ans : i=10 i=10

Page 74: Documentc

293) Swapping without using a temporary variables. (2 methods)(i) x = x+y; y = x-y; x = x-y;

(ii) x = x^y; y = x^y; x = x^y;

294) main() { int a[10] = {1, 2, 3, ...., 10}, i, x=10, temp;

for(i=0; i<x; i++){ temp = a[i]; a[i] = a[x-i-1]; a[x-i-1] = temp; }(i) All contents of array a are reversed(ii) Only some portions are altered(iii) Remains same(iv) NoneAns : (iii)

295) An array is stored in row major order. The memory capacity is 30 MB. And in unix system demand paging is used. Which one will give more page faults? #define V_L_I 10000 int i, j, array[V_L_I][V_L_I]; Code 1 : array[i][j] = 1;

Code 1 : for(j=0; j<V_L_I; j++) for(i=0; i<V_L_I; i++) array[i][j] = 1;

Ans : Code 2

(296) In C which parameter passing technique is used?(i) call by value,(ii) call by reference,(iii) bothAns : call by value

Page 75: Documentc

297) main() { int i = 1; fork(); fork(); printf("\ni = %d\n", i+1); }Ans : 4 printfs will occur and i = 2

298) # define MAX(a, b) a>b ? a:b main() { int m, n; m = 3 + MAX(2, 3); n = 2 * MAX(3, 2); printf("m = %d, n = %d\n", m, n) } Ans : m=2, n=3

299) 1.int a=2,b=3,c=4;printf("a=%d,b=%d\n",a,b,c);ANS:2,3

300)for(i=1;i<10;++i,printf("%d",i));+-ANS:compiling error.

301)whole logic is given in func s but they are working properly.the main logic is :

char *string;string=malloc(5*sizeof(char));strcpy(string,"hello");printf("%s",string); /* func to print */

ANS:hello and some extra characters until uccerence of \0 .

302) in a system integer takes 3bytes and char takes 1byte .......struct smthing{int a;char b[4];};

303) Which of the following language is a functional language a) RPG b) Small Talk

Page 76: Documentc

* c) PI/I d) LISPANS:sizeof struct smthing is 7 bytes.\

304)Which is pure object oriented language? a) Effiel b) c++ c) object pascal * d) Small talk

305) corba stands for ... * a. common object request broker architecture b. combined recovery based system c. code recovery bench architecture d. none of the above

306)which is non-procedural language? * a. effiel b. ada c. small talk d. sql

307)which of the following language supports associative arrays? a. pl/i b. rpg * c.perl d. ada308) FORTRAN implimentation do not permit recursion because * a) they use static allocation for variablesb) &quot; dynamic &quot; &quot;c) stacks are not avalible on all machinesd) it is not possible to impliment recursion on all m/c s

309) what does the following code do var a,b :integer begin a :=a+b b :=a-b a :=a-b end;* a) exchange a and bb) doubles a and stores in bc) &quot; b &quot; ad) leaves a and b unchangede) none

Page 77: Documentc

310) for program segament given bellow, which of the follwing are true? program main(output) type link = ^data data = record d : record n : link end; var ptr : link; begin new(ptr); ptr :=nil; ptr ^.d :=5.2 written(ptr); end; a) the programme leads to compile time error b) &quot; &quot; run &quot; &quot; c) the programme produces error relating to nil pointer dereferencing e) both b and a 311) what is the output of the program segament belowif the compiler operates call byreference? procedure CALC(P,Q,R); begin Q:=Q-1.0 R:=Q+P end; begin{main} A:=2.5; B:=9.0; CALC(B-A,A,A); print(A); end; {main} a) 1.5 b) 2.5 c) 10.5 * d) 8 e) 6.5

312) Which of the following is not provided in C? a) test loops b) grouping and subprograms * c) synchronization, coroutines,and parallel processing e) all the above

313) What will be the value of x and y after execution of the follwing statment ( C language)

Page 78: Documentc

n== 5; x = n++; y = --x; a) 5,4 b) 6,5 c) 6,6 * d) 5,5

314) consider the function below:function calc(x,y:integer):integer;begin if y=1 then calc:=x else calc:=calc(x,y-1)+xend;

315)assuming that the invocation call is &quot;calc(a,b)&quot;and that &quot;a&quot;and &quot;b&quot;are positive integers,what result does this function return?a. a*(b-1)b. a*bc. a+bd. a power be. a*b

316) to reverse a string using a recursive function, without swapping or using an extra memory.317)To reverse a linked list as above.318)given a macro like #define MAX(A,B) {to return that is larger} what will MAX(i++,j),MAX(i,j++) return.

319)Difference between Macro and ordinary definition.320)Difference between Class and Struct.321) int a=1,b=2,c=3; printf("%d,%d",a,b,c);

What is the output?

322) Scope of Static Variable ............ in a file.

323) typedef struct{ char *; nodeptr next; } * nodeptr;what does nodeptr stand for?ans:

Page 79: Documentc

324) 2 oranges,3 bananas and 4 apples cost Rs.15 . 3 ornages 2 bananas 1 apple costs Rs 10. what is the cost of 3 oranges, 3 bananas and 3 apples ANs Rs 15.

335) int *x[](); meansAns:expl: Elments of an array can't be functions.

326) struct list{int x;struct list *next;}*head;the struct head.x =100Ans: above is correct / wrongexpl: Before using the ptr type struct variable we have to give memory to that .And also when ever the struct variable is ptr then we access the members by "->" operator.

327)o/p=? int i; i=1; i=i+2*i++; printf(%d,i);ans: 4

328) FILE *fp1,*fp2;fp1=fopen("one","w")fp2=fopen("one","w")fputc('A',fp1)fputc('B',fp2)fclose(fp1)fclose(fp2)}a.error b. c. d.ans: no error. But It will over writes on same file.

329)#include<malloc.h>char *f(){char *s=malloc(8);strcpy(s,"goodbye")}main(){char *f();printf("%c",*f()='A');o/p=?

Page 80: Documentc

330) #define MAN(x,y) (x)>(y)?(x):(y) { int i=10;j=5;k=0; k= MAX(i++,++j) printf(%d %d %d %d,i,j,k)}ans:10 5 0331) a=10;b=5; c=3;d=3;if(a<b)&&(c=d++)printf(%d %d %d %d a,b,c,d)else printf("%d %d %d %d a,b,c,d);ans:

332) what is o/p #include<stdarg.h> show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf("\n %d",a) } display(char) {int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); } a) 13 b) 12 c) 44 d) 14

333)main(){printf("hello");fork();}ans:

334)main(){int i = 10;

Page 81: Documentc

printf(" %d %d %d \n", ++i, i++, ++i);}ans: 335)#include<stdio.h>main(){int *p, *c, i;i = 5;p = (int*) (malloc(sizeof(i)));printf("\n%d",*p);*p = 10;printf("\n%d %d",i,*p);c = (int*) calloc(2);printf("\n%d\n",*c);}ans:

336)#define MAX(x,y) (x) >(y)?(x):(y)main(){ int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }ans:

337)#include <stdio.h>main(){ enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back);}ans:

338)main(){ int a=10,b=20; a>=5?b=100:b=200; printf("%d\n",b);} ans:

Page 82: Documentc

339)#define PRINT(int) printf("int = %d ",int)main(){int x,y,z;x=03;y=02;z=01;PRINT(x^x);z<<=3;PRINT(x);y>>=3;PRINT(y);}ans:

340)#include<stdio.h>main(){char s[] = "Bouquets and Brickbats";printf("\n%c, ",*(&s[2]));printf("%s, ",s+5); printf("\n%s",s);printf("\n%c",*(s+2));}ans:

341)main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; for(i=0;i<=2;i++) p[i] = arr[i].ptr;

printf("%s\n",(*p)->str); printf("%s\n",(++*p)->str);

Page 83: Documentc

printf("%s\n",((*p)++)->str); }ans:

342)main(){char *p = "hello world!";p[0] = 'H'; printf("%s",p);}ans:343)m=3 while (m&lt;18) do {m=m+2;m=m-1} ans:15

344)m=1;a=30;while (m&lt;&gt;1) do {m=m+1;a=a-1;}

345)m=1;a=30;while (e*m-5&lt;a) do {m=m+1;a=a-2} ans:9

346)in questions 8 to 12 find the values of a and b at the end of the xecution of the program segment

347)a=2;b=1;x=1;while(x&lt;=4)do {a=a+b;x=x+1} ans:(5,1)34*)

348)a=1;b=2;x=1 while (x&lt;=5)do {b=a+b;x=x+1;} ans:(1,6)

349)a=0;b=0;x=1;while (x&lt;=4){a=a+x;b=b-x;x=x+1;} ans:(10,-10)

350) # define TRUE 0 some code while(TRUE) { some code

} This won't go into the loop as TRUE is defined as

Page 84: Documentc