1 1) ans::b 2) what is the postfix of the given infix expression (a+b)*c/d-e+f ans::ab+c*d/e-f+ 3) void main() { int i,*j; i=35; ??????

//j=&i; printf("%d",*j); } To get the 35 as the output,which statement is replaced by ?????? To print a single character in ouptut,which function is used? a) getchar() b) gets() c) putchar() d) puts() ans::c The effective way of sorting is done by _______________ a) single linked list b) arrays C) Doubly linked list d) Binary search trees ans::c or d?? void main() { struct emp { int a; struct emp b; }; struct emp m; printf("%d",sizeof(m)); } ans::error If you dont know the array size which one do you prefer? a) array b) linked list

4)

5)

6)

2

7)

#define t 10 void main() { printf("%d",t); } a) 10 b) Error:Unfined symbol 't' c) Error:Improper placement of preprocessor d) none of the above ans::a data structures used for stack a) array b) linked list c) both d) none ans::c Explicit datatype conversion is called a) Type casting b) conversion c) separation d) none ans::a what is the size of char *a,int *b,float *q,if the size of the double pointer is 2 bytes a) 1 1 1 b) 2 2 2 c) 4 4 4 d) 1 2 4 ans::b The data structure used for searching is a) arrays b) single linked list c) double linked list D) Binary search trees ans::d For what purpose queues are used? i) expression evaluation ii) device queue for processes a) i only b) ii only c) both i and ii d) neither i nor ii ans::b

8)

9)

10)

11)

12)

3

13)

The data structure used for sorting without moving the data is a) arrays b) single linked list c) double linked list D) Binary search trees ans::d struct stack { int a[10]; int top; }; struct stack *s;

14)

How will add an element called 'item' in top the stack? ans::s->a[s->top]=item 15) predict the ouput strcut emp { char name[50]; struct emp e; }*oemp; oemp->name="wipro"; ans::error 16) Predict the output struct a { int x; }e1; struct b { int y; }e2; if(e1==e2)//structure cannot be comapred simplys printf("Equal"); else printf("Unequal");

4

17)

ans::error main() { int i,j; for(i=0;i<2;i++) { for(j=0;j<5;j++) { if(i==j) continue; printf("wipro"); } } }

//wipro would be printed 8 times

18)

which one is used to get a multiword string? a) gets b) printf c) puts d) getchar ans::a. main() { char *a="\12345\n"; printf("%d",sizeof(a)); } ans::2

19)

20)

21)

int fun() { int k=10; return(&k); } main() { int *p; p=fun(); printf("%d",*p); } ans::10 i) char *str="welcome"; ii) char str[50]="welcome";

5 for these 2 definitions will they give you the same output for the given statement? printf("%c",str[3]); yes 22) void fun() { return(a>100?100:200); } void main() { printf("%d",fun(5)); } ans::error void disp(int a,int b) { return(a>b?a+b:a*b); } void main() { printf("%d",,disp(5,6)); } ans::error

23)

1) void main() { int i=0; while(i==0) { } printf("%d",i); } ans:: no output//infinte loop 2) void main() { int i=1; while(++i==1) {} printf("%d",i); }

6 ans::2 char s[]={'a','b','c','\0'}; printf("%s",s); output::abc int arr[3][3]={2,3,4, 5,6,7, 8,9,10}; for(i=0;i<=2;i++) for(j=0;j<=2;++j) printf("%d",*(*(arr+i)+j)); //*(arr[i]+j)--arr[i][j] output=2345678910 5) int b=20; printf("%d",++*&b); ans::21 which can be replaced by a switch block? a) do..while b) for c) while d) else if ans::d which of these is not a operator in c? a) ~ b) ^ c) % d) :: ans: d:: which of these is not a valid character constant a) "A" b) '*' c) '+' d) 'h' ans::a struct student { int i; char c[10]; struct student *s; }; struct student stud,*stu; stu=&stud; printf("%d %d",sizeof(stud)); ans::14

3)

4)

6)

7)

8)

9)

7

10)

insert(root,2); insert(root,1); insert(root,3); insert(root,4); insert(root,5); What is the inorder for the above tree? ans::1,2,3,4,5 insert(root,2); insert(root,1); insert(root,3); insert(root,4); insert(root,5); What is the preorder for the above tree? ans::2,1,3,4,5 The postfix expression is ab+c*d/e-.If the values of a,b,c,d,e are 5,2,3,3,1 respectively,then what will be the output? ans::6 What is the order in which the preorder is evaluated? i) root node ii) left node iii) right node a) i,ii,iii b) ii,iii,i c) iii,ii,i d) ii,i,iii

11)

12)

13)

14)

ans::a which operations are more effective in linked list than arrays? i) insertion ii) deletion iii) traversal a) i,ii only b) iii only c) all the above d) i,iii only

ans::a 15) what is the output of the following program? void main()

8 { int i=12; int *q; q=&i; *q=*q-8; printf("%d",i); } ans::4 what is the use of precedence in C programs for operators? a) Precendence are used to replace the variables used in operations b) precendence are used to allocate memory space c) precendence are used to evaluate the expression first d) None of the above ans::c

16)

17)

aaa(){ printf("Hai")}; bbb(){ printf("Hello")}; ccc(){ printf("Bye")}; void main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; } ans::nothing it will print to call function we sud write (*ptr[0])(); 18) In Unsigned char,signed value is represented by 1 in most significant bit. a) true b) false ans::b int i=1; switch(i*2) { case 1: printf("case1"); break; case 2: printf("case 2"); default: printf("default"); break; } a) case1 case2 default

19)

9 b) case2 c) case2 default d) compiler error ans::c struct node { int info; struct node *left,*right; }; if nd is a pointer which is pointing to the first node,then which one of the following is correct? a) nd->right = NULL; b) nd->left = NULL; c) nd = NuLL; d) nd->left->right = NULL; ans::b struct a { char *i; char *j; }; struct b { struct a x; int i; }*y; printf("%d %d",sizeof(y),sizeof(*y)); ans::2 6 #define t printf void main() { int i=10; t("%d",i); } ans::10 int a[3][4]={1,2,3,4, 5}; printf("%d",a[0][4]); ans::5 which one is used to check the given string is palindrome or not a) Single Linked list b) doubly linked list

20)

21)

22)

23)

24)

10 c) Arrays D) none of the above ans::c 25) #define HELLO hai void main() { printf("HELLO"); } ans::hello The formal arguments has a default value zero a) true b) false ans::b void fun() { ????? x++; printf("%d",x); } int x; void main() { x=7; printf("%d",x); x++; printf("%d",x); fun(); } if the outputs are 7,8,9,then which is replaced instead of ????? a) extern int x; b) auto int x; c) static int x; d) register int x; ans::a if rear=-1,front=-1 then what will be my queue? a) Queue is empty b) Queue is full c) Queue has one element D) Queue has max-1 element ans::a void main() { int i; for(i=1;i<=5;i++)

26)

27)

28)

29)

11 {} printf("%d",i); } ans::6 30) If p=(int *) malloc(sizeof(int)*10),then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero a) i only b)ii only c) both i and ii d) neither i nor ii ans::a If p=(int *) calloc(sizeof(int)*10),then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero a) i only b)ii only c) both i and ii d) neither i nor ii ans::c

31)

32) Predict the output int i=1; while(i<3) { switch(i) { case 1: printf ("Case 1"); break; case 2: printf ("case 2"); break; default: printf ("Default"); } i++: } ans::case1 case2 33) If rear=0 front=0 what is queue? ans::queue has one element 34) if rear=max, front=0, what is queue? ans::q is full 35) for (i=1; i=2; i++)

12 { printf ("HAI"); } ans::hai hai hai....infinite 36) *Consider a linked list where ptr is a pointer which is not pointing to the first node and not to the last node.If there is another node called "new" which is like new->next=NULL,then what is the scenario? a) It is the first node b) It is the last node c) It is in the middle d) none of these ans::b If 'a' is the integer which is not statically initialized then what is the value of 'a'? a) zero b) garbage c) none of these ans::b struct emp { int a=20;//intialization cannot be done here.. char name[10]="AAA"; }; void main() { struct emp oemp; printf("%s",oemp->name); printf("%d",oemp->a); } ans::error//if struct element cannot be intialized +oemp cannot use -> only ".". Which of the following is considered as tokens in C? a) Variables b) Keywords c) Constants d) All the above ans::d C is a ____________________ language a) Platform independent programming b) Platform dependent programming c) Object oriented programming d) None of the above ans::b main()

37)

38)

39)

40)

41)

main() { static int a[5].//g will be replaced by \0 for(i=0.i++) printf("%d %d". } ans::3 int b[5].i<5. *x=x[n]. case 1: printf("case 1").// //irl//rl//r// x++.b[i]).i.i<n.13 { int i=3. int i. switch(i) { default: printf("default").i++) { printf("%s \n". break. } } irl rl l 42) 43) 44) 45) ans:: .a[i].x).SECOND * SECOND). n=strlen(x). int n. for(i=0. } ans::default case1 case2 #define FIRST 1 #define SECOND FIRST+FIRST main() { printf("%d". } output::o o o o o o o o o o which is having the more precendence a) * b)+ c)== d) ans::a main() { char *x="girl". case 2: printf("case 2").

2[x]). j=&a.arr.2.4.&arr). x=*y+2.14 46) int sample(int x) { int *y.5}. } ans::error//mul n div cannot be done on pointers To make a pointer 'cursor'as a tail node. j=j*2.3.*k). k=&b. 48) 49) 50) 51) . printf("%d".which line is correct a) cursor->right==NULL b) cursor->left==NULL c) cursor==NULL d) cursor->left==0 ans::a Single linked list has a lnk to the next address a) true b) false ans::a int 5[x]={1. int a=5.*j. printf("%d %d". y=&x.5}.4.sample(x)).3. printf("%d".2. return(x).b=8. k=j/2. } void main() { int x=5. ans::error//declaration terminated incorrectly int arr[]={1.*k. } ans::7 47) void main() { int *j. printf("%d %d".

c=(float)a+b. int *p.7. 53) 54) 55) 56) 57) .2.12.15 garbage garbage//same both array statrting address 52) int a[3][4]={1.5).c).9. printf("%d %d".3. 5.argv are initialised in a) header file b) within main c) outside main d) none ans::a Queue is i) First in first out ii) used in expression evaluation.0}.a. a) i only b) ii only c) both i and ii d) neither i nor ii ans::a which is correct? a) Auto variables are local variables b) Extern variables are global variables c) static variables are global variables d) registers are local variables ans::b main() { int i=5. p=&5.8 .*p). printf("%c". } ans::error//must take an adress of a variable int foo(int a.i.6. } main() { ????? foo(8.a[2][1]).4. ans::garbage(%u sud be used) 0 The argc. printf("%d %d".float b) { float c.

5 ans::nuthing//not reqd %f sud be used tats it 58) main() { float v.sizeof(e)). v=10/4.24 d) None of these ans::none of these abnormal floating point 2. p=&i.0. p1 and p2 are the 2 nodes and node nd is inserted as nd->next=NULL nd->prev=p1->next ans::watever the question nd is last node till data provided void main() { int i=12. char *name.12. a) 0.12. printf("%d". printf("%2f". j=++*p+8.int a=123. }. printf("%f". .00 b) 123.j). struct emp { int a.j. } ans::2. int c=a+b.v). } ans::21 60) 1.12 c) 246.16 } which line is replaced for ?????? to get the ouput of 20.5000000 59) In a doubly linked list.c).*p. printf("%d". main() { struct emp *e. int b=-123.

When a string is more than 10 a) Error b) Overwrites c) Nothing d) garbage value ans::error/too many intializers ans::a 5. char *fun(). strcpy(buffer. which is the best thing for linked list than arrays? i) Insertion ii) Deletion iii) Traversal a) (i) only b) (i)."Hello world").str).17 } ans::2 3.iii only d) iii only ans::b 4. main() . str=fun(). a) hello world b) Compiler error c) Runtime error d) None of the above ans::c 6. } char * fun() { char *buffer.(ii) only c) ii. main() { char *str. return buffer. consider the character array of size 10. printf("%s". } ans::runtime error //as buffer is lost when it goes out of a function bettet to use static char *buffer or malloc to allocate memory for buffer.

"Hello world").18 { char *str. return buffer. } a) 65 b) p c) error d) none of the above ans::none of the above//aoutput capital "A" 10) In a function call. _____________ is passed as arguments.str). printf("%d".a). strcpy(buffer. printf("%s". . } a) hello world b) Compiler error c) Runtime error d) None of the above ans::a 7) what is the prefix expression for the given Infix expression A+B*C/D ans::+a/*bcd 8) int a. printf("%c". 9) main() { char p=65. buffer=(char *) malloc(sizeof(char)). char *fun(). } char * fun() { char *buffer.p). a) 0 b) Garbage c) 65535 d) -32768 output::garbage ans::to be precise will be -1//key here if no>+32767 then o/p is -(65536-number) and if no<-32768 then no=(65536+(-no)). a=65535. str=fun().

a[1]=5.\\it terminated by'\0'not/0 ok 14) The range of Unsigned integer is a) 127 to -128 b) 0 to 65535 c) Depend up on the compiler d) -32768 to 32767 ans::c 15) which one of the following is a illegal real constants a) 32..5E25 to 3. } .5E65 c) "53682" d) -6.a[5]. ascII=26 12) () is used for __________ a) function body b) Arguments c) Return type d) Declaration of function ans::b 13) How does the string ends? a) /n b) /t c) /0 d) none ans::none.i++) { printf("%d". a++.583 ans::"53682" 16) main() { int i.a[i]). for(i=0.535 b) -1.i<5..19 a) variables b) constants c) Expressions d) All the above all the above 11) The value of EOF is 26__-1_______.

while(*s) printf("%c". char *s.20 a) 0 0 0 0 0 b) Garbage value c) 0 5 0 0 0 d) Compiler error ans::d 17) The size of int is 2 bytes.s--) printf("%c".then what is the size of short int? a) 1 b) 2 c) 4 d) 8 ans::b 18) In a queue. . } ans::wipro infotech 21) char *a="Malayalam". s=&str[13]-13.what condition applies a) First In First Out b) Last in first out c) Elements are inserted and deleted at one end d) Elements can be inserted and deleted in different ends ans::a 19) which of the following statements are true in the case of doubly linked list i) Every node is connected to other node ii) We can traverse in both the directions a) i) only b)ii) only c) Both i and ii d) neither i nor ii ans::c 20) main() { char str[]="Wipro Infotech". s=str+8. Char *str.s>=str.*s). char *s. for(.*s++). str=a.

} ans::wipro 24) Is allocating a block of memory effectively the same as defining an array? a) True b) false ans::false 25) the size of a node of a doubly linked list is always greater than the single linked list a) True b) false ans::true 26) Queue is used for i) Expression Evaluation ii) Scheluding the job in First come First serve a) i) only b) ii only c) both i & ii d) neither i nor ii ans::b 27) what should be replace ????? in the program to get the output 25? ????? void main() { int x=2. printf("%d %d". int b. .y=3.j.sizeof(e1). j=SQRT(x+y). ans::2 6 23) #define wipro Hai void main() { printf("wipro"). struct main *e1.sizeof(*e1)).21 a) Malayalam b) malayalaM c) error d) None of the above ans::b 22) struct main { int a. }.

} what will be the output? a) Compiler Error b) Hello c) Garbage value d) None ans::a 29) void main() { int *p.3 8. } ans::1 10.j=10.i++. } a) #define SQRT(int) (int * int) b) #define SQRT(int) (int) * (int) c) #define SQRT(int) (int + int) d) #define SQRT(int) (int) + (int) ans::b 28) void fun() { static char p[]="Hello".4 7.i.22 printf("%d".5 6 31) Which of these will pass the address of the pointer *ptr to the function demofun()? a) demofun(ptr) b) demofun(&ptr) c) demofun(*ptr) d) demofun(*&*ptr). } What is the output? ans::garbage if calloc is used o/p is 00000 30) main() { int i.j).2 9. .j--). p=(int *)malloc(sizeof(int)). for(i=0.i<5.p[i]). } main() { printf("%s".fun()).i<j. for(i=1. return p.i++) printf("%d ". printf("%d %d".j.j).

c) while(1).23 ans::b 32) which is not a valid expression a) x!=y b) x! c) !x d) x!y ans::x! and x!y 33) If max=10. which is correct? i) All Values are intialised to garbage values ii) Creates memory for 10 integer data a) i only b) ii only c) both i and ii d) neither i nor ii ans::c 36) int *ptr. b) for(. ans::c 35) int *ptr.front=0. d) while(0).rear=max. which is correct? i) All Values are intialised to zero ii) Creates memory for 10 integer data a) i only b) ii only c) both i and ii d) neither i nor ii ans::b 37) Struct queue { .then what will be my queue? a) Queue Empty b) Queue Full c) Queue has one element d) Queue has max-1 elements ans::c or b?? 34) which is an indefinite loop? a) do while(0). ptr=(int *)calloc(10*sizeof(int)).). ptr=(int *)malloc(10*sizeof(int)).0.

c) q->a[rear]=item. ptr=(struct node *)calloc(sizeof(ptr)). then how will you add a new element called 'item' in the queue? a) q->rear[a]=item. int front. ans::b 38) In which of the following we can sort the data without moving the data a) Array b) Single Linked list c) Doubly linked list d) Binary search trees ans::d 39) Char d=128. what will be the output? traverse(struct node*end) { while(end!=NULL) . b) q->a[q->rear]=item. int a[100].if the first node is first and the last node is end. printf("%c". a) ptr is allocated 4 bytes b) ptr will be allocated sizeof struct node c) Error d) ptr will have 8 bytes ans::a 41) In a doubly linked list . d) q->rear[q->a]=item.d). a)128 b)-128 c)error d)Garbage values ans::d 40) In the following definition struct node *ptr. } struct queue *q.24 int rear.

4.4. printf("%d"*&b++).end->data). printf("%d". } if the input is 1.4.5 b) 5.3. } what will be the output? a) 21 b)20 c) error d) Garbage value ans::c//must take an adress of memory location *&b will work 43) how will you refer the last node in the doubly linked list which is pointed by the pointer variable 'cursor'? a)cursor==NULL b)cursor->link=NULL c)Cursor->link=0 d)cursor->data=NULL ans::b 44) how will you refer the previous node of the pointer 'cursor' in the doubly linked list (cursor is not in the first or in the last)? a)cursor->link++ b)cursor=cursor->left c) Cursor++ d) cursor->left++ ans::b .25 traverse(end->prev).2.3.2.3.5 then the output will be a) 1.2.1 c) compilation error d) none ans::b 42) void main() { int b=20.

c) ptr->link=ptr->link->link. struct node *link. }. i) start->link=s1. Suppose start is a pointer pointing to the first node of the linked list. iii) ptr->link=start. s1 and ptr are the two pointers(they are not pointing to the first or last node). ans::c 2) Consider the following structure struct node { int info. Suppose ptr is a pointer which is not pointing to the first or the last node. if rear=front then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element . }.26 1)Consider the following structure struct node { int info. d) ptr=ptr->link->link. b) ptr->link=ptr. ii) s1->link=ptr.s1. then the code will be a) ptr=ptr->link.ptr in the list.Then if we are going to delete a node after ptr. then the list is a) It is having only 3 nodes with start.Then if we are going to execute the following code.having start as the first node b) It is a circular linked list c) It is a doubly linked list d) None of the above ans::b 3) In a queue. struct node *link.

if top=0 then the stack is .front=1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) Queue is circular ans::d 6) In a queue.if rear=0.The values of a.if rear=-1.2.5.c.if rear=0.4.d.e are 2.b.front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) none of the above ans::c 5) 4) In a queue.if rear=max-1.1 respectively. Then the output is a) 14 b) 11 c) 20 d) 15 ans::a 9) The infix expression is a+b*(c-d)/(e+f)*h then my postfix expression is a) ab+cd-*ef+h*/ b) abcd-ef+*/h* c) abcd-*ef+/h*+ d) abcdef+-*/h*+ ans::c 10) In the stack.front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) none of the above ans::b 8) The postfix expression is ab+c*d/e-.front=-1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) none of the above ans::a 7) In a queue.27 d) none of the above ans::c 4) In a queue.

nd->left->right=nd. We have 10 elements in the list. b) nd->right=nd->right->right. Suppose nd is a node which is not in the beginning and also not in the end.*right.If the following executes what will be the output? for(ptr=start. struct node *left. c) nd->right=nd->right->left. }. ans::b 13) Struct node { int data. d) nd->right=nd->left->right. struct node *right.28 a) stack is empty b) stack is full c) stack has only one element d) none of the above ans::c 11) Conside the structure struct node { int info.nd->right->left=nd. .nd->right->left=nd->left->right. Struct node *left.ptr->data).ptr.ptr=ptr->right) { if(ptr->data%2==0) printf("%d". } a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values ans::c /well if ptr is defined then even no are printed 12) Struct node { int data. How will you delete a node after nd? a) nd->right=nd->right->left. }.nd->right->left=nd->right.

*right. iv) nd->right=ptr->right. struct node *left.29 struct node *left.nd->left->right=nd->right.nd->right->left=nd->left->right. d) nd->left=nd->left->right.nd->left->right=nd.free(ptr).ptr->left->right=ptr->left. struct node *left.free(ptr). Suppose ptr is a node which is not in the beginning and also not in the end. How will you delete a node before nd? a) nd->left=nd->right->left.free(ptr). iii) nd->left->right=nd. Suppose nd is a node which is not in the beginning and also not in the end. ans::a 15) Struct node { int data.ptr->left->right=ptr.*right. c) ptr->left->right=ptr->left->left. ii) nd->left=ptr. nd is the new node. }. ans::c 14) Struct node { int data. Here is the coding: i) nd->right->left=nd. c) nd->left=nd->left->left. b) nd->left=nd->right->right.*right.ptr->right->left=ptr->left. How will you delete a node ptr? a) ptr->left->right=ptr->right. Then what sequence does it follows for inserting nd after ptr? .ptr->left->right=ptr->right. b) ptr->left->right=ptr->right->right.free(ptr). }.nd->left->right=nd. d) ptr->left->right=ptr->left. Suppose ptr is a node which is not in the beginning and also not in the end. }.

13.i.5.70.32.8.70.32.66 c) 10.root).root). What will be the preorder traversal is a) 5.70 d) 8.root).8.iv.root).5.iii.32. delete(13.32. insert(66.45. insert(45.36. insert(13.i d) ii.iii.13 ans::b 18) The postoder traversal is 7.root).root).66. insert(32. insert(25.ii.iii.66.22.45.13.i.10.iii c)iv.36.14.36.8. insert(5.ii.36.root).iv b) ii. insert(70.25.10. insert(13.70 b) 10.5.25. insert(36.25.root).66.3.32.55.root). insert(8.45.45.13.5.30 a) i.root).root).root).17 Then ur Inorder traversal is .iv ans::b 16) In the Given Infix expression which is the root node for ur expression tree (A+B)-(C*D)+G/H*I a) + b) c) * d) / ans::a 17) Consider a binary search tree insert(10.

5.5. while(i==0) { } printf("%d".3.17.55 b) 14.'c'.22. while(++i==1) { } printf("%d".i).70 .22. printf("%s".17.17.55.5.s). } ans::2 3) char s[]={'a'.What will be the root node a) 5 b) 66 c)70 d)30 ans::5 20) which one of the following is true for the binary tree i) root is greater than the left sub tree and lesser than the right sub tree ii) root is lesser than the left sub tree and greater than the right sub tree ans::i a) only i b) only ii c) both i and ii d) neither i nor ii ans::a 1) void main() { int i=0. } ans::infinite loop 2) { int i=1.i).55 d) 55.5.14.17.3 ans::a 19) The preorder traversal is 5.7.7.7.14.66.22.22.77.30.14.'\0'}.3 c) 3.31 a) 3.7. void main() .'b'.

9.1).sizeof(stud)).i<=2.. insert(root. . ans::d 7) ans::d 8) which of these is not a valid character constant a) "A" b) '*' c) '+' d) 'h' ans::a 9) struct student { int i.4). printf("%d". }. printf("%d %d". ans::2 3 4 5 6 7 8 9 10 5) ans::21 6) which can be replaced by a switch block? a) do.3).++*&b).8.7.*stu.*(*(arr+i)+j)).5.3. insert(root.6.4.j<=2. struct student *s. for(i=0.while b) for c) while d) else if which of these is not a operator in c? a) ~ b) ^ c) % d) :: int b=20. stu=&stud.32 ans::abc 4) int arr[3][3]={2. ans::14 10) insert(root. struct student stud.++j) printf("%d".10}. insert(root.2). char c[10].i++) for(j=0.

i). insert(root. printf("%d". What is the preorder for the above tree? ans::2 1 3 4 5 12) 13) The prefix expression is ab+c*d/e-.5).iii only 15) what is the output of the following program? void main() { int i=12. insert(root.3). q=&i.2. insert(root.33 insert(root.1 respectively.iii 14) which operations are more effective in linked list than arrays? i) insertion ii) deletion iii) traversal a)i.ii.5).If the values of a.1).b.i.i d) ii. What is the inorder for the above tree? ans::1 2 3 4 5 11) insert(root.4). *q=*q-8.e are 5.iii b) ii.3. insert(root.ii.iii.2).ii only b)iii only c) all the above d) i.c.i c) iii. } .d.then what will be the output? What is the order in which the preorder is evaluated? i) root node ii) left node iii) right node a) i. int *q.3.

break. case 2: printf("case 2"). } In Unsigned char. bbb(){ printf("Hello")}. a) true b) false int i=1. switch(i*2) { case 1: printf("case1"). ptr[0]=aaa.34 16) what is the use of precedence in C programs for operators? a) Precendence are used to replace the variables used in operations b) precendence are used to allocate memory space c) precendence are used to evaluate the expression first d) None of the above 17) aaa(){ printf("Hai")}.signed value is represented by 1 in most significant bit. default: printf("default"). 18) 19) 20) . } a) case1 case2 default b) case2 c) case2 default d) compiler error struct node { int info.*right. ccc(){ printf("Bye")}. ptr[1]=bbb. void main() { int (*ptr[3])(). break. ptr[2]=ccc. struct node *left.

#define t printf void main() { int i=10. c) nd = NuLL. if nd is a pointer which is pointing to the first node. t("%d".35 }.sizeof(*y)). }. char *j.i).then which one of the following is correct? a) nd->right = NULL.2. 22) 23) 24) 25) . } int a[3][4]={1.5}. printf("%d".3. int i. struct b { struct a x. printf("%d %d".4. d) nd->left->right = NULL. 21) struct a { char *i. which one is used to check the given string is palindrome or not a) Single Linked list b) doubly linked list c) Arrays D) none of the above #define HELLO hai void main() { printf("HELLO"). b) nd->left = NULL.sizeof(y). }*y.a[0][4]).

x).front=-1 then what will be my queue? a) Queue is empty b) Queue is full c) Queue has one element D) Queue has max-1 element void main() { int i.i<=5. printf("%d".8. } int x. for(i=1. } if the outputs are 7.then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero 27) 28) 29) 30) .x). b) auto int x. fun(). printf("%d". printf("%d". void main() { x=7. } If p=(int *) malloc(sizeof(int)*10). x++.i).x).then which is replaced instead of ????? a) extern int x.36 } 26) The formal arguments has a default value zero a) true b) false void fun() { ????? x++. d) register int x.i++) {} printf("%d". if rear=-1.9. c) static int x.

default: printf ("Default"). } 36) Consider a linked list where ptr is a pointer which is not pointing to the first node and not to the last node.then what is the scenario? . break.If there is another node called "new" which is like new->next=NULL.then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero a) i only b)ii only c) both i and ii d) neither i nor ii 32) Predict the output int i=1. } i++: } 33) If rear=0 front=0 what is queue? 34) if rear=max. i=2. front=0. break. i++) { printf ("HAI"). while(i<3) { switch(i) { case 1: printf ("Case 1"). what is queue? 35) for (i=1. case 2: printf ("case 2").37 a) i only b)ii only c) both i and ii d) neither i nor ii 31) If p=(int *) calloc(sizeof(int)*10).

printf("%s".38 a) It is the first node b) It is the last node c) It is in the middle d) none of these 37) If 'a' is the integer which is not statically initialized then what is the value of 'a'? a) zero b) garbage c) none of these struct emp { int a=20. case 1: printf("case 1"). case 2: printf("case 2"). printf("%d". { default: printf("default"). } Which of the following is considered as tokens in C? a) Variables b) Keywords c) Constants d) All the above C is a ____________________ language a) Platform independent programming b) Platform dependent programming c) Object oriented programming d) None of the above main() { int i=3. switch(i). break. 38) 39) 40) 41) . }.oemp->a). void main() { struct emp oemp. char name[10]="AAA".oemp->name).

x). n=strlen(x).b[i]). } int b[5]. return(x). } which is having the more precendence a) * b)+ c)== d) main() { char *x="girl". y=&x. int i.a[i]. main() { static int a[5].39 } 42) #define FIRST 1 #define SECOND FIRST+FIRST main() { printf("%d".SECOND * SECOND). int n. for(i=0. x=*y+2. } } int sample(int x) { int *y.i++) printf("%d %d".i<5. 43) 44) 45) 46) . for(i=0. x++. *x=x[n].i++) { printf("%s \n".i<n. } void main() { int x=5.

3. } 48) To make a pointer 'cursor'as a tail node. error int arr[]={1. k=j/2.3.which line is correct a) cursor->right==NULL b) cursor->left==NULL c) cursor==NULL d) cursor->left==0 Single linked list has a lnk to the next address a) true b) false int 5[x]={1.2.5}.b=8. int a[3][4]={1.a[2][1]). The argc.4. printf("%d %d".2[x]). printf("%d %d".&arr).0}.40 printf("%d". k=&b.*k.4.6. printf("%d".a. printf("%d %d".7.3. } 47) void main() { int *j.2.argv are initialised in a) header file b) within main c) outside main 49) 50) 51) 52) 53) .5}.9. int a=5.sample(x)).8. j=&a.4.arr.*k).*j.5. j=j*2.2.

i. printf("%c". int *p.5 main() { float v. 55) 56) 57) 58) . printf("%f".12. c=(float)a+b. a) i only b) ii only c) both i and ii d) neither i nor ii which is correct? a) Auto variables are local variables b) Extern variables are global variables c) static variables are global variables d) registers are local variables main() { int i=5.*p). p=&5.41 d) none ans:: 54) Queue is i) First in first out ii) used in expression evaluation.5).v). v=10/4.c). printf("%d %d".float b) { float c. } which line is replaced for ?????? to get the ouput of 20. } int foo(int a. } main() { ????? foo(8.0.

*p. while(++i==1) {} printf("%d". p1 and p2 are the 2 nodes and node nd is inserted as nd->next=NULL nd->prev=p1->next 60) void main() { int i=12.4. printf("%d".3. j=++*p+8. for(i=0. while(i==0) { } printf("%d".5.10}.i<=2.j. } ans::21 1) void main() { int i=0.i).i++) void main() 4) . p=&i.'b'. int arr[3][3]={2.500000 59) In a doubly linked list.8.9.s). } output::infinet loop 2) { int i=1.6.42 } ans::2.j). } 3) char s[]={'a'.'c'.i).7.'\0'}. printf("%s".

3). stu=&stud. printf("%d".++*&b).43 for(j=0. insert(root.1).*stu.4).*(*(arr+i)+j)).sizeof(stud)). insert(root. char c[10]. 5) int b=20. insert(root.j<=2.while b) for c) while d) else if which of these is not a operator in c? a) ~ b) ^ c) % d) :: which of these is not a valid character constant a) "A" b) '*' c) '+' d) 'h' struct student { int i.2). What is the inorder for the above tree? 6) 7) 8) 9) 10) . printf("%d %d".++j) printf("%d". struct student *s. which can be replaced by a switch block? a) do.5).. insert(root. insert(root. }. struct student stud.

insert(root. int *q.iii b) ii. *q=*q-8.iii 14) which operations are more effective in linked list than arrays? i) insertion ii) deletion iii) traversal a)i.i). } 16) what is the use of precedence in C programs for operators? a) Precendence are used to replace the variables used in operations b) precendence are used to allocate memory space 12) 13) .i d) ii.e are 5. insert(root.If the values of a.d.c.then what will be the output? What is the order in which the preorder is evaluated? i) root node ii) left node iii) right node a) i. q=&i. insert(root.5). What is the preorder for the above tree? The prefix expression is ab+c*d/e-.i c) iii.ii.b.4).2.3.ii.44 11) insert(root.2). insert(root.iii.1 respectively. printf("%d".3).3.iii only 15) what is the output of the following program? void main() { int i=12.ii only b)iii only c) all the above d) i.i.1).

void main() { int (*ptr[3])(). bbb(){ printf("Hello")}. switch(i*2) { case 1: printf("case1"). ptr[1]=bbb. ptr[2]=ccc. } a) case1 case2 default b) case2 c) case2 default d) compiler error struct node { int info.*right. }. default: printf("default"). ccc(){ printf("Bye")}.signed value is represented by 1 in most significant bit. if nd is a pointer which is pointing to the first node. ptr[0]=aaa. break. break. struct node *left. 18) 19) 20) . a) true b) false int i=1. case 2: printf("case 2").then which one of the following is correct? a) nd->right = NULL.45 c) precendence are used to evaluate the expression first d) None of the above 17) aaa(){ printf("Hai")}. } In Unsigned char.

} The formal arguments has a default value zero a) true 22) 23) 24) 25) 26) . c) nd = NuLL.i). } int a[3][4]={1. char *j. int i. printf("%d %d".4.5}. #define t printf void main() { int i=10.a[0][4]).3. printf("%d". 21) struct a { char *i. }*y.2. d) nd->left->right = NULL. struct b { struct a x. t("%d". }.46 b) nd->left = NULL.sizeof(*y)). which one is used to check the given string is palindrome or not a) Single Linked list b) doubly linked list c) Arrays D) none of the above #define HELLO hai void main() { printf("HELLO").sizeof(y).

47 b) false 27) void fun() { ????? x++. void main() { x=7. x++. d) register int x.9.x).then which is replaced instead of ????? a) extern int x.i<=5. for(i=1.8.front=-1 then what will be my queue? a) Queue is empty b) Queue is full c) Queue has one element D) Queue has max-1 element void main() { int i. fun(). if rear=-1. c) static int x. } if the outputs are 7. printf("%d". b) auto int x.i). printf("%d". } int x.x).then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero a) i only b)ii only c) both i and ii d) neither i nor ii 28) 29) 30) .i++) {} printf("%d".x). } If p=(int *) malloc(sizeof(int)*10). printf("%d".

what is queue? 35) for (i=1. case 2: printf ("case 2"). i=2.then what is the scenario? a) It is the first node b) It is the last node c) It is in the middle d) none of these . } i++: } 33) If rear=0 front=0 what is queue? 34) if rear=max. i++) { printf ("HAI"). break.then which one is true? i) It allocates 20 bytes of memory ii) The value in the memory is allocated to zero a) i only b)ii only c) both i and ii d) neither i nor ii 32) Predict the output int i=1.If there is another node called "new" which is like new->next=NULL. } 36) Consider a linked list where ptr is a pointer which is not pointing to the first node and not to the last node. default: printf ("Default"). break. front=0. while(i<3) { switch(i) { case 1: printf ("Case 1").48 31) If p=(int *) calloc(sizeof(int)*10).

printf("%s". case 2: printf("case 2"). char name[10]="AAA". { default: printf("default"). } #define FIRST 1 #define SECOND FIRST+FIRST 38) 39) 40) 41) 42) . }. } Which of the following is considered as tokens in C? a) Variables b) Keywords c) Constants d) All the above C is a ____________________ language a) Platform independent programming b) Platform dependent programming c) Object oriented programming d) None of the above main() { int i=3. void main() { struct emp oemp. switch(i).49 37) If 'a' is the integer which is not statically initialized then what is the value of 'a'? a) zero b) garbage c) none of these struct emp { int a=20. case 1: printf("case 1"). printf("%d".oemp->name). break.oemp->a).

return(x). x=*y+2. } } int sample(int x) { int *y.50 main() { printf("%d". main() { static int a[5].x).i++) printf("%d %d".i<n. } 43) int b[5].i<5. n=strlen(x). } which is having the more precendence a) * b)+ c)== d) main() { char *x="girl".SECOND * SECOND). int i. x++.i++) { printf("%s \n". y=&x. *x=x[n]. for(i=0.sample(x)). } 44) 45) 46) .b[i]). printf("%d". int n. } void main() { int x=5. for(i=0.a[i].

int arr[]={1.5.2. printf("%d %d".*j.*k).0}.6.3.4.5}.a. j=&a. The argc. k=&b.4.&arr).9. int a=5.which line is correct a) cursor->right==NULL b) cursor->left==NULL c) cursor==NULL d) cursor->left==0 Single linked list has a lnk to the next address a) true b) false int 5[x]={1. printf("%d". j=j*2. printf("%d %d".b=8.*k.arr.7.8. k=j/2.a[2][1]).2.2[x]).5}. int a[3][4]={1.3. } 48) To make a pointer 'cursor'as a tail node. printf("%d %d".3.2.argv are initialised in a) header file b) within main c) outside main d) none Queue is 49) 50) 51) 52) 53) 54) .4.51 47) void main() { int *j.

printf("%c". p1 and p2 are the 2 nodes and node nd is inserted as .c). int *p. printf("%d %d". } int foo(int a.v).float b) { float c. } 56) 57) 58) 59) In a doubly linked list.12. } main() { ????? foo(8. a) i only b) ii only c) both i and ii d) neither i nor ii 55) which is correct? a) Auto variables are local variables b) Extern variables are global variables c) static variables are global variables d) registers are local variables main() { int i=5.i.0. p=&5.*p). c=(float)a+b.52 i) First in first out ii) used in expression evaluation. } which line is replaced for ?????? to get the ouput of 20.5). printf("%f".5 main() { float v. v=10/4.

What is the output of the following: unsigned i=32768. } b. d. 32768 Ans::b 2. } a.53 nd->next=NULL nd->prev=p1->next 60) void main() { int i=12. void main() { static int i=3. p=&i. Error d. printf("%d". j=++*p+8. -32768 c. } 1. } a. b.t). char *t="test". What is the output of the following: main() { void change(char *). c.*p. None of the above . change(t). printf("%s".j). void main() { printf("%d". printf("%d".j. int i. 3 Multiple declaration (since I is static) 0 None of the above Ans::3 3.i).i).

nest d.54 void change(char *t) { char *ab="new test". break. What would be printed: #include<stdio. Welcome c. test c. case 3>2:printf("Hello"). void main() { while(i) { switch(i) { case 3<2:printf("Hi"). Error . *t=*ab. new test b. None of the above 4. default: printf("welcome"). } a. break. Hi Ans::c b.h> int i=0. No output d. } ++i. } } a.

p1). hbj!gsjfoet hbj!gsjfoet d. } int get() { return(60).a.int *b) . 10 20 Ans::a 7. ibj!gsjfoet ans::d b. void main() { int x=20. printf("%d ". printf("%s %s". None b. 20 10 c.&b).h> int get(). } a. a=b. main() { char *p="hai friends".*p1. swap(int *a. Error d. swap(&a. } void main() { int a=10. hbj!gsjfoet c. printf(“%d %d”.x). b=t. } a.b). t=a. } a.p. x=get(). p1=p.55 # include<stdio. 60 { int *t.b=20. 20 5. Garbage c. Garbage value b. Error d. while(*p!='\0') ++*++p.

&a[1]). When fopen() fails to open a file it returns _______ a. main() { char a[100]={“abcdef”}. NULL b. a++. -1 c. 1 d. printf(“%s”. None of the above .56 8. } a) bcdef b) abcdef c)compilation error d) none of the above 9.

2 1 c. 3 2 1 0 b.sizeof(p). main() { static int i=3. char **p. fun( ) { printf("%d\n". return i>0?main():0. printf("%d". printf("%s". a. } } a. int i=5. printf("\n%s".57 10.*p++). 3 2 1 c. 2 1 b. 3. } main( ) { int i= 2. 3. dharma harma ewlet-packard b.++*p). P is a character pointer variable then. void main() { char *s[]={"dharma". i). 2 1 0 d."hewlet-packard". harma hewlet-packard . i * 3).sizeof(*p)). 1 2 b. printf("%d %d". 6 c. } a. 1 1 13. 3 d. p=s. printf(" %d". 0 12."siemens".i--). 15 11. fun(). 2 2 d. printf("\n%s".++*p). what will be the output of the following statement. } a."ibm"}. { int i = 3.

harma harma hewlet-packard d. harma harma ewlet-packard .58 siemens c.

Which of the following function does not return an integer value? A. printf("%s\n". printf B. scanf C.59 14.h> main() { switch (5) { case 5: printf(" 5 "). 5 6 b. printf("%s". printf("%d". Register C. Which of the following is not a storage class in C? A. amco Systems mco Systems 16. } a. 5 10 D. Samco Systems Samco Systems c. case 6: printf(" 6 "). (*ptr)++. Samco Systems amco Systems d. default: printf(" 10 "). } } A. void main() { char *ptr="Ramco Systems".abc(i=i/4)). 5 B. Extern D. int i=5.ptr). ptr++. strcpy D. 5 10 6 C. Stack B. amco Systems amco Systems 15. Static 17. strlen 18.ptr). } a) error b) 5 c) 2 d) 0 . #include <stdio. int abc(int z) { return i/2. } main() { int i=4.

val=printf("C") + printf("Skills"). return(0). } (a) 7 (b) C7 (c) Compile-Time Error (d) CSkills7 .val).60 19. printf("%d". What will be the output of the following program : int main() { int val=5.

switch(i) { case 1: printf("1").) operator 21.y=20.*a=*a-*b. 20 20 d. printf("%d". Compiler Error c.*b=*a-*b.&y). 20 10 b. printf("%s". 10 10 22. c = ++*p++. int swap(int *a. char c. printf("x= %d y = %d\n". }.int *b) { *a=*a+*b. default : printf("0"). } b) b c) y d) z . printf(“%c”. Run time error d.h> main() { struct xx { int x=3.x. use dot (.5. #include<stdio. swap(&x.5: printf("2").s->x). } main() { int x=10. } a. case 1. char name[]="hello". 3 hello b.c).s->name). 10 20 c.61 20. } a) a 23. main() { char *p = “ayqm”. struct xx *s. main() { float i=1.y). } a.

d. 0 b. nd is a node which is not in the beginning and also not in the end.nd->right->left=nd->left->right. struct node { int data. Consider the following structure . How will you remove a node after nd from the list? a) nd->right=nd->right->left. Then the output is a) -6 b) 12 c) 20 d) None d) None 28. 3 respectively. in that case the variables are assumed a) static b) external c) global d) auto d. 30. 2 0 24. None of the above 25.nd->right->left=nd. If the CPU fails to keep the variables in CPU registers. In the stack. 0 1 2 c. struct node *left. 6. 1 2 0 d. 5. d) nd->right=nd->left->right. if rear=max-1. -1 b. In the Given Infix expression which is the root node for your expression tree (A+B)-(C*D)+G/H*I a) + b) c) * d) / 31. e. b) nd->right=nd->right->right. c) nd->right=nd->right->left. Compiler Error e. The EOF is equivalent to a. 0 26.The values of a. front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 27. c. 2. In a queue. 2.62 } a.nd->left->right=nd. }. The postfix expression is ab-cd+*ef/-.f are 4.*right. if top=0 then the stack is a) Stack is empty b) Stack is full c) Stack has only one element 29. b.nd->right->left=nd->right. 1 c.

struct node *link. }. b) ptr->link=ptr. Then if you remove a node after ptr from the list. d) ptr=ptr->link->link. then the code will be a) ptr=ptr->link. . Suppose ptr is a pointer which is not pointing to the first also not to the last node. c) ptr->link=ptr->link->link.63 struct node { int info.

A binary tree with 15 nodes have _____ null branches a) 15 b) 14 c) 16 d) 17 1. a) b) c) d) no effect inserts a node deletes a node shuffling of pointers -+A/*BCD/*EFG 33. Printf(“%d”.ch[0]=4 . What is the Infix expression for a) A + B * C / D – E / F * G b) A + B / C * D – E * F / G c) A + B * C / D – E * F / G d) A . free(temp). Here is an infix expression: 6+2*(1*5-9). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What does below code do.a=5. temp ->next -> prev = temp -> prev.64 32. union u { Int a.a). U1. u1. if temp is pointing to a node other than first and last node temp -> prev ->next = temp ->next. 1 . } (a) 5 (b) 42 ( c) 1028 (d) 24 36.B * C / D + E * F / G 34. 35.ch[1]=2. What is the postfix expression for A + B * C / D – E * F / G a) ABC*D/+EFG*/b) ABC*D/+EF*G/c) ABCD/*+EF*G/d) None of these. }u1. U1. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? a. Char ch[2].

b.ch[1]= 2. } a) 3 2 515 b)515 2 3 c) 3 2 5 d) none of these main() { . u.ch[0]= 3. char ch[2]. All of the above. a. 45. d. A run-time error always occurs when *p is evaluated What kind of list is best to access the item at given position n?" Doubly-linked lists.u.u.Suppose that p is a pointer variable that contains the NULL pointer.i). 5 39. What happens if your program tries to read or write *p? a. }. union a u. a. Singly-linked lists.ch[0]. printf("%d %d %d". 50.h> void main() { union a { int i. Evolution of postfix expression. A run-time error always occurs when the program finishes. Doubly-linked or singly-linked lists are equally best Which of the following applications may use a stack? A parentheses balancing program.u. d. #include<stdio. d. The results are unpredictable. Syntax analyzer for a compiler.ch[1]. c. b. c. A syntax error always occurs at compilation time. u. c. 2 3 4 e. Lists implemented with an array. d.65 b. c. b.

day.screen. &student.dob. scanf("%s%d%d%d".month. } a) It scans perfectly with error compilation Error b) scanf format is incorrect c) No Error d) In printf().the appearance of the output of the output can be affected by 1) field with 3) flag 2) conversion character 4) all of the above Any of the following programs in c has access to three standard files: 1) standard input file.dob. stud.rollno.year). &student. standard output file.screen 4) all the above Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above Function definition void check(int i .year. struct date { int day. &student.char*j) is 1) call by value 2)call by reference 3) both (1) and (2) 4)in valid function definition Masking is used . stderr 3) keyboard.stdout.month. standard error file 2) stdin. struct date dob. }.dob.66 struct student { char name[30]. }stud.

num[25]=num[0].num[25]). } (a)1000 f87 (b)8800 0xf88 (d)0x1000 0xf88 Ans. printf("\n%d %d". .z. num[25]=200. num[0]=temp. z=x<<y.temp. (d) (c)1000 f88 int num[26]. temp=num[25]. printf("%#x %#x". while the reminder of the new variable is filled with 1’s (using the bitwise OR) 3) to copy a portion of a given bit pattern to a new variable.x>>y-1). while the remainder of the new variable is filled with 0’s(using the bitwise AND) 2) to copy a portion of a given bit pattern to a new variable.y=5.z.67 1) to copy a portion of a given bit pattern to a new variable.num[0]. while the remainder of the original bit pattern is inverted within the new variable 4) all of the above A fields width specifier in a printf() function 1) specifies the maximum value of a number 2) controls the size of type used to print numbers 3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number The global variables by default belong to 1) the register type 3) the auto type 2) the static type 4) the dynamic type What will be the output of the following program : void main() { unsigned x=0xf880. num[0]=100.

for(i=0.i<=48.5.a+i). printf("\n%d. array[i].a[3].6.i++) { sub[i]=i. o/p: address of a 5.4.7}.6.a[++i]).i<5.a[5]={3. for(i=0.a[5]). printf("\n%d". int array[26].4. o/p: 4.6. o/p: a[i]=a+i adress’s of all int’s is printed 6.7}.i++) { array[i]='A'+i.5. for(i=0.adress value 8.i++) printf("\n%d". for(i=0.4. printf("\n%d".a[5]={3. } o/p:65=A to 97-Z int sub[50].4. } o/p:0-48 4.a[3]). printf("%d". int i. a[3]=8.i. int i.array[i]).7}. .a). 3.6.i.5. %c".5. int i. int a[5]={3.i++) printf("\n%d".i<5.a[5]={3. sub[i]).68 o/p: 200 100 2.6. int i.i<=25. printf("\n%d". o/p: adress of a[5] is printed 7.7}.

a[i][i]).69 o/p:8 9.4}. "Hemal".a[2][2]={1. "Parag".i++) printf("%d . int i. int a[2][2]={1.i<2.3.8999 8686. "Hetal"}.2. "Hemal".4}. o/p: 8230 8234 ( adress’s of int’s) 11. o/p: akshay 14.a).4}.a[2][2]={1.i<2.a[i]). "Hetal"}. "Parag".2.4 10. printf("%s".3.3. "Chirag".2. for (i=0. for (i=0. int i.2. o/p:chirag . %d\n". "Chirag".8999 12. int i.i++) printf("%d". printf("%d". o/p: base address of a (1st element) 8686 13. o/p:8682.a[i]+1).3.4}. o/p: 1.a+2).i++) printf("%d". char a[5][10]={"akshay".a). char a[5][10]={"akshay". printf("%s".a[2][2]={1.i<2. for (i=0.

char a[5][10]={"akshay".a[2][7]). "Hetal"}. "Chirag". "Hetal"}.c). "Parag". char s[]="Get organized ! learn C". printf("%s". printf("%c". o/p:a 18. printf("\n%c". "Parag". o/p: (some symbol) 19. char a[5][10]={"akshay". "Chirag". "Hemal".a[+2]). . "Parag". printf("\n%s". char a[5][10]={"akshay". printf("%c".&s[2]).c[0]). "Hetal"}. "Chirag". "Parag". "Hetal"}. "Hemal". o/p:chirag 17. "Hemal".a[2][4]). printf("\n%s". o/p:chirag 16. "Chirag". printf("%c".70 15. char a[5][10]={"akshay". "Hemal". char c[2]="A". o/p:A A 20.a[2]).

21.'l'. } char str1[]={'H'.&s). while (s[i]!=0) { printf("\n%c"."abcdefgh"[4]). o/p:e printf("\n%d%d%d". display(). str2). printf("\n%s". o/p: Morning printf("%c". } void display() { printf("\n Brilliants too use C!"). str1).'l'. o/p:1 2 2 22.sizeof(3)). i++. } . printf(5+"Good Morning"). 24.'o'}.s). #include<stdio. main(). int i=0. printf("\n%s". o/p: t organized ! learn C Get organized ! learn C". printf("\n%s". Get organized ! learn C".s[i]). char str2[]="Hello".i[s]). void main() { printf("\n Only smarties use C?"). 1. o/p: Hello garbage values Hello 23.sizeof('3').71 printf("\n%s".'e'.h> void display(). char s[]="No two viruses work similarly". printf("\n%c".sizeof("3"). 25.

c=check(i *1000). main(). . } int check(int ch) { if(ch>=40000) return (ch/10). #include<stdio.h> void main() { printf("\n Only smarties use C?"). #include<stdio. } o/p: error cannot call main() from the program 3. printf("\n%d". else return (10). void main() { int i=45. printf("\n%d". } int check(int ch) { if(ch>=45) return (100).c.72 o/p: error cannot call main() from the program 2.c). c=check(i). void main() { int i=45. } o/p:100 4.c.h> int check(int). #include<stdio.h> int check(int).c).

int x=10. display(). decrement(). } void increment() { i=i+1.x). increment(). } o/p: 20. decrement(). void display(). void main() { int x=20. void main() { printf("\ni=%d". printf("\n%d". .inside display 10 6. void decrement().73 else return (10). } o/p:10 5. } void display() { printf("Inside display %d". void increment().x).i). #include<stdio. increment().h> int i.

int j) { i=i*i.i). } void decrement() { i=i-1.&j).int *).j). printf("\non decrementing i=%d".j=2. fun(&i.i. } o/p: 25 4(call by reference) 9. } void fun(int i.int *j) { *i=*i * *i.i). void fun(int *. } o/p:1 2 1 0 7.j). void main() { int i=5.int y) { int i=4. printf("\n%d%d".74 printf("\non incrementing i=%d".j). printf("\n%d%d". .i. fun(i. fun(&i.2 (call by value ex:) 8. void fun(int *x.j=2. } o/p:5.int) void main() { int i=5. j=j*j. *j=*j * *j. } void fun(int *i.j=2.j). void fun(int.

} o/p: no output 31.y=0. void fun(void *).x). printf("%d".j). vptr=&i. } void fun(int *i.75 printf("\n%d%d".1. fun(vptr). j=j*j.y).1. while (x>=0) { x--. } .x.int j) { *i=*i * *i. y++. int i. x=x-0. if(x==y) continue. q=(int **)&p. while(x==1.**q). void main() { void *vptr. float x=1. int x=3.z. } void fun(void *p) { int **q. else printf("\n%d%d".1) { printf("\n%f". } 10.i. } o/p:0 30.

for(.printf("\n%d". int i=1. } o/p:2 5 36. o/p: infinite 1’s 34. x--. for(.i. j=1. i++. int x=4. int i. int i=0.y=0.. } o/p:4 0 31 33.) { if(i>5) break. char suite=3. else j+=i. switch(suite) { . while(x>=0) { if(x==y) break. for(i=1.z.y).i<=5. printf("\n%d".x.76 o/p: 2 1 12 03 -1 4 32. 35. i+=j.) printf("\n Here is some mail for you"). else printf("\n%d%d".i)).j). y++.

break. int k. default: printf("Ofcourse provided you win a prize"). float j=2. } o/p: You always lose the gold prize 38. int c=3.77 case 1: printf("\n Diamond"). case 4/2: printf("\nInvestors are moody"). } o/p: Atleast employees are good 39. case 3: printf("You always lose the gold prize"). break. default: printf("\n Heart"). } o/p:Heart 37. case 1+0: printf("\nMarkets are pricey"). int i=3. case 8%5: printf("\nAtleast employees are good"). switch(c) { case '3': printf("You never win the silver prize"). switch(k=j+1) . case 2: printf("\n Spade").0. switch(i) { case 0: printf("\nCustomers are dicey").

switch(ch) { case 'a': case 'b': printf("\nYou entered b").x<78).int ch='a'+'b'. case 0: printf("\n Weeding grass").78 { case 3: printf("\n Trapped"). } 42. 43. } o/p: You entered a and b 41. int i=1. int x=25. switch(i-2) { case -1: printf("\nFeeding Fish"). break. } o/p:Trapped 40. case 1: printf("\n Mending roof").x=50. case 'A': printf("\na as in ashar").x==25. default: printf("\n Caught"). o/p:0 50 1 int x=25. case 'b' + 'a': printf("\n You entered a and b"). printf("%d%d%d".x==50. default : printf("\n Just to survive").x=50. printf("%d%d%d". .x<78).

40.x=100.20. printf("\n%c".40.20. for(i=0. for(i=0.*(i+s)). k++.50 2. o/p:error 4.x<78.*tt.*k).5 3.o/p:0 100 1 1. int b[]={10. int i=0. int x=50.30. } char s[]="Churchgate:no church no gate".*(b+i)).40. } o/p: 0.*(s+i)). ss=s. while (s[i]!=0) { printf("\n%c".30. i++.x==50). int i.40.79 44.0.i++) printf("\n%d". char s[]="No two viruses work similarly".50}. int b[]={0. while(*ss!='\0') *ss++=*tt++.i++) { printf("\n%d".5}.20. k=b.*k. printf("%d%d%d". printf("\n%s".0.i<=4. char *ss.i<=4. o/p: 10.20. int i.t). char t[25]. .

printf("\n%f %f %f %f %f". #include<stdio. if(j==k) printf("The two pointers point to the same location").h> void main() { int s[2][2]={ {2. o/p: The two pointers point to the same location 6.c).j. j=&arr[4].*b.*&a.b.a. 8. int *j.72. for(i=0.80 5.3}.2.36}.j++) printf("%d\n". } int *p. {3. b=&a.5.j<2. c=b.2}.&a. k=(arr +4).3} }.a[3]={1. .45.*(&a). void main() { float a=13. } o/p:2 2 3 3 7.*c).i<2. else printf("The two pointers do not point to the same location"). int i.*(*(s+i)+j)). float *b. printf("\n%u %u %u".36. int arr[]={10.i++) for(j=0.*c.*k.20.

p=&a. o/p:20 20 10. printf("%d". . int a. 13.p). float *p. printf("%d". int a.&a.*p).*p++). printf("A= %d and *P=%f".a.p). p=&a. q=&p. int *p.50}. int a[]={10. printf("A= %d and *P = %d and **Q = %d".a. a=30.40. int *p. o/p:1 1 2 9.*p).*p).30.&a. scanf("%d". a=20. printf("%d". 11.81 p=a.p).**q). int **q. 12. printf("A= %d and *P = %d". float a. a=30.90.b=40. p=&a. float *p. *q=&b. p=&a. p=&a.*p. a=30.a.a. int *p. printf("Address of A= %u and Value of P=%u".*a).*p. a=20. 14. printf("Address of A= %u and Value of P=%u".a.20.

"K").300).a[1]). int *p. printf("%d". printf(str. 18.300).50}.*p). str="%4s". p++.30.40. printf("The value of a[0] is %d\n". printf("Now the value of a[1] is %d\n". int a[]={10. p=p*2.20.30. *p=300. 15.50}. p++. p=a. int a[]={10. } void main() { char *str.*p).40. .20.82 p=a. 17. str++. void main() { char *str. } void main() { char *str.*p). printf("Now the value of *P is %d\n". p=a. } 16. str="%d\n". printf("The value of *P is %d\n". printf(str-1. printf(str.*p). 19. int *p. str="%d\n".

} 5. i=3.d). } 2. #define disp printf 21. j=&i.pi). } 3. } 4. #define pi 3.i**j*i+*j). void main() { disp("Hello World"). void main() { int i.14 void main() { float d=pi. #define newline "\n" void main() { printf("Hello newline World"). #define pi 3. printf("%f".*j. printf("%d".11. printf("%f". } 1.14 void main() { float pi=2.83 20. #define pi 3.14 void main() .

printf("%f".**k). k=&j. } (1) which of the following lines gives/prints the output 20 void main() { int i=20. printf("%f". printf("\n%d". x=y+NULL.i). #define maxi(a. printf("\n%d". scanf("%f".&pi).pi).y)). } (2)only 7 (4)all 5. j=&i. printf("%d".**j.y=6. printf("\n%d".y.84 { printf("%f".6. scanf("%f%f".&y).7 lint1: line2: line3: line4: line5: line6: line7: (1) only 5 (3) only 6 ans:(4) (2) void main() { int x. .***&k).maxi(x. int *k.pi).x). } 6.b) a>b?a:b void main() { float x.&x.

++i) printf("%f ". .5.7.400000 5. } o/p: 1.85 } o/p: 6 (3) void main() { static int arr[12]. printf("%d". } o/p: 24 (4) void main() { float a[]={1.2.a[i]).4.700000 12. for(i=0.3.000000 0.3}.7["wipro infortech").i<=5.200000 3.300000 0.sizeof(arr)).12. int i.000000 (5)A user-defined function returns a pointer (yes/No) yes (6)In a normal c program the library will be defined in ________________ (7) void main() { printf("%s".

86 } (8) #include<stdio.h> void main() { char *p="hello".sizeof(*q)). case 3>2: printf("Hello"). char q[]={'h'. printf("%d %d".'o'}. default: printf("welcome"). } } o/p: error . } o/p: 1 1 (9) #include<stdio.sizeof(*p).'l'.h> void main() { int i=0. } ++i. break. while() { switch(i) { case 3<2: printf("Hi"). break.'l'.'e'.

char str2[]="Hello" if(str1==str2) printf("\nEqual"). case 2: printf("case2"). } } o/p:default case1 case2 case2 (11) #include<stdio. default: printf("Default").87 (10) void main() { int i=0. } 0/p: Error . } ++i. while(i<3) { switch(i) { case 1: printf("case1").h> void main() { char str1[]="Hello". else printf("\nNot equal"). break.

i=0. struct emp .i--) { printf("%d". for(i=2. }.h> void main() { int i.88 (12) which one of the comment line statement is correct (1) (2) (3) (4) /* hello world */ //hello world// */ hello world */ /&hello world &/ Ans: (1) (13) The value of EOF is _____ (1) NULL (2)0 (3)-1 (4)1 Ans: (3) (14) #include<stdio. } } No output (15) struct addr { char city[5].&i). char street[5].

struct emp *pemp. ans: pemp->a->city (16) If you want to allocate 2 blocks of memory for a set of 5 integers. struct addr *a. }.89 { char name[20]. } 0/p: 50 (18) #include<stdio. How will you access city from the *pemp.h> void main() { int i=10. printf("%d ".which will you use? (a) malloc (c)neither (a)&(b) Ans:(d) (b)calloc (d)either (a)&(b) (17) #include<stdio. int empno.h> #define HELLO hi void main() { .i=50).

}. void main() { struct emp *e1. } o/p: HELLO (19) Convert to prefix (a+b)*(c/d) ans: *+ab/cd (20) #include<stdio.h> struct person { char *name.h> .90 printf("HELLO"). char *age. struct emp { int a. }. char *c. struct person *addr. } o/p: 4 (21) #include<stdio. printf("%d".sizeof(e1)).

i=10/4. line&: j=&(i+25). printf("%f". printf("%d". } o/p: 2. i=10/4.i).91 void main() { int i.000000 (23) To arrange nodes in ascending order ________ is used 1)inorder ans: inorder 2)preorder 3)postorder 4)all the above (24) int i=6. .*j. line1: j=&i.h> void main() { float i.i). } o/p: 2 (22) #include<stdio. line2: j=&35.

h> void main() { int a[3][4]={1. } o/p: 1 (26) #include<stdio.h> void main() { int i=10.92 Which of the above lines are correct? Ans: line1 (25) #include<stdio.4.x).6. } o/p: 60 (27) #include<stdio.8.7.9}. void main() { int x=20.2. printf("%d". x=get(). printf("%d ".h> int get().5.3. } int get() { return(60).i==10). .

int i. for(i=0. }.h> void main() { static int a[100]. struct details { struct city c.a[2][1]).i++) printf("%d". } o/p: 0 (28) #include<stdio. char address[0].93 printf("%d ". } o/p: 0 0 0 0 (29) which is better memory allocation when size is not known 1)static ans: dynamic (30) struct city { char name[10].i<4. 2)dynamic 3)both 4)neither .a[i]).

struct details *d.address Ans:d->c.p>=array.*p).c.*p. p=&array[0] + 4.40.c->adddress (31) #include<stdio. //p=array+4 for(.30.50}.address 2)d.94 }. } Ans:50 40 30 20 10 (32) A complete binary tree is (a) non-leaf nodes have two child (b) all left subtree less than root and root less than right tree which is correct 1) a alone 2)b alone 3)neither (a) nor (b) (33) Linked list is better than array because of 1) insertion 2)deletion 3)traversal a) (1) & (2) b) (2) & (3) . How will u access address(member) 1)d->c.p--) printf("%d ".address 3)d.20.h> void main() { int array[]={10.

b=3.to add a new element in the tail node (35) #include<stdio.h> #define output(int) printf("%d ".h> #define wipro main void wipro() { printf("main").int) void main() { int a=2.h> #define wipro printf void main() { wipro("welcome"). output(a).95 (34) In the doubly linked list . } o/p: 2 3 (37) #include<stdio. } o/p: main (36) #include<stdio. } . output(b).

ptr[1](). } void main() { int (*ptr[3])(). } bbb() { printf("hello").h> aaa() { printf("hi").d=3 . } o/p: hello (40) a=15. ptr[2]=ccc. ptr[1]=bbb.b=3.96 o/p: welcome (38) Which one of the following statement is false for binary search tree 1) root is less than left and right subtree 2)root is less than left subtree but greater than right a) 1 only b) 2 only c)both 1 and 2 d)neigher 1 nor 2 (39) #include<stdio. } ccc() { printf("bye"). ptr[0]=aaa.c=5.

for(i=0.h> void main() { int a=10.j<5. printf("wipro"). } } } How many times wipro will be printed o/p: 1 time 42) #include<stdio. } o/p: hi .97 a*b+c-d evaluate the expression Ans:47 (41) #include<stdio.j.j++) { if(i==j) break.h> void main() { int i. a+=1. printf((a>b)?"hi":"hello").i++) { for(j=0.b=10.i<2.

}.what we will use? 1)malloc( ) or calloc( ) 3)calloc( ) Ans: (1) 47) #include<stdio. for(i=0. int i. void main() 2)only malloc 4)neither malloc( ) nor calloc( ) . } o/p: 0 0 0 0 0 46) For allocating 2 blocks of 5 elements of integer type.i<5.++i) printf("%d ". char name[15].h> void main() { static int a[5].h> struct emp { int i.98 43) which is not an operator in c? 1)& 2)! 3)~ 4):: 44) Which operator is highest precedence? a)"==" b)"*" c)"+" d)"->" 45) #include<stdio.a[i]).

printf("%s". } o/p:Hello 50) The range of unsigned integers is _________ . } Ans: error 48) The arguments in a function call are known as a) Actual parameters b)Formal parameters 49) #include<stdio. } char *fun() { return("Hello").h> void main() { char *fun(). if(e1==e2) printf("\nstructures are equal"). char *s."hi"}.99 { struct emp e1={1. e2=&e1.s). else printf("\nstructures are not equal"). s=fun().*e2.

static int b=5.b).a). printf("%d ". } void main() { fun1(). a++. } o/p: . b++.(2).100 51) prefix to infix postfix to infix 52)Which is initialized as zero 1)global variable 3)register variable a)(1) and (2) c) (1). printf("%d\n".(3) and (4) 54) #include<stdio.h> fun1() { int a=5. fun1().(2)and (3) Ans: a 53) which statement used to read from file 1)fgets 2)fread 3)fscanf 4)sscanf 2)static variable 4)extern variable b) (1) and (3) d) (1).

5.h> void main() { int a.101 66 67 55) In what aspect linked list is efficient than array 1)Insertion a)1 and 2 Ans:(a) 2)deletion b)3 only 3)Traversal c)2 and 3 only 56) #include<stdio. a=9/4.a). printf("%d". for(i=16/3.h> void main() { int i. } o/p: no output 57) #include<stdio. } Ans: 2 58) #include<stdio.i++) printf("%d".i<5.h> .i).

(b) and (d) 61) #include<stdio.h> void main() { char str1[]="Hello". b) To read a character by character in files fgetc is used.h> itn one_d[]={1. } o/p:false 60) Which of the following is correct a) To read a character by character in files getc is used.2. void main() . d) To read a line by line in a file fgets is used. Ans:(a). c) To read a line by line in a file gets is used. if(str1==str2) printf("True"). } o/p: True 59) #include<stdio. else printf("False").3}. char str2[]="Hello". else printf("False").102 #define TRUE 1 #define FALSE 0 void main() { if(TRUE) printf("True").

}. } /*#include<stdio.d1->c.103 { int *ptr. } }*/ //______________________________________________________________________ ________ /*#include<stdio.address). }*/ //______________________________________________________________________ ________ . }. void main() { struct details *d1. struct details { struct city c. int *p. ptr+=3.h> void main() { int array[] = {10.*ptr). p = &array+4.p>=array.20. p--) { printf ("%d \n".50}.h> struct city { char name[10]. ptr=one_d.30. printf("%d". char *address.40. for (. *p). scanf("%s".

which order is correct 123 321 3 1 2 */ //______________________________________________________________________ ________ /*#include<stdio. ++q.4. nd-> prev->next = tail. j++) { printf("%d".5}.8. *c). to add a new element in the tail node 1. } for (j=0.7. *p). . ++q.> prev = tail. *p=c. j++) { printf("%d". 3 nd .4. for (j=0. j<=5.4. j<5.3. *q = c.104 /* A complete binary tree has statement 1: non-leaf nodeshave two child statement 2: All left subtree values less than root and root less than right tree Which is correct 1 alone 2 alone either 1 or 2 neither 1 nor 2*/ //______________________________________________________________________ ________ /* In doubly linked list. nd->next = NULL: 2. int j.6.h> void main() { int c[] ={2.

int by default is short int 4. j<5. for(i=0.h> #include<string. } }*/ //______________________________________________________________________ ________ /*#include<stdio. short int by default is signed short int */ //______________________________________________________________________ ________ /*#include<stdio. ++i) { printf ("%s \n". x++. x). j++) . i++) { for(j=0. i <2. signed char range is -128 to 127 2. *x = x[n]. for(i=0. unsigned char range is 0 to 255 3.h> void main() { int i. i <n.n.h> void main() { int i. char *x = "OOAD". n = strlen(x). j.105 } }*/ //______________________________________________________________________ ________ /* Which of the following is correct 1.

h> void main() { int *p. ???? . case 1: printf ("Case1"). } } }*/ //______________________________________________________________________ ________ /*#include<stdio. j. runtime error while acessing the pointer c. break. } }*/ //______________________________________________________________________ ________ /* When pointer is assign to null pointer what will be the output a. switch(i) { case 2: printf ("Case2"). compile Error b. some output*/ //______________________________________________________________________ ________ /*#include<stdio. printf ("wipro").106 { if(i==j) break.h> void main() { int i=2.

h> aaa() { printf("hi"). } ccc() { printf("bye").h> #define wipro main wipro() { printf ("main"). } void main() { int (*ptr[3])(). }*/ //______________________________________________________________________ ________ /*#include<stdio. ptr[0] = aaa. } bbb() { printf ("Hello"). ptr[1] = bbb. j). ptr[2](). printf ("%d". } . ptr[2] = ccc. }*/ //______________________________________________________________________ ________ /*#include<stdio.107 *p = 35.

root is less than left & right sub tree 2. }*/ //______________________________________________________________________ ________ /* Which one of the following statements is true for binary searc tree 1. }*/ //______________________________________________________________________ ________ /*#include<stdio.b=3. output(a). int). output(b).h> #define wipro printf main() { wipro("Hai").h> #define output(int) printf ("%d".108 void main() { wipro(). void main() { int a=2. root is less than left sub tree but greater than right sub tree*/ //______________________________________________________________________ ________ /* The Range fo unsigned integer is _____________________________*/ //______________________________________________________________________ ________ . }*/ //______________________________________________________________________ ________ /*#include<stdio.

h> void main() { int i=10. j. } }*/ //______________________________________________________________________ ________ /*#include<stdio.l). i++. extern int k =0. j++.109 /*#include<stdio. /*They will ask u what will be the define statement to . while(++i>10) { printf ("something"). k++.h> define mul(a) (a) * (a).h> void main() { auto int i=0. l++. printf ("%d %d %d". i. }*/ //______________________________________________________________________ ________ /*#include<stdio.h> void main() { const char a="b". static int j=0. }*/ //______________________________________________________________________ ________ /*#include<stdio. register int l=0.

This is correct option to get the output*/ /*void main() { int result.h> struct a { int no. i<5. void main() { printf ("%d %d %d %d". } }*/ //______________________________________________________________________ ________ . }*/ //______________________________________________________________________ ________ /*#include<stdio. printf ("%d". sizeof(a1)). sizeof(a1->no). int *no2. }*/ //______________________________________________________________________ ________ /*#include<stdio. i++) { printf ("%d". for(i=0. } *a1. int *no1. result = mul(10). sizeof(*a1). int i.110 get the output as hundred and the define statement have four opitons. result). a[i]).sizeof(a1->no1).h> void main() { static int a[5].

3. i= =10). int i.++i) printf("%f ". } */ //______________________________________________________________________ ________ /*#include<stdio.h> void main() { float a[]={1.4.12. } */ //______________________________________________________________________ ________ /*#include<stdio.3}. }*/ //______________________________________________________________________ ________ /*#include<stdio.y=6.2.7.x). printf("%d". printf ("%d".h> void main() { int x. for(i=0. x=y+NULL.h> void main() { static int arr[12].sizeof(arr)).111 /*#include<stdio.i<=5. printf("%d".h> void main() { int i=10.a[i]).5. }*/ //______________________________________________________________________ ________ //A user-defined function returns a pointer (yes/No) .

char q[]={'h'.'o'}.'l'. case 3>2: printf("Hello"). break.h> void main() { int i=0. } }*/ //______________________________________________________________________ ________ /*#include<stdio.112 //______________________________________________________________________ ________ /*#include<stdio. default: printf("welcome").sizeof(*q)).'l'.h> void main() { char *p="hello". } ++i.h> void main() { int i=0. break.sizeof(*p). printf("%d %d". while(i<3) { switch(i) { case 1: . while() { switch(i) { case 3<2: printf("Hi").'e'. }*/ //______________________________________________________________________ ________ /*#include<stdio.

}*/ //______________________________________________________________________ ________ /*#include<stdio. case 2: printf("case2").i--) { printf("%d". } }*/ //______________________________________________________________________ ________ /*#include<stdio. break. if(str1==str2) printf("\nEqual").h> void main() { . } ++i.&i).h> void main() { int i.i=0. else printf("\nNot equal"). } }*/ //______________________________________________________________________ ________ /*#include<stdio. char str2[]="Hello". default: printf("Default").h> void main() { char str1[]="Hello".113 printf("case1"). for(i=2.

114 int i=5.h> void main() { int i=10. . struct person *addr. }*/ //______________________________________________________________________ ________ /*#include<stdio. char *age. }.h> #define HELLO "hi" void main() { printf("HELLO"). void main() { struct emp *e1. printf("%d". }*/ //______________________________________________________________________ ________ /*#include<stdio. char *c. printf ("%d".i=50). }. }*/ //______________________________________________________________________ ________ /*#include<stdio.sizeof(e1)). struct emp { int a. printf("%d ". ~i).h> struct person { char *name.

}*/ //______________________________________________________________________ ________ /*#include<stdio.h> void main() { int i. printf("%d ".p>=array. printf("%d".5.i).40.a[2][1]).115 }*/ //______________________________________________________________________ ________ /*#include<stdio.20.*p. }*/ //______________________________________________________________________ ________ /*#include<stdio.h> #define wipro main void wipro() { . //p=array+4 for(.6.8.h> void main() { int array[]={10.2.4. i=10/4.30.7. p=&array[0] + 4.h> void main() { int a[3][4]={1.3.50}. }*/ //______________________________________________________________________ ________ /*#include<stdio.p--) printf("%d ".*p).9}.

void main() { struct emp e1={1. }*/ //______________________________________________________________________ ________ /*#include<stdio. if(e1==e2) printf("\nstructures are equal"). What is the output of the following: unsigned i=32768. e2=&e1. else printf("\nstructures are not equal"). The size of long double is a.116 printf("main"). void main() . 10 Bytes c. }*/ //______________________________________________________________________ ________ 6. char name[15]. 8 bytes b. There is no datatype called long double. Ans::b 7. a+=1.h> struct emp { int i."hi"}.h> void main() { int a=10.*e2. }*/ //______________________________________________________________________ ________ /*#include<stdio. Compiler Dependent d. }.b=10. printf((a>b)?"hi":"hello").

i++) for (j=0. None of the above Ans::b 8.i). } e. printf("%s".j<5. } b. printf(“Wipro Technologies”). -32768 d.t). } void change(char *t) . Infinite loop d. change(t). 4 times b.i). char *t="test". 0 h. printf("%d".j--) { if (i==j) break. 3 f. Not predictable Ans::c 9. } a. None of the above Ans::a(3) 10. Error e.i<5. Error c. How many times Wipro Technologies printed in the following code: for(i=0. void main() { static int i=3.117 { printf("%d". Multiple declaration (since I is static) g. 32768 c. What is the output of the following: main() { void change(char *). What is the output of the following int i.

11 11 11 b. main() { int a=10.//valid printf(“%d %d %d”. #define c(a) a*a #define c(b) b+b void main() { printf(“%d”. Garbage value.a. 10 10 11 c. new test c. } char * fun() { char buffer[]=”Hello World”. } b.c(10)). d.*p. 100 .*q). None of the above Ans::c 6. } a. main() { char *fun().*q=p.fun()).*p=&a. test d. Error Garbage value//actaually 10 10 garbage Ans::c 12. } e. } a) hello world b) Compiler error c) Garbage Value d) None of the above ans::c//if static char buffer is used it would have worked 11. printf("%s". *q++.118 { char *ab="new test". return buffer. *t=*ab. nest e.

z=x++ . 6 c.n). x=5. int z. 400 h. . Error Ans::f 13. printf ("y = %s \n".b=2. void rec(int). void main() { rec(3).119 f. return (ptr). *y. 11 ans::c 10. char* myFunc (char *ptr) { ptr += 3. x = "HELLO". rec(--n). Error Ans::a 14. return 0. } void rec(int n) { if (n<=0) return. y = myFunc (x). Infinite loop d. y).a=4. 0 1 2 0 c. rec(n-1). What number will z in the sample code above contain? a. } int main() { char *x. 20 g. } a. printf(“%d”.y=-10. 1 2 1 3 1 2 1 b. 5 b.--y * b / a. 10 d.

case 3>2: printf("Hello"). break. 6 6 c.'l'. y = ELLO c.h> int i=0. What would be printed: #include<stdio. 5 6 Ans::c 13. a. char q[]={'h'.sizeof(q)).7["wipro infotech"). break. y = HELLO b.120 } What will print when the sample code above is executed? a. 5 5 b. default: printf("welcome"). printf("%d %d". Predict the output char p[]="hello". f b. y = LLO d. . What would be the output? void main() { printf("%s". void main() { while(i) { switch(i) { Case 3<2: printf("Hi"). Error Ans::b Garbage value //used as”wipro infotech”+7 12.'e'. Garbage value c. fotech d. } a.sizeof(p). y = LO Ans::d 11.'o'}.'l'. 6 5 d.

}. }.121 } ++i. pemp->a->city b. #include<stdio. struct emp { char name[20]. How will you access city from the *pemp.h> int get(). int empno. pemp->a. printf("%d ". struct emp *pemp. Hi c. Garbage . char street[5]. void main() { int x=20. } } b. struct addr { char city[5]. } int get() { return(60).x). pemp->*a. struct addr *a.*city d. Ans::a //rest invalid 15.city c. No output e. x=get(). All the above. Error Ans::c 14. Welcome d. } b. a. 60 c.

b=2. 11 0 30 c. void main() { int a=1.122 d. None of the above Ans::a 16.b=20. void main() { printf("Hi!"). What will be the output of the following program : void main() { printf("Hi!"). Error Ans::c 17.e. if !(0) printf("Bye"). } (a)No Output (b)Hi! (c)Bye Ans::d 20. Error e.a.e).c=30. } a. 11 20 30 d.c). } (a)Compile-Time error (b)Hi! (c)Bye Bye Ans::a 19.d=4. a++ || b-20 && ++c. void main() { printf("Hi!").c=3. if (-1) printf("Bye"). if (e=(a & b | c ^ d)) printf("%d". 11 20 31 b. printf("%d %d %d". What would be the out put of the following void main() { int a=10. if (-1+1+1+1-1-1-1+(-1)-(-1)) printf("Bye"). } (a)No Output (b)Hi! (c)Bye Ans::d 18.b. (d)Hi!Bye (d)Hi! (d)Hi!Bye .

for (i=0.1.3 (b)Compile-Time Error (c)Run-Time Error (d)No Output Ans::a 24. printf("Again"). i+=0.10.4.1f".1) printf("%. main() { int a=1.123 } (a)0 (b)7 (c)3 (d)No Output Nas:: 21.i). struct yy { char s. if (a) printf("Test").a).//name sud be given…. void main() { printf("%d". }. i<0. struct xx *p. void main() { float i. else. } (a)0. auto int a=5. . struct yy *q.Point out the error if any #include<stdio. } (a)Compile-Time error (b)Run-Time error (c)5 (d)Unpredictable Ans::a//auto cannot be declared outside any fuction 22. } (a)Again (b)Test (c)Compile-Time Error (d)TestAgain Ans::b 23.20.h> main() { struct xx { int x.

What will be the output of the following program ? #include<stdio. c = a = = b. a) 0 b) error c) 1 d) garbage value ans::error//= = would not work == will do 27.124 }. c.h> #include<math. printf("%d".4 }.5. What will be the output of the following statements ? int a[2][2] = { 3. Compile time error Run time error No error.2. Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above Ans::4 26.*(*(*(a)))). Which of the functions is most apt for reading a multi-word ? a) puts() b) gets() c) scanf() d) vsscanf() Ans::b 29. printf("%i". } a. a) error b) 3 c) garbage value d) 2 Ans::a 28.c.c). Predict the output int a = 4. b. b = 7. Compiler dependent ans::a 5. d.h> .

.h> void main() { printf("%d"). printf("Enter 2 numbers\n"). #include<stdio.h> void main() { int a = 36. } a) 300 b) 324 c) 32489 d) 89 Ans::324 30. #include<stdio.a>>a/b-2).&b). b = 9.&a.n). char *str = "324. } a) 9 b) 7 c) 5 d) none of these Ans::a 32.b. } a) error b) no output c) %d d) 0 Ans::d 31. #include<stdio. else printf("B is less than A").int).h> void main() { int a. printf("%d". printf("%d".89". n = atoi(str).int y) { if (x<y) printf("A is less than B"'). scanf("%d %d".125 void main() { int n. } void small(int x. void small(int.

126 } If a=10, b=10 What is the output a. B is less than A b. A is less than B c. Error d. No output Ans::d 33. swap(int *a,int *b) { int *t; t=a; a=b; b=t; } void main() { int a=10,b=20; swap(&a,&b); printf(“%d %d”,a,b); } b. 10 20 c. 20 10 d. Error e. Garbage value Ans::a 34. main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*++p; printf("%s %s",p,p1); } a. ibj!gsjfoet b. hbj!gsjfoet c. hbj!gsjfoet hbj!gsjfoet d. None of the above Ans::d//abnormal program termination 35. main( ) { char *q; int j;

127 for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); } If the input given are Wipro Technologies Chennai What will be the output a. WTChennai TChennai Chennai b. Chennai Chennai Chennai c. Wipro Technologies Chennai d. None of the above Ans::d 36. main() { int i, n; char *x = “OOAD”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } } a. OOAD OAD AD b. OAD AD D c. No output d. None of the above Ans::b 37. #define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE");

128 } a. TRUE b. FALSE c. TRUE FALSE d. Error Ans::a 38. main() { int i=5,j=6,z; printf("%d",i---j); } a. -1 b. Error c. 0 d. None of the above Ans::a 39. main() { char *p; int *q; long *r; p=0; q=0; r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); } a. 0001 0002 0004 b. 0000:0001 0000:0002 0000:0004 c. 1 2 4 d. Error Ans::a//inc by their type value in p,q r set to zero 40. # include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye");

129 } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; (*ptr)(); } a. hi b. hello c. bye d. Error Ans::hi 1) Which of the following is a compound assignment statement? a)a=b b) a=b=c c) a+=b d) a=b;b=c; ans::c 2) given that the file is being read using fgetc command,as ch =fgetc(fp),then what is the condition to check for the end of the file a) ch!=EOF b) ch!=NULL c) ch==NULL d) ch=='\0' ans::a 3) which of the following accepts only the specified number of characters from a file a) fgets b) fread c) fputc d) fputs ans::a 4) which of the following is the best for getting a string with space from the standard input a) gets b) getc c) fgets d) puts ans::fgets//gets 5)how to represent a character pointer named 'message' pointing to the array"hello" a) char message="hello" b) char message[ ]="hello" a) char *message="hello"

130 a) char *message[ ]="hello" ans::c 6) which data structure is best for searching an element in the given list a) arrays b) single linked list c) doubly linked list d) binary search trees ans::d 7) assume that integer is 4 bytes,pointer as 4 byter and character as 1 byte,then predict the output struct student { int a; char name[10]; int *p; }s1,*s2; printf("%d%d",sizeof(s1),sizeof(*s2)); a) 18,18 b)18,4 c) 4,18 d) 4,4 ans::a 8) what would the statement strcmp("Astring","Astring"); return? a) 0 b) <1 c)>1 d) -1 ans::a 9) which statement is used to compare the two strings ? a) strcmp b)strcompare c) stringcompare d) str_cmp ans::a 10) int fun(int x) { int y=55; return((x-y)?y:x); } main() { int a=20; fun(a); printf("%d",y); }

131

ans::error 11) main() { static int a[10]={1,2,3,4,5}; int i; for(i=0;i<10;i++) printf("%d ",a[i]); } ans::1 2 3 4 5 0 0 0 0 0 12) main() { char *y; y=x(); printf("%s",y); } char *x() { char result[ ]="Hello"; strcpy(result,"anything good"); return result; } ans::buffer die after function get lost 13) The post order is 5,20,10.what will be the inorder? A)5,10,20 b) 20,5,10 c) 20,10,5 d) none of the above ans::a 14) int fact(int x) { ?????? return(x*fact(x-1)); } main() { fact(5); } what would be replaced in terms of ??????? a) if(x==0) return 0; b) if(x==1) return 1; c) if(x==2) return 2; d) none of the above ans::b

132 15) Allocating a 2 blocks of memory for 'n' intgers is by using a) malloc b) calloc c) both malloc and calloc d) none of the above ans::b 16) In queue using linked list, which is correct? a) both insertion and deltionis made at the front end b) insertion is made at the beginning and deletion is made at the last c) insertion is made at the last and deletion is made at the beginning d) both insertion and deltionis made at the back end ans::c 17) main() { int i=10; printf("%d",i==10); } ans::1 18) main() { char c='p'; printf("%c",c); } ans::p 19) main() { int i=0; while(i<3) { switch(i) { case 3>2: printf("case1"): break; case 3<2: printf("case2"); break; defalut: printf("default"); break; } i++; } ans::case2case1 20) which is correct?

133 a) unsigned char short b) unsigned short char c) short unsigned char d)noneof the above ans::b 21) void fun(char *str) { char *str1="hai"; str=str1; } main() { char *str="Hello"; fun(str); printf("%s",str); } ans::hello 22) struct city { char *name[20]; int age; }*s; how to allocatethe memory for the member 'name'? s->name[]=(char*) 23) what is the header file to be included for doing mathematical calculations? 24) what is the way to declare a float pointer? float *f; 25) what kind of error does the syntax error is? 26) float fun( f1) { return(f1*f1); } main() { float f1=3.25; fun(f1); printf("%f",f1); } ans::3.25//also f1 will take int value only 27) for(i=0;i<2;i++) { for(j=0;j<5;j++) {

134 if(i==j) break; printf("wipro"); } } how many times would wipro to be printed? ans::wipro will be printed only one times. 28) main() { FILE *fp; char data[100]; printf("Enter the file name"); gets(data); ???? fclose(fp); } fp=fopen(data,"r"); what would be replaced for ???? to open a file in a read mode 29) main() { int 5[a]={10,20,30,40,50}; int *p; p=a[2]; printf("%d",2[a]); } error 30) which of these isn an infinite loop i) for(;;); ii)for(i=1;;i++); iii) for(i=0;i<=5;i++) { --i;} a) i,ii only b) i only c)all the three d) none of the above ans::c 31)which of these is replaced by a switch block? a) while loop b) do while c) for loop d)else if

?

135

32) void disp(char *string) { printf("%d\n",string); printf("%s\n",string); } void main() { char string[ ]="Hello world"; printf("%d\n",string); disp(string); } 33) char *gxxx() { static char x[1024]; printf("%s\n",x); return x; } void main() { char *g="string"; strcpy(gxxx(),g); g=gxxx(); strcpy(g,"old string"); printf("%s\n",gxxx()); } ans::old string 34) main() { char s[ ]="\12345s\n"; printf("%d\n",sizeof(str)); } ans::6 35) main() { char *k[ ]={" Good Morning","Good Evening","Good night"}; printf("%s\n",k[0]); printf("%s\n",*(k+1)); } ans::Good Morning Good Evening 36) which one of the following is incorrect? a) signed char a;

136 b)char signed a; c) char a signed; d) none of the above ans::c 37) all the local variables are stored in ----------------a) stack b) heap c) queue d) none ans::a 38) Once you call a function,all the return addresses are stored in ---------------a) stack b) heap c) queue d) none ans::a 39) Which of the following is true about binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. a) i only b)ii only c) both i and ii d) neither i nor ii ans::b 40) Which of the following is true about complete binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. a) i only b)ii only c) both i and ii d) neither i nor ii ans::c 41) struct node { int data; struct node *left,*right; }; suppose start and end are the pointers pointing to the beginning and ending node reapectively.then, what will be the output of the following snippet front=start; back=end; while(back!=NULL) { printf("%d",back->data);

137 back=back->left; } reverse printing 42) struct node { int data; struct node *left,*right; }; suppose start and end are the pointers pointing to the beginning and ending node reapectively.then,what will be the output of the following snippet front=start; back=end; while((front!=back)&&(back->left!=front)) { temp=front->data; front->data=back->data; back->data=temp; } 43) the declaration of the pinter to an array ofint having the name iptr is ------------------a) int *iptr b) int &iptr c) int *&iptr d)iptr *int ans::a 44) int one_d={0,1,2}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); } ans::error 45) struct a { char *b; char *c; char *d; }; struct e { char *f;

}.b=4. p=x*y*z. }abc.c). printf("%d".sizeof(abc)). printf("%d". meq(). struct a g. void main() { printf("Hai"). prod(a.c=5. }abc. } meq() { . printf("Hello"). } void main() { int a=3. char *c. ans::4 46) struct a { char *b.p).int y. } 49) int meq().138 struct a *g. char *d.sizeof(abc)). } ans::main 48) void prod(int x.int z) { int p. printf("%d". struct e { char *f. ans::8 47)#define wipro main wipro() { printf("main").b.

i). char q[ ]={'w'. sptr=ptr+5.'c'.*sptr).'e'}.'m'. syntax error is generated by --------------------a) compiler b) Interpreter C) linker d) none 54) char *ptr="Madam".sptr).sizeof(*p). } ans::0 . char *sptr=ptr+4.139 printf("Bye"). printf("%d %d". while(sptr>=ptr) { printf("%c". ans::fgh 52) If the integer occupies 2 bytes then short int will take how many bytes? 53) In C. sptr--.'o'. i=10/20.'l'. } ans::11 50) The size of the doubly linked list is always greater than the single linked list a) true b) false 51) char *ptr="abcdefgh".'e'. } ans::HaiByeHello 49) void main() { char *p="welcome". } ans::madaM 55) void main() { int i. char *sptr.sizeof(*q)). printf("%s". printf("%d".

} . for(m=0. printf("%d". a[1]=&j.m++) printf("%d". a[3]=&l. for(i=0.m<4.l=40.i). } ans::3020 59) void fun().i<10.i). main() { fun(). } ans::10 58) int i=10. a[2]=&k. int *a[4].*a[m]).j=20.k=30.140 56) The arguments in a function call is known as --------------------a) formal arguments b) actual arguments 57) main() { int i.m. } void fun() { printf("good"). main() { int i=20.i++). printf("%d". } ans::good 60) void main() { int i=10. { int i=30. } printf("%d". a[0]=&i.i).

*p).  Program is compiled using Turbo C/C++ compiler. printf("%s". It is assumed that. The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).141 ans::10203040 61) if the insertion is made only at the beginning then which data structure is used a) array b) stack c) queue d) linked list 62) to access the 4th element in the array 'num' we need ------------a) num[4] b) num[1] c)num[3] d) none of the above 63) void main() { char *a[ ]={"Dharma". char **ptr=a.++*p). } ans::harmaharmaHewlett packard 64) C Questions Note : All the programs are tested under Turbo C/C++ compilers."Hewlett packard".  The underlying machine is an x86 system."ibm"}. Predict the output or error(s) for the following: 1.*p++)."New city". void main() . printf("%s". printf("%s".  Programs run under DOS environment.

i[s]).142 { int const * p=5. >. So. . *(i+s). double. >=. <. i[s] may be surprising. int i.++(*p)). <=. the precession with of the value represented varies. But in the case of C it is same as s[i].i++) printf("\n%c%c%c%c". if(me==you) printf("I love U"). *(s+i). 2.9 with less precision than long double. But we tried to change the value of the "constant integer".1. Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== . indirecting it with * is same as s[i]. So float stores 0.*(i+s). long double) the values cannot be predicted exactly. } Answer: I hate U Explanation: For floating point numbers (float. printf("%d". main() { char s[ ]="man". Here s is the base address. Explanation: p is a pointer to a "constant integer". 3. main() { float me = 1.1.s[ i ]. i[s] are all different ways of expressing the same idea.!= ) . i is the index number/displacement from the base address. else printf("I hate U").s[ i ]. Generally array name is the base address for that array.*(s+i). double you = 1. } Answer: Compiler error: Cannot modify a constant value. Depending on the number of bytes. for(i=0. Float takes 4 bytes and long double takes 10 bytes. } Answer: mmmm aaaa nnnn Explanation: s[i].

7. main() { extern int i. int j.i). it is initialized once. . In second loop p itself is incremented.*c). In the first loop. i=20. printf("%d". } Answer: 54321 Explanation: When static storage class is given. Main is also treated like any other ordinary function. which can be called recursively.6.8. ++p.143 4.5}. extern int i. 6. The change in the value of a static variable is retained even between the function calls.*p=c.j<5.j++) { printf(" %d ".4. } Answer: Linker Error : Undefined symbol '_i' Explanation: extern storage class in the following declaration. the value 2 will be printed 5 times.var--). } for(j=0. if(var) main().4. since only q is incremented and not c .*q=c.j<5. main() { static int var = 5.j++){ printf(" %d ". 5.3. main() { int c[ ]={2. ++q. printf("%d ". So the values 2 3 4 6 5 will be printed. } } Answer: 2222223465 Explanation: Initially pointer c is assigned to both p and q. for(j=0.*p).

sizeof(p)). And also the logical AND (&&) operator has higher priority over the logical OR (||) operator.i. } Answer: 00131 Explanation : Logical operations always give a result of 1 or 0 . break. m=i++&&j++&&k++||l++.m). 9. So the value of m is 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.l. printf("%d %d ".sizeof(*p). Hence sizeof(*p) gives a value of 1.m. } Answer: 12 Explanation: The sizeof() operator gives the number of bytes taken by its operand. switch(i) { default:printf("zero"). main() { int i=-1.k. main() { int i=3. 8. case 3: printf("three"). printf("%d %d %d %d %d".l=2.j=-1. So the expression ‘i++ && j++ && k++’ is executed first. break. main() { char *p. 7. which needs one byte for storing its value (a character). case 2:printf("two"). But linker finds that no other variable of name i is available in any other program with memory space allocated for it. P is a character pointer. The result of this expression is 0 (1 && -1 && 0 = 0). . Hence a linker error has occurred . The values of other variables are also incremented by 1.144 specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking.k=0.for which it gives 0). case 1: printf("one"). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination.j.

the compiler doesn't know anything about the function display. 11. } Answer: fff0 Explanation : -1 is internally represented as all 1's.c).string).145 break. It is executed only when all other cases doesn't match. } Answer: Compiler Error : Type mismatch in redeclaration of function display Explanation : In third line. } Answer: c=2.-1<<4). main() { printf("%x". Hence a compile time error occurs. printf("c=%d". the arguments and type contradicts with what it has assumed previously. main() { char string[]="Hello World".The %x format specifier specifies that the integer value be printed as a hexadecimal value. when the function display is encountered.-2. (which is the default type). It assumes the arguments and return types to be integers. When left shifted four times the least significant 4 bits are filled with 0's. When it sees the actual function display. 10. 12. } } Answer : three Explanation : The default case can be placed anywhere inside the loop. Explanation: . display(string). } void display(char *string) { printf("%s". main() { int c=.

str1=s.operator can only be applied to variables as a decrement operator (eg. ! is a unary logical operator. 13.++*p + ++*str1-32). 0>14 is false (zero).'\0'}.'\n'. str=p. Because -. } Answer: i=0 Explanation: In the expression !i>14 . main() { int i=10. !i (!10) is 0 (not of true is false). 15. Printf ("i=%d". p=&s[3]. #include<stdio. printf("sizeof(i)=%d". ie.h> main() { char s[]={'a'. char *p. 2 is a constant and not a variable. } Answer: 77 Explanation: .*str1. #define int char main() { int i=65.*str.. } Answer: sizeof(i)=1 Explanation: Since the #define replaces the string int by the macro char 14. Note: However you cannot give like --2.sizeof(i)). minus * minus= plus.'c'.'b'. i--). i=!i>14. printf("%d". Same maths rules applies.146 Here unary minus (or negation) operator is used twice.i).'c'. NOT (!) operator has more precedence than ‘ >’ symbol.

h> main() { struct xx { .6. p=&a[2][2][2]. ASCII value of 'b' is 98.147 p is pointing to character '\n'. {5. So we get the output 77 :: "M" (Ascii is 77). which is then incremented to 11. *q=***a starting address of a is assigned integer pointer. str1 is pointing to character 'a' ++*p.h> main() { int a[2][2][2] = { {10. } Answer: Compiler Error Explanation: You should not initialize variables in declaration 18. "p is pointing to '\n' and that is incremented by one. ++*str1. } Answer: SomeGarbageValue---1 Explanation: p=&a[2][2][2] you declare only two 2D arrays." the ASCII value of '\n' is 10. 17.*q). #include<stdio.4}.3.7.h> main() { struct xx { int x=3.8} }. but you are trying to access the third 2D(which you are not declared) it will print garbage values. The value of ++*p is 11. int *p. Now performing (11 + 98 – 32). printf("%d". }. #include<stdio. #include<stdio. we get 77("M").s->name).*p. 16. If you print *q. *q=***a. printf("%s". it will print first element of 3D array. struct xx *s. str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'.*q. char name[]="hello". Now q is pointing to starting address of a.s->x). printf("%d----%d".2.

i++. main() { printf("\nab").linefeed 20. } Answer: Compiler Error Explanation: The structure yy is nested within structure xx. The evaluation is by popping out from the stack. Hence for nested structure yy you have to declare member. 19. Hence. printf("\rha").i). hence the result. the elements are of yy are to be accessed through the instance of structure xx. printf("\bsi"). struct xx *p. struct yy { char s. #define square(x) x*x main() { . main() { int i=5. and the evaluation is from right to left. } Answer: 45545 Explanation: The arguments in a function call are pushed into the stack from left to right.newline \b . }. struct yy *q. 21. printf("%d%d%d%d%d%d". which needs an instance of yy to be known.++i.i--. } Answer: hai Explanation: \n .backspace \r .--i. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. }.148 int x.

we obtain value in p becomes “ibj! gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything. while(*p!='\0') ++*p++. ‘a’ which is similarly changed to ‘b’ and so on. 24. in the while loop initial value pointed by p is ‘h’.149 int i. main() { char *p="hai friends". Similarly blank space is converted to ‘!’. So the most recently assigned value will be taken. p1=p. 16*4 = 64 22. which is changed to ‘i’ by executing ++*p and pointer moves to point. #include <stdio.*p1.e. printf("%s %s". } Answer: 50 Explanation: The preprocessor directives can be redefined anywhere in the program. Since / and * has equal priority the expression will be evaluated as (64/4)*4 i. Thus. i = 64/square(4). is encountered the location will be incremented that is p++ will be executed Hence.p. #define clrscr() 100 main() { .h> #define a 10 main() { #define a 50 printf("%d". 23. } Answer: 64 Explanation: the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . } Answer: ibj!gsjfoet Explanation: ++*p++ will be parse in the given order  *p that is value at the location currently pointed by p will be taken  ++*p the retrieved value will be incremented  when .p1). printf("%d".i).a).

is a function declaration (because it is not inside any function). 28) enum colors {BLACK. main() is also a function.main).100). } clrscr().The input program to compiler looks like this : main() { 100. So it doesn't give any problem 25. So the address of function main will be printed.150 clrscr().clrscr()). printf("%d\n".GREEN} main() { . 27) main() { clrscr(). } Answer: Some address will be printed. Answer: No output/error Explanation: The first clrscr() occurs inside a function. So it becomes a function call. } Answer: 100 Explanation: Preprocessor executes as a seperate pass before the execution of the compiler. main() { printf("%p". } Note: 100. %p in printf specifies that the argument is an address. So textual replacement of clrscr() to 100 occurs.BLUE. printf("%d\n". Explanation: Function names are just addresses (just like array names are addresses). They are printed as hexadecimal numbers. In the second clrscr(). is an executable statement but with no action.

If more number of assignments given in the program. All of them take only the first two values.BLACK.. } Answer: 400.GREEN).sizeof(farther).sizeof(farthest)). They can be applied any number of times provided it is meaningful.2 Explanation: the second pointer is of char type and not a far pointer 30) main() { int i=400.%d". return(1). } Answer: H Explanation: * is a dereference operator & is a reference operator.%d".. printf("%d.then printf will take garbage values.. Here p points to the first character in the string "Hello".151 printf("%d.300 Explanation: printf takes the values of the first two assignments of the program.1. main() { char *p. *p dereferences it and so its value 31) .2 Explanation: enum assigns numbers starting from 0.*&*p).%d"). Any number of printf's may be given.%d.j=300. } Answer: 4... p="Hello"....*farthest. printf("%c\n".BLUE. } Answer: 0. printf("%d. 29) void main() { char far *farther. if not explicitly defined.

} } fun() { here: printf("PP"). printf("%d". int i. } Answer: Compiler error: Undefined label 'here' in function main Explanation: Labels have functions scope. void main() { int i=5.i<=4. main() { static char names[5][20]={"pascal". } Answer: Compiler error: Lvalue required in function main Explanation: Array names are pointer constants.names[i]). char *t."perl"}. 32) main() { int i=1. for (i=0.i). 33) 34) . So it cannot be modified. i++."fortran". while (i<=5) { printf("%d". if (i>2) goto here."cobol". names[3]=names[4].i++) printf("%s". in other words The scope of the labels is limited to functions ."ada". The label 'here' is available in function fun() Hence it is not visible in function main.i++ + ++i). names[4]=t. Again & references it to an address and * dereferences it to the value H. t=names[3].152 is H.

#include<stdio. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).j=2. main() { int i. // value 10 is given as input here } Answer: 1 Explanation: 36) 37) .i+++++i). } } Answer: Compiler Error: Constant expression required in function main. case j: printf("BAD"). switch(i) { case 1: printf("GOOD").&i)).153 } Answer: Output Cannot be predicted exactly. Note: Enumerated types can be used in case statements. break. Explanation: Side effects are involved in the evaluation of i 35) void main() { int i=5. printf("%d".scanf("%d". } Answer: Compiler Error Explanation: The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators. break.h> main() { int i=1. printf("%d".

printf("%d". printf("%d".'\0'}.'c'. char *p. and i is incremented (note the semicolon after the for loop).h> main() { char s[]={'a'.*str.i)) . 38) #define f(g." the ASCII value of '\n' is 10. Here 10 is given as input which should have been scanned successfully. printf("%d".i++. ASCII value of 'b' is 98. 40) #include<stdio. then it is incremented to 11. the value of ++*p is 11.++*p + ++*str1-32). Here it evaluates to 0 (false) and comes out of the loop.f(var. both 11 and 98 is added and result is subtracted from 32.12)). printf("%d".'b'. } Answer: M Explanation: p is pointing to character '\n'.i). str1=s.'\n'.*str1.str1 is pointing to character 'a' ++*p meAnswer:"p is pointing to '\n' and that is incremented by one.'c'.154 Scanf returns number of items successfully read and not 1/0. } Answer: 1 Explanation: before entering into the for loop the checking condition is "evaluated". } Answer: 100 main() { int i=0.g2) g##g2 main() { int var12=100. + +*str1 meAnswer:"str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. 39) . str=p. p=&s[3]. So number of items read is 1. for(.

printf("%s". } Answer: Compiler Error Explanation: Initialization should not be done for structure members inside the structure declaration #include<stdio.h> main() { struct xx { int x=3. }. } Answer: 42) 43) . i=20.h> main() { struct xx { int x. main() { extern int i. struct yy { char s. } Answer: Compiler Error Explanation: in the end of nested structure yy a member have to be declared. }.sizeof(i)). (11+98-32)=77("M").155 i. printf("%d". }.e. char name[]="hello". struct xx *s=malloc(sizeof(struct xx)). 41) #include<stdio. printf("%d".s->x). struct yy *q. struct xx *p.s->name).

156 Linker error: undefined symbol '_i'. printf("%d". } Answer: Compier error: Type mismatch in redeclaration of show. Hence the error. out). The solutions are as follows: 45) 46) . Explanation: When the compiler sees the function show it doesn't know anything about it. So compiler doesn't find an error. During linking the linker searches for the definition of i. out). Even though a is a global variable. Answer: Compiler error: undefined symbol out in function main. Answer: 100 Explanation: This is the correct way of writing the previous program. main() { show(). Explanation: The rule is that a variable is available for use from the point of declaration. Since it is not found the linker flags an error. } int out=100. Hence an error. int) is assumed. So the default return type (ie. } int out=100. The compiler passes the external variable to be resolved by the linker. main() { extern out. 44) main() { printf("%d". Explanation: extern declaration specifies that the variable i is defined somewhere else. But when compiler sees the actual definition of show mismatch occurs since it is declared as void. it is not available for main. } void show() { printf("I'm the greatest").

It can also be viewed as a 1-D array. **a +1 increments the first dimension thus points to 102 and ***a+1 first gets the value at first location and then increments it by 1. } p = a. for the first printf statement a.{7. .30. 100. 100.4}}}. 2. } Answer: 100.50}.40. j<5.*a).*a+1.{3. the first line of the output. 2 4 7 8 3 4 2 2 2 3 3 4 100 102 104 106 108 110 112 114 116 118 120 122 thus.a.{3. j++) { printf(“%d ” . 47) main( ) { int a[2][3][2] = {{{2. declare void show() in main() . printf(“%u %u %u %d \n”.***a).157 1. } } Answer: Compiler error: lvalue required. for the second printf a+1 increases in the third dimension thus points to value at 114. 102.a+1. 3.*p). for(j=0. j<5.{2. j++) { printf(“%d” .20. 2 114.**a. Hence. printf(“%u %u %u %d \n”. *a+1 increments in second dimension thus points to 104. the output. define show() before main().4}. **a give address of first element . p++.8}. 3 Explanation: The given array is a 3-D one. for(j=0. a++. Hence.***a+1).*p.j.3}.4}}. declare extern void show() before the use of show().*a. 104.2}.**a+1.{{2. since the indirection ***a gives the value. *a. 48) main( ) { int a[ ] = {10.

so it becomes1004. . **ptr = 2. **ptr). *ptr-a. ++*ptr. Now ptr – p is value in ptr – starting location of array p. } Answer: 111 222 333 344 Explanation: Let us consider the array and the two pointers with some address a 0 1 2 3 4 100 102 104 106 108 p 100 102 104 106 108 1000 1002 1004 1006 1008 ptr 1000 2000 After execution of the instruction ptr++ value in ptr becomes 1002.a+4}.a+2. int *p[ ] = {a. ptr-p.1. int **ptr = p. if scaling factor for integer is 2 bytes. 1. array name only when subscripted is an lvalue. printf(“\n %d %d %d”. *++ptr. **ptr). ptr++. 1. **ptr is the value stored in the location pointed by the pointer of ptr = value pointed by value pointed by 1002 = value pointed by 102 = 1. ptr-p. **ptr). the outputs for the second printf are ptr – p = 2. (1002 – 1000) / (scaling factor) = 1. **ptr).4}. *ptr-a. 49) main( ) { static int a[ ] = {0.a+1. *ptr-a.2.a+3. *ptr++.3. ptr-p. The operand must be an lvalue and may be of any of scalar type for the any operator. 1002 has a value 102 so the value is (102 – 100)/(scaling factor) = 1. ptr-p.158 Explanation: Error is in line with statement a++. Hence. *ptr – a = 2. After execution of *ptr++ increments value of the value in ptr by scaling factor. printf(“\n %d %d %d”. printf(“\n %d %d %d”. Simply array name is a non-modifiable lvalue. Hence the output of the firs printf is 1. printf(“\n %d %d %d”. *ptr-a. *ptr – a = value at address pointed by ptr – starting value of array a.

j++) scanf(“%s” . q+1. the outputs for the third printf are ptr – p = 3.*(q+j)). Hence. Suppose the inputs are MOUSE.*(int *)vp). **ptr = 4. *ptr – a = 3. *ptr – a = 108 – 100 = 4. vp = &j. } Answer: . TRACK and VIRTUAL. j++) printf(“%c” . j<3. After execution of ++*ptr value in ptr remains the same. q+2 i. q+1 and q+2 = M T V The second printf prints three strings starting from locations q. 51) main( ) { void *vp. Hence. j<3.(char *)vp + 3). vp = cp. **ptr = 3. so it becomes1004. for (j=0.159 After execution of *++ptr increments value of the value in ptr by scaling factor. *cp = “goofy”. So the value in array p at location 1006 changes from 106 10 108. int j = 20. the outputs for the fourth printf are ptr – p = 1006 – 1000 = 3. 50) main( ) { char *q. for (j=0.e MTVIRTUAL. int j. j<3. The first printf prints the values at the position q. } Explanation: Here we have only one pointer to type char and since we take input in the same pointer thus we keep writing over in the same location. each time shifting the pointer value by 1. so the input is filled in memory starting from 101. *(char *)vp). char ch = ‘g’. printf(“%s”. printf(“%d”. printf(“%c”. Then for the first input suppose the pointer starts at location 100 then the input one is stored as M O U S E \0 When the second input is given the pointer is incremented as j value becomes 1. the value pointed by the value is incremented by the scaling factor.(q+j)). vp = &ch.. j++) printf(“%s” . for (j=0. TVIRTUAL and VIRTUAL. M T R A C K \0 The third input starts filling from the location 102 M T V I R T U A L \0 This is the final value stored .(q+j)).

s+2. s}. “yellow”. “violet”}. char *x = “girl”. n = strlen(x). “white”. for(i=0. i<n. } } Answer: (blank space) irl rl 53) . n. } Answer: ck Explanation: In this problem we have an array of char pointers pointing to start of 4 strings. the indirection operator now gets the value from the array of s and adds 3 to the starting address. the output is ‘ck’. thus now value of p = s+2. char **ptr[ ] = {s+3. p = ptr. 52) main ( ) { static char *s[ ] = {“black”. p = s+3.x). The string is printed starting from this position. Similarly the output from second printf is ‘20’. The third printf statement type casts it to print the string from the 4 th value hence the output is ‘fy’. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. ++i) { printf(“%s\n”. i. vp = &ch stores address of char ch and the next statement prints the value stored in vp after type casting it to the proper data type pointer. the output is ‘g’. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . ***p. p hold the initial value of ptr. main() { int i. *x = x[n]. printf(“%s”. x++. The next statement increment value in p by 1 .e.*--*++p + 3). s+1.160 g20fy Explanation: Since a void pointer is used it can be type casted to any other type pointer. Thus. **++p.

for(i=0.i<=10.standard error). What are the files which are automatically opened when a C file is executed? Answer: stdin. If assertion fails. +i = -1 Explanation: Unary + is the only dummy operator in C. Now the printf statement prints the string after each iteration it increments it starting position. The next statement assigns value at the nth location (‘\0’) to the first location. 54) 55) 56) 57) what will be the position of the file marker? . stdout.<line number> Explanation: asserts are used during debugging to make sure that certain conditions are satisfied. int i. #undef NDEBUG and this will disable all the assertions from the source code. } Answer: i = -1. +i = %d \n". Assertion is a good debugging tool to make use of. After debugging use. } Answer: Runtime error: Abnormal program termination. Now the string becomes “\0irl” . stderr (standard input. the program will terminate reporting the same. +i. printf("i = %d. assert failed (i<5). <file name>.standard output.i. thus n has a value 4. Loop starts from 0 to 4.j.e “irl” and the third time it prints “rl” and the last time it prints “l” and the loop terminates. main() { int i=-1. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator). The first time x[0] = ‘\0’ hence it prints nothing and pointer value is incremented.161 l Explanation: Here a string (a pointer to char) is initialized with a value “girl”. The second time it prints from x[1] i. The strlen function returns the length of the string.+i). assert(i<5).i++) { j+=5.

What is the problem with the following code segment? while ((fgets(receiving array.0.0.c. So the correct end of file check is checking for != NULL. Explanation: main function calls itself again and again. the call stack overflows at runtime.v.s[12].s).162 a: fseek(ptr. scanf(" \"%[^\"]\"".file_ptr)) != EOF) . } Answer: Runtime error : Stack overflow. vptr=&v. c=10.v).SEEK_CUR). main() { main(). Answer & Explanation: fgets returns a pointer. cptr=&c.SEEK_SET).50. printf("%c%v". } How scanf will execute? Answer: First it checks for the leading white space and discards it. b: The SEEK_CUR sets the file position marker to the current position of the file. Since there is no condition to terminate the function call. } 59) 60) 61) . b: fseek(ptr. void *vptr. Each time the function is called its return address is stored in the call stack. Answer : a: The SEEK_SET sets the file position marker to the starting of the file. main() { char *cptr. 58) main() { char name[10].Then it matches with a quotation mark and then it reads all character upto another quotation mark. v=0.c. So it terminates the program and results in an error.

} Answer: 0 Explanation: ! is a logical operator. str1 is a character pointer so it gives you the size of the pointer variable. else puts("FALSE"). main() { char not. 62) main() { char *str1="abcd".not). In second sizeof the name str2 indicates the name of the array whose size is 5 (including the '\0' termination character). else if(FALSE) puts("TRUE"). } Answer: 255 Explanation: In first sizeof. not=!2.sizeof(str1). Here 2 is a non-zero value so TRUE. and any non-zero value is considered to be the boolean value TRUE. printf("%d". #define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"). In the second line you are creating variable vptr of type void * and v of type void hence an error. Explanation: You can create a variable of type void * but not of type void. char str2[]="abcd".sizeof(str2).163 Answer: Compiler error (at line number 4): size of v is Unknown. In C the value 0 is considered to be the boolean value FALSE. } 63) 64) . printf("%d %d %d". !TRUE is FALSE (0) so it prints 0. The third sizeof is similar to the second one.sizeof("abcd")). since void is an empty type.

The check by if condition is boolean value false so it goes to else. else printf("%d is not a leap year"). In second if -1 is boolean value true hence "TRUE" is printed. } Preprocessor doesn't replace the values given inside the double quotes. else if(-1) puts("TRUE"). printf("%d==1 is ""%s".k. } Answer: 2000 is a leap year Explanation: An ordinary program to check if leap year or not. else puts("FALSE"). So the string is as if it is given as "%d==1 is %s".164 Answer: TRUE Explanation: The input program to the compiler after processing by the preprocessor is.&y). The conditional operator( ?: ) evaluates to "TRUE".k==1?"TRUE":"FALSE"). main() { int y. main(){ if(0) puts("NULL"). } Answer: 1==1 is TRUE Explanation: When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). scanf("%d". // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"). #define max 5 #define int arr1[max] main() 66) 67) . 65) main() { int k=1.

2. const volatile unsigned which is a valid declaration.10 Explanation: '{' introduces new block and thus new scope.3.4}) Explanation: arr2 is declared of type array of size 5 of characters.name). After compilation is over the linker resolves it to global variable i (since it is the only variable visible there). } printf("%d". Rule of Thumb: #defines are used for textual replacement whereas typedefs are used for declaring new types. Hence an error. printf("%d %s". In the innermost block i is declared as.list[0]. So it can be used to declare the variable name of the type arr2.4}. } printf("%d".i).1. In the outermost block.165 { typedef char arr2[max].1. { 69) . But it is not the case of arr1. arr2 name="name". { const volatile unsigned i=30. 68) int i=10. i is assumed of type int. So printf prints 30. } Answer: 30. main() { int *j. arr1 list={0. main() { extern int i. { int i=20.i).20.3. So it prints i's value as 10. i has value 20 and so printf prints 20. In the next block.i).2. so no storage space is allocated for it. printf("%d". } Answer: Compiler error (in the line arr1 list = {0. i is declared as extern.

2. } Answer: Compiler error Explanation: i is a constant.h> main() { int a[2][2][2] = { {10. Since the i is still allocated space.8} }.h> main() { const int i=4. *q=***a. int *p.*q. #include<stdio. } printf("%d". you cannot change the value of constant #include<stdio.-i).6. -i = 1 Explanation: -i is executed and this execution doesn't affect the value of i. } Answer: 10 Explanation: The variable i is a block level variable and the visibility is inside that block only. } Answer: i = -1. printf("i = %d.++j).7.3. 70) main() { int i=-1. {5. *j prints the value stored in i since j points i.4}. After that the value of the expression -i = -(-1) is printed.*j). j=&i.166 int i=10. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. i. In printf first you just print the value of i. 71) 72) . printf("%d %f". float j. p=&a[2][2][2]. -i. j = ++i. -i = %d \n".i.

abc.prev=&jkl. } Answer: hello 5 Explanation: if you declare i as register compiler will treat it as ordinary integer and it will take integer value. }. int i. 73) #include<stdio.abc. char j[]= "hello". struct aaa *next. int x=100.def. } Answer: 11 Explanation: the expression i+++j is treated as (i++ + j) struct aaa{ struct aaa *prev.next=&def.h> main() { register i=5. printf("%d".if you print *q meAnswer:it will print first element of 3D array. main() { int i=5..j. now q is pointing to starting address of a.i=0. main() { struct aaa abc.*p.. 74) 76) .z.167 printf("%d.1 Explanation: p=&a[2][2][2] you declare only two 2D arrays. printf("%s %d". but you are trying to access the third 2D(which you are not declared) it will print garbage values.i+++j).%d".i). i value may be stored either in register or in memory. } Answer: garbagevalue. abc.j=6.ghi.jkl. *q=***a starting address of a is assigned integer pointer.*q).

printf("%d".pp->x.next=&abc. jkl.jkl.prev=&abc. int y.168 def. } int _l_abc(int i) { return(i++). Note: Since structure point is globally declared x & y are initialized as zeroes 78) main() { int i=_l_abc(10).0) Explanation: pp is a pointer to structure.0) origin is(0. we can access the elements of the structure either with arrow mark or with indirection operator.jkl.next->next->prev->next->i.prev=&ghi. main() { pp=&origin. } Answer: .next=&jkl.i=1.def.pp->y). }.i=3. ghi.next->next->prev->next->i this one points to "ghi" node the value of at particular node is 2.i=2. printf("%d\n". printf("origin is(%d%d)\n".(*pp). abc.prev=&def. 77) struct point { int x. struct point origin. printf("origin is (%d%d)\n".x. x=abc.x).def. } Answer: 2 Explanation: above all statements form a double circular linked list.ghi. } Answer: origin is(0.*pp.(*pp). ghi.y).next=&ghi.--i).

.q.. main(int argc. p++. 79) main() { char *p. } Answer: Compiler error Explanation: declaration of convert and format of getc() are wrong. p=q=r=0.r). getchar()..e. char **argv) { printf("enter the character"). printf("%p.169 9 Explanation: return(i++) it will first return i and then increments.convert(z). } sum(num1.argv[2]). main() { char c=' '.num2) 80) 81) .x.0004 Explanation: ++ operator when applied to pointers increments address according to their corresponding data-types. printf("%c".. 10 will be returned.x).. getc(c). int *q..p. sum(argv[1]. r++. long *r. q++. } Answer: 0001. i.0002..%p. if((c>='a') && (c<='z')) x=convert(c).%p".. } convert(z) { return z-32.

} Answer: garbage value Explanation: ptr pointer is pointing to out of the array range of one_d.h> int one_d[]={1. } Answer: Compiler error. } bbb(){ printf("hello"). main() { int *ptr.*ptr). ptr+=3.h> aaa() { printf("hi"). # include<stdio.3}. ptr[0]=aaa. } ccc(){ printf("bye"). ptr[2](). ptr=one_d. } main() { int (*ptr[3])(). 82) # include <stdio. Explanation: argv[1] & argv[2] are strings.num2.2. They are passed to the function sum without converting it to integer values. printf("%d".170 int num1. ptr[1]=bbb. { return num1+num2. } Answer: bye Explanation: 83) . ptr[2]=ccc.

.c followed by an infinite loop Explanation: The condition is checked against EOF.. if(i && j++) printf("%d. it should be checked against NULL. char i. printf("%d.0 Explanation: The value of i is 0. The values of i and j remain unchanged and get printed. } abc() { _AX = 1000. } Answer: contents of zzz.j=0.i). Since this information is enough to determine the truth value of the boolean expression.ptr[0] is assigned to address of the function aaa.i++. main() { int i.h> main() { FILE *ptr.i.j).%d". printf("%d". i = abc(). ptr=fopen("zzz. } Answer: 1000 86) 87) .c"."r").i).j). 85) #include<stdio.171 ptr is array of pointers to functions of return type int. ptr[2]() is in effect of writing ccc(). while((i=fgetch(ptr))!=EOF) printf("%c". So the statement following the if statement is not executed. since ptr[2] points to ccc.. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. main() { int i =0.%d. } Answer: 0.

"hello" will be printed.b.scanf("%d".1. 88) int i. It is compared with a signed value. Hence. Here _AH is the pseudo global variable denoting the accumulator.y) printf("hello").2. Since the both types doesn't match. for ( t=4.&i)-t. Thus the value of last variable y is returned to check in if.x. } // If the inputs are 0.int b = 20.t--). main(){ int t. } Answer: hello Explanation: The comma operator has associativity from left to right.&i)-t the values during execution will be.printf("%d\n". Since it is a non zero value if becomes true so. if(a. for(i=1. Only the rightmost value is returned and the other values are evaluated and ignored. t i x 4 0 -4 3 1 -2 2 2 0 main(){ int a= 0. main(){ unsigned int i.i>-2. } Explanation: i is an unsigned integer.char x =1.172 Explanation: Normally the return value from the function is through the information from the accumulator.3 find the o/p Answer: 4--0 3--1 2--2 Explanation: Let us assume some x= scanf("%d".i--) printf("c aptitude").i)) printf("%d--". signed is promoted to unsigned value.char y =10. the value of the accumulator is set 1000 so the function returns value 1000. The unsigned 89) 90) .

int abc(a. fun(&j). /* add a stmt here*/ } Answer: *k = &a Explanation: The argument of the function is a pointer to a pointer. p="%d\n".173 equivalent of -2 is a huge value so condition becomes false and control comes out of the loop. { /* some code*/ } Answer: i.float b) { /* some code */ } ii.300). Kernighan & Ritche notation main() { char *p. ANSI C notation ii. printf(p-2. 92) 93) . void fun(int **). 91) In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. What are the following notations of defining functions known as? i. main(){ int * j. int abc(int a. p++. } void fun(int **k) { int a =0. p++. float b. it points to '%d\n' and 300 is printed. } Answer: 300 Explanation: The pointer points to % since it is incremented twice and again decremented by 2.b) int a.

} Answer: The value if process is 0 ! Explanation: The function 'process' has 3 parameters . a==b returns 0. printf("%c".1. printf("%c". { return((*pf) (val1. { return( a= (a==b) ). } process(pf.*a). abc(a).b.a[1]]='b'. The formal parameters are substituted as 3 for a and 6 for b.func().process(func.a[2]='c'. a[0]='a'. int val1. This function returns the result of the operation performed by the function 'func'. a++.*a).b) int a. func(a. } main() { int process(). The function func has two integer parameters. } abc(char a[]){ a++.val2)). the following substitutions for formal parameters take place: func for pf. } Explanation: The base address is modified only in function and as a result a points to 'b' then after incrementing to 'c' so bc will be printed. a pointer to another function 2 and 3.6)). therefore the function returns 0 which in turn is returned by the function 'process'. since 3 is not equal to 6. integers. When this function is invoked from main. 3 for val1 and 6 for val2.val2.174 94) main(){ char a[100].a[4]='d'. printf("The value of process is %d !\n ".val1.val2) int (*pf) ().3. void main() { 95) 96) .

. Hence the 'I' will hold the value equal to 5.5. ie. as ret is integer hence the value stored in ret will have implicit type conversion from float to int. the function ret() is called in which the sizeof(float) ie. 4 is passed. Firstly. after the pre-increment in the printf statement. printf("%d ". so the value of static I ie. printf("here in 3 %d\n". } } Answer: 0000 Explanation: The variable "I" is declared as static.. hence memory for I will be allocated for only once. the function name and the argument name can be the same. and since main() is recursively called. The function main() will be called recursively unless I becomes equal to 0. the 6 will be printed. } Answer: here in 3 6 Explanation: The char array 'a' will hold the initialized string.i). int i=strlen(a). 0 will be printed every time the control is returned. as it encounters the statement. printf("\n here value is %d". 98) void main() { char a[]="12345\0". } int ret(int ret) { ret += 2.175 static int i=5. return(ret). .++i).. } Answer: Here value is 7 Explanation: The int ret(int ret). whose length will be counted from 0 till the null character. if(--i){ main().++k). The ret is returned in main() it is printed after and preincrement. after the first expression the value in ret will be 6. 97) void main() { int k=ret(sizeof(float)).

int integer=2. 1. Explanation: Void pointer is a generic pointer type. } Answer: 0 65535 Explanation: void main() { int i. Used when the exact pointer type will be known at a later point of time. int *i=&integer. 100) 101) . Void pointers are normally used for. Passing generic pointers to functions and returning such pointers. int gotit.gotit=--giveit). } Answer: Ok here Explanation: Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true. printf("%d".a)) printf("Ok here \n"). void main() { void *v.++giveit). No pointer arithmetic can be done on it.(int*)*v). if(printf("%s\n". printf("%u \n". 2. v=i. 3. We cannot apply indirection on type void*. printf("%u ".176 99) void main() { unsigned giveit=-1. As a intermediate pointer type. } Answer: Compiler Error. char a[]="\0". thus "Ok here" is printed. else printf("Forget it\n").

i. else continue. j. printf(“%d%d%d”. k). So expressions such as i = i++ are valid statements. main() { unsigned int i=10.i. j=j++.k=k++. } } Answer: Garbage values Explanation: The inner printf executes first to print some garbage value. So it encounters the break statement and comes out of the while statement. void main() { while(1){ if(printf("%d".k). Explanation: An identifier is available to use in program code from the point of its declaration.j=j++.j. Garbage in is garbage out (GIGO). printf(“i = %d j = %d k = %d”. The printf returns no of characters printed and this value also cannot be predicted. void main() { static int i=i++.177 102) void main() { int i=i++. } Answer: i=1j=1k=1 Explanation: Since static variables are initialized to zero by default. 103) 104) 104) . Still the outer printf prints something and so returns a non-zero value. j and k are automatic variables and so they contain some garbage value. k=k++. } Answer: Garbage values.printf("%d"))) break. The i.

*a+1-*a+3). The condition reduces to if (x) or in other words if(0) and so z goes uninitialized.y-1)). printf("%d".x).178 while(i-->=0) printf("%u ". printf("%d %d ".prod(x+2. main() { int a[10]. Thumb Rule: Check all control paths to write bug free code.>=0 will always be true. } Answer: 4 Explanation: *a and -*a cancels out. printf("%d".b) a*b main() { int x=3. This value is assigned to x.h> main() { int x. a=2.z. } Answer: 10 9 8 7 6 5 4 3 2 1 0 65535 65534…. So the expression i-. if(x=y%2) z=2.y=2. Explanation: Since i is an unsigned integer it can never become negative.y=4.. The result is as simple as 1 + 3 = 4 ! 107) #define prod(a.i). } Answer: Garbage-value 0 Explanation: The value of y%2 is 0. } Answer: 10 Explanation: The macro expands and evaluates to as: x+2*y-1 => x+(2*y)-1 => 10 106) . 105) #include<conio. leading to an infinite loop.a.z.

++k). 109) main() { int i=0. printf("%lf\n".k=50}.j=20.fmod(f. When the value of i becomes 0 it comes out of while loop. 113) main() { float f=5. printf("%d".f<<2). } Answer: 1 Explanation: Note the semicolon after the while statement. The value –1 is printed due to the postdecrement operator. Due to post-increment on i the value of i while printing is 1.g=10. So it has no effect on the expression and now the while loop is. printf("%lf\n".179 108) main() { unsigned int i=65000.f%g). printf("%f\n". } Answer: Line no 5: Error: Lvalue required Line no 6: Cannot apply leftshift to float Line no 7: Cannot apply mod to float Explanation: Enumeration constants cannot be modified. printf("%d\n".i). . while(i--!=0) which is false and so breaks out of while loop. printf("%d". while(i++!=0). while(+(+i--)!=0) i-=i++. so you cannot apply ++. fmod() is to find the modulus values for floats as % operator is for ints. Bit-wise operators and % operators cannot be applied on float values.i). enum{i=10.g)). } Answer: -1 Explanation: Unary + is the only dummy operator in C.

cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.int. } Answer: 10 11 12 13 12 11 10 13 Explanation: Pascal argument passing mechanism forces the arguments to be called from left to right.i++. f(i++. } void cdecl f(int i. k).integer :k) { write(i.k). What is the output of the program given below . j. } main() { int i=10. f(i++.int k) { printf(“%d %d %d”. 112).i. printf(" %d".int). printf(" %d\n". } Answer: Compiler error: unknown type integer Compiler error: undeclared function write Explanation: Pascal keyword doesn’t mean that pascal code can be used.int j. It means that the function follows Pascal argument passing mechanism in calling the functions.i++.i).int j.j.i).int k) { printf(“%d %d %d”. f(i++. k).180 110) main() { int i=10. 111) void pascal f(int i. } void pascal f(integer :i. printf(" %d". i=10.i++). j. void pascal f(int.i++).i.i).i++).integer:j.i++.

113) main() { unsigned char i=0. .i). printf("%d\n". On the other hand if it considers char to be unsigned by default. So the i++ can never yield negative value and i>=0 never becomes false so that it can come out of the for loop.i>=0. 114) main() { char i=0. for(. The inner loop executes to increment the value from 0 to 127 (the positive range of char) and then it rotates to the negative value of -128. THe initial value of the i is set to 0. Explanation: The detail if the char is signed/unsigned by default is implementation dependent. } Answer: Behavior is implementation dependent. The condition in the for loop fails and so comes out of the for loop. If the implementation treats the char to be signed by default the program will print –128 and terminate.i).i++) . printf("%d\n". it goes to infinite loop.i).i>=0. for(. It prints the current value of i that is -128. Rule: You can write programs that have implementation dependent behavior.i++) .i>=0.181 main() { signed char i=0. } Answer infinite loop Explanation The difference between the previous question and this one is that the char is declared to be unsigned. } Answer -128 Explanation Notice the semicolon at the end of the for loop. for(. printf("%d\n". But dont write programs that depend on such behavior.i++) .

main() { error g1. x is a pointer to array of(size 10) integers. printf("%d". Answer Definition. Apply clock-wise rule to find the meaning of this definition.error =1. enum errorType{warning. 117) typedef struct error{int warning. The another use is that it is a type name (due to typedef) for enum errorType. names can only be overloaded in different namespaces). g1. main() { error g1. Given a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used: error g1.g1. g1=error. Note: the extra comma in the declaration. error.} is not an error. error.error). printf("%d". What is the output for the program given below typedef enum errorType{warning. exception. } Answer Compiler error: Multiple declaration for error Explanation The name error is used in the two meanings. error. Find what does it mean? int (*x)[10]. An extra comma is valid and is provided just for programmer’s convenience.g1). exception.}error. g1=1.182 115) Is the following statement a declaration/definition. exception. } . One means that it is a enumerator constant with value 1. // which error it refers in each case? When the compiler can distinguish between usages then it will not issue error (in pure technical terms. 116).}error.

it is perfectly legal and valid. exception. #endif main() { int thing = 0. Note This code is given here to just explain the concept behind. (dot) or -> (arrow) operator preceded by the variable name as in : g1. 119) #if something == 0 . This error can be used only by preceding the error by struct kayword as in: struct error someError. Possible doesn’t mean that we should use it! 118) #ifdef something int some=0. Typedef struct error{int warning.error =1. error. some . } Answer: Compiler error : undefined symbol some Explanation: This is a very simple example for conditional compilation. exception. Since the compiler can perfectly distinguish between these three usages.thing).183 Answer 1 Explanation The three usages of name errors can be distinguishable by the compiler at any instance. In real programming don’t use such overloading of names. error. typedef struct error{int warning. It reduces the readability of the code.}error. so valid (they are in different namespaces). printf("%d %d\n".}error. exception. The name something is not already known to the compiler making the declaration int some = 0.g1. effectively removed from the source code.error). This can be used only after . typedef struct error{int warning.}error. error. printf("%d". This can be used to define variables without using the preceding struct keyword as in: error g1.

thing). If a name is not known the preprocessor treats it to be equal to zero. adding a zero doesn’t change the value/meaning. *arr2D refers to the start of the first 1D array (of 3 integers) that is the same address as arr2D. } Answer 00 Explanation This code is to show that preprocessor expressions are not the same as the ordinary expressions. What is the output for the following program main() { int arr2D[3][3]. ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ). some . *arr2D is nothing but *(arr2D + 0).184 int some=0. #endif main() { int thing = 0. . Again arr2D[0] is the another way of telling *(arr2D + 0). So the expression (arr2D == *arr2D) is true (1). 120). printf("%d %d\n". arr2D arr2D[1] arr2D[2] arr2D[3] The name arr2D refers to the beginning of all the 3 arrays. Similarly. arr2D is made up of a 3 single arrays that contains 3 integers each . N dimensional arrays are made up of (N-1) dimensional arrays. } Answer 1 Explanation This is due to the close relation between the arrays and pointers. So the expression (*(arr2D + 0) == arr2D[0]) is true (1). printf("%d\n".

swap(&x. printf("%d". 123) main() { char *p = “ayqm”.int *b) { *a=*a+*b. } main() { int x=10. printf(“%c”.++*(p++)).y).&y). 121) void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”).y=20. –1 is represented in unsigned value as all 1’s and so both are equal. } Answer You can answer this if you know how values are represented in memory Explanation ~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. Simple checking will help understand this.185 Since both parts of the expression evaluates to true the result is true(1) and the same is printed. 122) int swap(int *a.*a=*a-*b. } Answer: b main() { int i=5.*b=*a-*b. } Answer x = 20 y = 10 Explanation This is one way of swapping two values.++i++). } 124) . printf("x= %d y = %d\n".x.

ptr[0] = aaa. Similarly. } Answer: bye Explanation: int (* ptr[3])() says that ptr is an array of pointers to functions that takes no arguments and returns the type int. 126) int aaa() {printf(“Hi”).} iny ccc(){printf(“bye”). 125) main() { char *p = “ayqm”. Since ptr[2] contains the address of the function ccc. } Answer: b Explanation: There is no difference between the expression ++*(p++) and + +*p++. Parenthesis just works as a visual clue for the reader to see which expression is first evaluated. For postfix ++ to operate an lvalue is required. c = ++*p++. it means that the first function pointer in the array is initialized with the address of the function aaa.} main() { int ( * ptr[3]) (). char c.} int bbb(){printf(“hello”).186 Answer: Compiler error: Lvalue required in function main Explanation: ++i yields an rvalue. printf(“%c”. By the assignment ptr[0] = aaa. So it results in printing "bye". the call to the function ptr[2]() is same as calling ccc(). ptr[1] = bbb. the other two array elements also get initialized with the addresses of the functions bbb and ccc. ptr[2](). ptr[2] =ccc.c). 127) main() .

(b).(a). printf(p.65). a ptrto a funtion which returns void. } Answer: 1 Explanation: The expression can be treated as i = (++i==6). 129) void ( * abc( int. So “some” and “some\0” are equivalent. void ( *def) () ) ) (). the return type of the function is void. because == is of higher precedence than = operator. “%c\n”.i=++i ==6). Answer:: abc is a ptr to a function which takes 2 parameters . Explanation: Apply the clock-wise rule to find the result. printf(“%d”.”some\0”)) printf(“Strings are not equal\n”). } Answer: A Explanation: Due to the assignment p[1] = ‘c’ the string becomes. ++i is equal to 6 yielding true(1). So. 128) main() { char p[ ]="%d\n". an integer variable. } Answer: No output Explanation: Ending the string constant with \0 explicitly makes no difference. strcmp returns 0 (false) hence breaking out of the while loop. p[1] = 'c'.187 { int i=5. In the inner expression. the same gets printed. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’. Hence the result. 130) main() { while (strcmp(“some”. .

1). mptr = (int*)malloc(sizeof(int)). for (. Explanation: If a string constant is initialized explicitly with characters. int *cptr = (int*)calloc(sizeof(int). char str2[] = {‘s’. printf(“%d”. } Answer: garbage-value 0 Explanation: The memory space allocated by malloc is uninitialized.’o’.*cptr). while (strcmp(str1. Explanation: As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation. So str1 and str2 are not the same.’o’. } Answer: “Strings are not equal” “Strings are not equal” …. it treats whatever the values that are in the following positions as part of the string until it randomly reaches a ‘\0’. Since str1 doesn’t have null termination.’\0’}. hence the result.’e’.*mptr).’e’}.’m’. } Answer: Compiler Error: Lvalue required.i++=0. printf(“%d”.188 131) main() { char str1[] = {‘s’. ‘\0’ is not appended automatically to the string. 132) main() { int i = 3. whereas calloc returns the allocated memory space initialized to zeros. 133) void main() { int *mptr.i).str2)) printf(“Strings are not equal\n”).’m’.) printf(“%d”. *cptr. void main() 134) .

Answer: 1. } else j = j. -Differentiate the above declarations. 136) 1. printf("%d %d". printf(“%d”. } Answer: 10 10 Explanation: The Ternary operator ( ? : ) is equivalent for if-then-else statement. The while condition becomes false and hence. 3. This continues till the integer value rotates to positive value (32767). j?(i.j) { if(i. while(i<=10) (i>2)?i++:i--.j).j)?i:j:j. const char *a.189 { static int i. comes out of the while loop. char* const a. 2. j = i. 135) main() { int i=10. Inside the while loop the conditional operator evaluates to false. char const *a. printing the i value. So the question can be written as: if(i. executing i--. else j = j.j) j = i. 'const' applies to char * rather than 'a' ( pointer to a constant char ) *a='F' : illegal a="Hi" : legal .i. i). } Answer: 32767 Explanation: Since i is static it is initialized to 0.j=20.

i. false && (anything) => false where (anything) will not be evaluated.j=10. } Answer: 41 Explanation: The boolean expression needs to be evaluated only till the truth value of the expression is not known. i=i&=j&&10. j). i is 5.j). when any of the operands become false. Similarly when && operator is involved in an expression. j is not equal to zero itself means that the expression’s truth value is 1. 137) main() { int i=5. Hence the result. i = 5&1 is 1.190 2. Same as 1. j = j || i++ && printf("YOU CAN"). 138) main() { int i=4. printf("%d %d". printf("%d %d". the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated. So the remaining expression is not evaluated and so the value of i remains the same. 'const' applies to 'a' rather than to the value of a (constant pointer to char ) *a='F' a="Hi" 3. The inner expression (j&&10) evaluates to 1 because j==10. Because it is followed by || and true || (anything) => true where (anything) will not be evaluated. 139) main() { register int a=2. : legal : illegal .j=7. } Answer: 1 10 Explanation: The expression can be written as i=(i&=(j&&10)).i.

printf("%d\n". printf("%d\n".*f1.&a). } Answer: Compier Error: '&' on register variable Rule to Remember: & (address of ) operator cannot be applied on register variables.5. printf("Value of a = %d".*f2. 141) main() { extern i.*f1. 142) main() { int a=2.5. switch(i) { case 1: printf("1"). *f2+=*f2+=a+=2. } } Answer: Compiler Error: switch expression not integral Explanation: Switch statements can be applied only to integral types. case 2: printf("2").*f2). } Answer: . printf("\n%d %d %d". { int i=20. } } Answer: Linker Error : Unresolved external symbol i Explanation: The identifier i is available in the inner block and so using extern has no use in resolving it.a. default : printf("0").191 printf("Address of a = %d". 140) main() { float i=1. f1=f2=&a.i).a).i).

int DIM(int array[]) { return sizeof(array)/sizeof(int ). sizeof(*p). sizeof(*p) = 1. sizeof(a). } Answer: 10 Explanation: The size of integer array of 10 elements is 10 * sizeof(int). So changes through f1 and f2 ultimately affects only the value of a. printf("\n sizeof(a) = %d. sizeof(*p) = %d. } main() { 145) . 144) #define DIM( array.192 16 16 16 Explanation: f1 and f2 both refer to the same memory location a. DIM(arr. strlen(p) = %d". sizeof(a) => size of the character array => 5 When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable. printf("\n sizeof(p) = %d. The macro expands to sizeof(arr)/sizeof(int) => 10 * sizeof(int) / sizeof(int) => 10. printf(“The dimension of the array is %d”. strlen(a) = %d". strlen(p)). sizeof(p). Here the sizeof(a) where a is the character array and the size of the array is 5 because the space necessary for the terminating NULL character should also be taken into account. char a[ ]="GOOD". } Answer: sizeof(p) = 2. 143) main() { char *p="GOOD". strlen(a)). int)). strlen(a) = 4 Explanation: sizeof(p) => sizeof(char*) => 2 sizeof(*p) => sizeof(char) => 1 Similarly. strlen(p) = 4 sizeof(a) = 5. type) sizeof(array)/sizeof(type) main() { int arr[10].

So the argument is equivalent to int * array (this is one of the very few places where [] and * usage are equivalent).a+1. DIM(arr)).8. for(i=0.3.*(*(p+j)+i)). static *p[]={a. } } Answer: 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9 Explanation: *(*(p+i)+j) is equivalent to p[i][j]. } void swap(int *a. int i. 147) main() { void swap().i++) { for(j=0.9}.i<3. int x=10.&y).6. } Answer: 1 Explanation: Arrays cannot be passed to functions as arguments and only the pointers can be passed.*(*(i+p)+j).j. *(*(j+p)+i).j<3.a+2}.7. printf(“The dimension of the array is %d”. swap(&x. sizeof(int *)/ sizeof(int) that happens to be equal in this case. The return statement becomes.y). int *b) { .5.4.*(*(p+i)+j). printf("x=%d y=%d".j++) printf("%d\t%d\t%d\t%d\n".y=8.x.193 int arr[10].2. 146) main() { static int a[3][3]={1.

printf("%d %d". So this doesn’t issue a compiler error by the call swap(&x. *((char*)iPtr). Inside main(). Remember that the INTEL machines are ‘small-endian’ . printf("%d %d". the swap function will be defined as follows. *((char*)iPtr). *b ^= *a. that has two arguments.&y). *b ^= *a.194 *a ^= *b. void swap() int *a. In that style. *((char*)iPtr+1) ). void swap(). 149) main() { int i = 258. int *iPtr = &i. *((char*)iPtr+1) ). 00000001 00000001. 00000001 00000001. so the individual bytes are taken by casting it to char * and get printed. 148) main() { int i = 257. int *b { *a ^= *b. } Answer: 21 Explanation: The integer value 257 can be represented in binary as. *a ^= *b. means that swap is a function that may take any number of arguments (not no arguments) and returns nothing. int *iPtr = &i. } Answer: 11 Explanation: The integer value 257 is stored in the memory as. void swap() which means the swap can take any number of arguments. *a ^= *b. This convention is historically due to pre-ANSI style (referred to as Kernighan and Ritchie style) style of function declaration. } where the arguments follow the (). So naturally the declaration for swap will look like. } Answer: x=10 y=8 Explanation: Using ^ like this is a way to swap two variables without using a temporary variable and that too in a single statement.

printf("%d". So the value of ‘least’ finally is 0. So the integer corresponding to it is 00000010 00101100 => 556. So the value of ‘str’ is less than that of ‘least’. char least = 127.195 machines. char * ptr = str. } Answer: 556 Explanation: The integer value 300 in binary notation is: 00000001 00101100. 151) #include <stdio.i).least). Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. char *ptr = &i. It is stored in memory (small-endian) as: 00101100 00000001. The integer value 258 is stored in memory as: 00000001 00000010. while (*ptr++) least = (*ptr<least ) ?*ptr :least. *++ptr=2. printf("%d". } Answer: 0 Explanation: After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘\0’. Small-endian means that the lower order bytes are stored in the higher memory addresses and the higher order bytes are stored in lower addresses. 150) main() { int i=300. main() { struct student 152) 153) .h> main() { char * str = "hello". Declare an array of N pointers to functions returning pointers to functions returning pointers to characters? Answer: (char*(*)( )) (*ptr[N])( ).

stud.year).month.dob.rollno. &student.dob. }stud. struct date dob. &student.dob.dob.day. What went wrong? void main() { struct student { .month.year.dob. 155) There were 10 records stored in “somefile.day. &student.year.year). } Answer: Compiler Error: Undefined structure date Explanation: Only declaration of struct date is available inside the structure definition of ‘student’ but to have a variable of type struct date the definition of the structure is required. scanf("%s%d%d%d". } Answer: Compiler Error: Undefined structure date Explanation: Inside the struct definition of ‘student’ the member of type struct date is given. scanf("%s%d%d%d". }stud. 154) main() { struct date. }.month.month.dob.dat” but the following program printed 11 names. stud. &student. &student. struct date dob. The compiler doesn’t have the definition of date structure (forward reference is not allowed in C in this case) so it issues an error. }.rollno. struct student { char name[30]. struct date { int day. &student. struct date { int day.196 { char name[30].

The numbers that are allowed inside the [] is just for more readability. 1. } } Explanation: fread reads 10 records and prints the names successfully. 1 . What is the subtle error in the following code segment? void fun(int n. 156) Is there any difference between the two declarations. int i=0. int foo(int *arr[]) and 2.197 char name[30]. fp). *p = 0. So it prints the last record again. } Answer & Explanation: If the body of the loop never executes p is assigned no address. What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100). It will return EOF only when fread tries to read another record and fails reading EOF (and returning EOF). }stud. So there is no difference between the two declarations. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program). rollno[6].dat”.name). int foo(int *arr[2]) Answer: No Explanation: Functions can only pass pointers and not arrays. hence comes out of the while loop. while(!feof(fp)) { fread(&stud. After this only the condition feof(fp) becomes false. puts(stud. sizeof(stud). int arr[]) { int *p=0.”r”). FILE *fp = fopen(“somefile. while(i++<n) p = &arr[i]. 157) 158) .

159) What is the hidden bug with the following statement? assert(val++ != 0). return s. Answer & Explanation: Assert macro is used for debugging and removed in release version. } Answer & Explanation: assert macro should be used for debugging and finding out bugs. file %s. // i points to the address 400 *i = 0. } Answer: No output 160) 161) . abort()) void main() { int i = 10.#cond. Rule to Remember: Don’t use expressions that have side-effects in assert statements. "assertion failed: %s. This type of pointer in which the non-availability of the implementation of the referenced location is known as 'incomplete type'. So the behavior of the code becomes different in case of debug version and the release version thus leading to a subtle bug. else printf("This statement becomes else for if in assert macro").198 assert(s != NULL). In assert. if(i==0) assert(i < 100).\ __FILE__. the experssion involves side-effects. void main() { int *i = 0x400. The check s != NULL is for error/exception handling and for that assert shouldn’t be used. line %d \n".__LINE__). } Answer: Undefined behavior Explanation: The second statement results in undefined behavior because it points to some location whose value may not be available for modification. A plain if and the corresponding remedy statement has to be given. #define assert(cond) if(!(cond)) \ (fprintf(stderr. // set the value of memory location pointed by i.

Explanation: *b is a pointer to type struct a and so is legal. The solution is to use conditional operator instead of if statement. Is the following code legal? typedef struct a { 163) 164) .__LINE__). abort()) \ } 162) Is the following code legal? struct a { int x. Is the following code legal? struct a { int x. } Answer: No Explanation: Is it not legal for a structure to contain a member that is of the same type as in this case. __FILE__. #define assert(cond) ((cond)?(0): (fprintf (stderr. the size of the pointer to a structure even before the size of the structure is determined(as you know the pointer to any type is of same size). Because this will cause the structure declaration to be recursive without end. "assertion failed: \ %s.199 Explanation: The else part in which the printf is there becomes the else for if in the assert macro.\ __FILE__. file %s.#cond. line %d \n".#cond. file %s. } Answer: Yes. struct a *b. Hence nothing is printed. The compiler knows. abort())) Note: However this problem of “matching with nearest else” cannot be solved by the usual method of placing the if statement inside a block like this. line %d \n". This type of structures is known as ‘self-referencing’ structure. #define assert(cond) { \ if(!(cond)) \ (fprintf(stderr. "assertion failed: %s. struct a b.__LINE__).

166) 167) . sizeof(double *)). printf(“sizeof (double *) = %d \n”. printf(“sizeof (int *) = %d \n”. typedef struct a aType. } Answer: No Explanation: When the declaration. void main() { printf(“sizeof (void *) = %d \n“. struct a { int x. sizeof( void *)). This is known as ‘incomplete types’. Is the following code legal? void main() { typedef struct a aType. aType someVariable. struct a { int x. aType *b. aType *b. is encountered body of struct a is not known. }. Answer: Yes Explanation: The typename aType is known at the point of declaring the structure. aType *b. }aType Answer: No Explanation: The typename aType is not known at the point of declaring the structure (forward references are not made for typedefs). }. 165) Is the following code legal? typedef struct a aType.200 int x. sizeof(int *)). because it is already typedefined.

*jp = &j. int k = *ip/*jp. Which version do you prefer of the following two. if a very big input (here. When fgets is used with stdin performs the same operation as gets but is safe. If the str contains any format characters like %d then it will result in a subtle bug. fp) Answer & Explanation: The second one is better because gets(inputString) doesn't know the size of the string passed and so. Answer & Explanation: Prefer the first one. } Answer: Compiler Error: “Unexpected end of file in comment started in line 5”. 168) char inputString[100] = {0}. sizeof(struct unknown *)). int *ip= &i. // put braces to force the intention 169) 170) . To force what is intended by the programmer. printf(“%d”. j=2. Explanation: The programmer intended to divide two integers. } Answer : sizeof (void *) = 2 sizeof (int *) = 2 sizeof (double *) = 2 sizeof(struct unknown *) = 2 Explanation: The pointer to any type is of same size. To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString.k).str). void main() { int i=10.201 printf(“sizeof(struct unknown *) = %d \n”. sizeof(inputString). 1) printf(“%s”. // or the more curt one 2) printf(str). // give space explicity separating / and * //or int k = *ip/(*jp). the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. int k = *ip/ *jp. more than 100 chars) the charactes will be written past the input string. but by the “maximum munch” rule.

202 will solve the problem. ch. printf("%s". 171) void main() { char ch. 174) main() { char a[4]="HELL". } Answer: HELL%@!~@!@???@~~! Explanation: The character array has the memory just enough to hold the string “HELL” and doesnt have enough space to store the terminating null character. So it prints the HELL correctly and continues to print garbage values till it accidentally comes across a NULL character. Thus ch is always smaller than 127.ch++) printf(“%c %d \n“. ptr = (int *) 0x400.a). 172) 173) . main() { char a[4]="HELLO". for(ch=0.ch<=127. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. Is this code legal? int *ptr. } Answer: Implementaion dependent Explanation: The char type may be signed or unsigned by default. printf("%s". } Answer: Compiler error: Too many initializers Explanation: The array a is of size 4 but the string constant requires 6 bytes to get stored. ch).a). Answer: Yes Explanation: The pointer ptr will point at the integer in the memory location 0x400.

176) main() { { { } printf("%d".i). } int main() { puts(someFun()). 177) Printf can be implemented by using __________ list. return temp. } Answer: string constant Explanation: . } int i.203 175) main() { int a=10. No pointer arithmetic can be done on it and you cannot apply indirection operator (*) on void pointers. printf("\n %u %u ". k++.k). printf("%d". j++. j=k=&a. } Answer: Compiler error: Cannot increment a void pointer Explanation: Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type.i).j. Answer: Variable length argument lists 178) char *someFun() { char *temp = “string constant". const volatile unsigned i=30. extern int i. void *k.i).*j. } printf("%d". int i=20.

Predict the output or error(s) for the following: 26.  Program is compiled using Turbo C/C++ compiler. Explanation: Both the functions suffer from the problem of dangling pointers. .  The underlying machine is an x86 system.’n’. return temp. return temp.’i’. ‘t’. } char *someFun2() { char temp[ ] = {‘s’. It is assumed that. void main() { int const * p=5. C Aptitude Aptitude Note : All the programs are tested under Turbo C/C++ compilers. The function someFun2() also suffers from the same problem but the problem can be easily identified in this case. } Answer: Garbage values. 179) char *someFun1() { char temp[ ] = “string".  Programs run under DOS environment. This is created dynamically as the function is called. The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed). } int main() { puts(someFun1()).204 The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack. In someFun1() temp is a character array and so the space for it is allocated in heap and is initialized with character string “string”.’g’}.’r’. puts(someFun2()). so is also deleted dynamically on exiting the function so the string data is not available in the calling function main() leading to print some garbage values. so this doesn’t lead to dangling pointers.

*(i+s). Float takes 4 bytes and long double takes 10 bytes. i is the index number/displacement from the base address. But in the case of C it is same as s[i]. Rule of Thumb: . } Answer: mmmm aaaa nnnn Explanation: s[i]. So float stores 0. 28. i[s] are all different ways of expressing the same idea.*(i+s). 27.9 with less precision than long double.s[ i ].1. double. for(i=0.++(*p)). But we tried to change the value of the "constant integer".s[ i ]. double you = 1. Generally array name is the base address for that array.205 printf("%d". Depending on the number of bytes. int i. Explanation: p is a pointer to a "constant integer". if(me==you) printf("I love U"). indirecting it with * is same as s[i].i[s]). So.i++) printf("\n%c%c%c%c". i[s] may be surprising.1. *(s+i). } Answer: I hate U Explanation: For floating point numbers (float. Here s is the base address. main() { char s[ ]="man". main() { float me = 1. the precession with of the value represented varies. } Answer: Compiler error: Cannot modify a constant value. long double) the values cannot be predicted exactly. else printf("I hate U").*(s+i).

main() { int c[ ]={2.var--).j<5. i=20.4.!= ) . } } Answer: 2222223465 Explanation: Initially pointer c is assigned to both p and q. printf("%d ". Main is also treated like any other ordinary function. . ++p. In second loop p itself is incremented. } Answer: Linker Error : Undefined symbol '_i' Explanation: extern storage class in the following declaration. 31. if(var) main().j++) { printf(" %d ". the value 2 will be printed 5 times. int j. it is initialized once.*q=c.6.206 Never compare or at-least be cautious when using floating point numbers with relational operators (== . main() { extern int i.8. >=. In the first loop.*c). which can be called recursively.j<5. } Answer: 54321 Explanation: When static storage class is given.3. for(j=0. <=.5}.j++){ printf(" %d ". main() { static int var = 5.i).7. extern int i.*p=c. <.*p). 29. So the values 2 3 4 6 5 will be printed. printf("%d". The change in the value of a static variable is retained even between the function calls. >. ++q. since only q is incremented and not c . 30. } for(j=0.4.

m=i++&&j++&&k++||l++.m). case 1: printf("one"). 32. printf("%d %d %d %d %d".m.k. But linker finds that no other variable of name i is available in any other program with memory space allocated for it.j.i. Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2. 34. printf("%d %d ". So the expression ‘i++ && j++ && k++’ is executed first. 33. main() { int i=-1. .k=0.sizeof(*p). The values of other variables are also incremented by 1. The result of this expression is 0 (1 && -1 && 0 = 0).l. main() { int i=3. break.for which it gives 0). case 2:printf("two"). switch(i) { default:printf("zero"). main() { char *p. P is a character pointer. which needs one byte for storing its value (a character). And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the value of m is 1.sizeof(p)). } Answer: 00131 Explanation : Logical operations always give a result of 1 or 0 .l=2.j=-1. Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination. Hence a linker error has occurred . } Answer: 12 Explanation: The sizeof() operator gives the number of bytes taken by its operand.207 specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking.

the compiler doesn't know anything about the function display. 37.208 break. display(string).The %x format specifier specifies that the integer value be printed as a hexadecimal value. printf("c=%d". } void display(char *string) { printf("%s". Hence a compile time error occurs. . 36. When it sees the actual function display.string). the arguments and type contradicts with what it has assumed previously. (which is the default type). } Answer: Compiler Error : Type mismatch in redeclaration of function display Explanation : In third line. 35.-1<<4). } Answer: fff0 Explanation : -1 is internally represented as all 1's. It is executed only when all other cases doesn't match. main() { int c=. main() { printf("%x".c). break. case 3: printf("three"). It assumes the arguments and return types to be integers. When left shifted four times the least significant 4 bits are filled with 0's.-2. main() { char string[]="Hello World". } } Answer : three Explanation : The default case can be placed anywhere inside the loop. when the function display is encountered.

. main() { int i=10. 0>14 is false (zero).*str1. ie.'\0'}. p=&s[3]. minus * minus= plus. i--). #define int char main() { int i=65. } Answer: i=0 Explanation: In the expression !i>14 . } Answer: 77 . 2 is a constant and not a variable.i). i=!i>14.h> main() { char s[]={'a'. char *p. 40.'c'. 38. } Answer: sizeof(i)=1 Explanation: Since the #define replaces the string int by the macro char 39. Explanation: Here unary minus (or negation) operator is used twice.'\n'.209 } Answer: c=2.++*p + ++*str1-32). printf("%d". Because -. Same maths rules applies. !i (!10) is 0 (not of true is false). printf("sizeof(i)=%d". str=p. printf("i=%d". Note: However you cannot give like --2.operator can only be applied to variables as a decrement operator (eg.'c'.'b'. str1=s. ! is a unary logical operator.*str. #include<stdio. NOT (!) operator has more precedence than ‘ >’ symbol.sizeof(i)).

} Answer: SomeGarbageValue---1 Explanation: p=&a[2][2][2] you declare only two 2D arrays. If you print *q.210 Explanation: p is pointing to character '\n'.*q. #include<stdio.3.4}. struct xx *s. it will print first element of 3D array. char name[]="hello". }. {5. Now q is pointing to starting address of a. "p is pointing to '\n' and that is incremented by one. So we get the output 77 :: "M" (Ascii is 77). str1 is pointing to character 'a' ++*p. printf("%s".6. *q=***a starting address of a is assigned integer pointer. The value of ++*p is 11.h> main() { .*q). printf("%d----%d".2. 42.h> main() { struct xx { int x=3.h> main() { int a[2][2][2] = { {10. Now performing (11 + 98 – 32). #include<stdio. str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'.s->x). 41." the ASCII value of '\n' is 10.8} }. printf("%d". we get 77("M"). #include<stdio.*p. p=&a[2][2][2].s->name). int *p. *q=***a. but you are trying to access the third 2D(which you are not declared) it will print garbage values. ASCII value of 'b' is 98. which is then incremented to 11.7. } Answer: Compiler Error Explanation: You should not initialize variables in declaration 43. ++*str1.

i). } Answer: 45545 Explanation: The arguments in a function call are pushed into the stack from left to right.211 struct xx { int x. . } Answer: Compiler Error Explanation: The structure yy is nested within structure xx. Hence for nested structure yy you have to declare member. printf("%d%d%d%d%d%d".++i. which needs an instance of yy to be known. main() { printf("\nab").newline \b . struct yy { char s. and the evaluation is from right to left. printf("\rha"). If the instance is created after defining the structure the compiler will not know about the instance relative to xx. 44.i++. }. }. struct xx *p. printf("\bsi"). Hence.backspace \r .--i. } Answer: hai Explanation: \n . hence the result.linefeed 45. the elements are of yy are to be accessed through the instance of structure xx. main() { int i=5.i--. struct yy *q. The evaluation is by popping out from the stack.

i = 64/square(4). main() { char *p="hai friends". while(*p!='\0') ++*p++. So the most recently assigned value will be taken.*p1.p. } Answer: ibj!gsjfoet Explanation: ++*p++ will be parse in the given order  *p that is value at the location currently pointed by p will be taken  ++*p the retrieved value will be incremented  when . #include <stdio. in the while loop initial value pointed by p is ‘h’. p1=p. Thus.h> #define a 10 main() { #define a 50 printf("%d". Similarly blank space is converted to ‘!’.212 46.e. #define square(x) x*x main() { int i. ‘a’ which is similarly changed to ‘b’ and so on. which is changed to ‘i’ by executing ++*p and pointer moves to point.a). } Answer: 64 Explanation: the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 .i).p1). printf("%s %s". } Answer: 50 Explanation: The preprocessor directives can be redefined anywhere in the program. is encountered the location will be incremented that is p++ will be executed Hence. . 48. Since / and * has equal priority the expression will be evaluated as (64/4)*4 i. we obtain value in p becomes “ibj! gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything. printf("%d". 16*4 = 64 47.

213 49. } Answer: Some address will be printed. is an executable statement but with no action. printf("%d\n".The input program to compiler looks like this : main() { 100. . } Note: 100. 27) main() { clrscr().main). Answer: No output/error Explanation: The first clrscr() occurs inside a function. Explanation: Function names are just addresses (just like array names are addresses). So it becomes a function call. } clrscr(). is a function declaration (because it is not inside any function). printf("%d\n". So it doesn't give any problem 50. In the second clrscr(). They are printed as hexadecimal numbers.100). main() { printf("%p". } Answer: 100 Explanation: Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs. main() is also a function. %p in printf specifies that the argument is an address. #define clrscr() 100 main() { clrscr(). So the address of function main will be printed.clrscr()).

} Answer: 400.sizeof(farther). main() { char *p.%d").BLACK. If more number of assignments given in the program...214 28) enum colors {BLACK...GREEN} main() { printf("%d. 31) .BLUE. Any number of printf's may be given.BLUE.2 Explanation: enum assigns numbers starting from 0. printf("%d.then printf will take garbage values.GREEN).sizeof(farthest))..%d. 29) void main() { char far *farther.j=300.%d".300 Explanation: printf takes the values of the first two assignments of the program.*farthest. printf("%d.%d". return(1). if not explicitly defined.2 Explanation: the second pointer is of char type and not a far pointer 30) main() { int i=400...1. } Answer: 0. } Answer: 4.. All of them take only the first two values.

i). } 33) . names[3]=names[4]. They can be applied any number of times provided it is meaningful.names[i]). names[4]=t."ada". Again & references it to an address and * dereferences it to the value H.i<=4. while (i<=5) { printf("%d"."fortran". for (i=0."perl"}. if (i>2) goto here. main() { static char names[5][20]={"pascal". i++.215 p="Hello". *p dereferences it and so its value is H. The label 'here' is available in function fun() Hence it is not visible in function main. int i. char *t. } } fun() { here: printf("PP"). } Answer: H Explanation: * is a dereference operator & is a reference operator."cobol".*&*p). in other words The scope of the labels is limited to functions . } Answer: Compiler error: Undefined label 'here' in function main Explanation: Labels have functions scope. printf("%c\n".i++) printf("%s". Here p points to the first character in the string "Hello". 32) main() { int i=1. t=names[3].

#include<stdio. Explanation: Side effects are involved in the evaluation of i void main() { int i=5. switch(i) { case 1: printf("GOOD").h> main() { int i=1. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error). 35) 36) . } Answer: Compiler Error Explanation: The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators.i++ + ++i). printf("%d".i+++++i). break.j=2. printf("%d". break. } } Answer: Compiler Error: Constant expression required in function main.216 Answer: Compiler error: Lvalue required in function main Explanation: Array names are pointer constants. Note: Enumerated types can be used in case statements. case j: printf("BAD"). } Answer: Output Cannot be predicted exactly. 34) void main() { int i=5. So it cannot be modified.

217

37)

main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here } Answer: 1 Explanation: Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned successfully. So number of items read is 1. #define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); } Answer: 100 main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); } Answer: 1 Explanation: before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).

38)

39)

40)

#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

218 Answer: M Explanation: p is pointing to character '\n'.str1 is pointing to character 'a' ++*p meAnswer:"p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11. + +*str1 meAnswer:"str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 is added and result is subtracted from 32. i.e. (11+98-32)=77("M"); 41) #include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); } Answer: Compiler Error Explanation: Initialization should not be done for structure members inside the structure declaration #include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; } Answer: Compiler Error Explanation:

42)

219 in the end of nested structure yy a member have to be declared. 43) main() { extern int i; i=20; printf("%d",sizeof(i)); } Answer: Linker error: undefined symbol '_i'. Explanation: extern declaration specifies that the variable i is defined somewhere else. The compiler passes the external variable to be resolved by the linker. So compiler doesn't find an error. During linking the linker searches for the definition of i. Since it is not found the linker flags an error. main() { printf("%d", out); } int out=100; Answer: Compiler error: undefined symbol out in function main. Explanation: The rule is that a variable is available for use from the point of declaration. Even though a is a global variable, it is not available for main. Hence an error. main() { extern out; printf("%d", out); } int out=100; Answer: 100 Explanation: This is the correct way of writing the previous program. main() { show(); } void show() {

44)

45)

46)

220 printf("I'm the greatest"); } Answer: Compier error: Type mismatch in redeclaration of show. Explanation: When the compiler sees the function show it doesn't know anything about it. So the default return type (ie, int) is assumed. But when compiler sees the actual definition of show mismatch occurs since it is declared as void. Hence the error. The solutions are as follows: 1. declare void show() in main() . 2. define show() before main(). 3. declare extern void show() before the use of show(). 47) main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); } Answer: 100, 100, 100, 2 114, 104, 102, 3 Explanation: The given array is a 3-D one. It can also be viewed as a 1-D array. 2 4 7 8 3 4 2 2 2 3 3 4 100 102 104 106 108 110 112 114 116 118 120 122 thus, for the first printf statement a, *a, **a give address of first element . since the indirection ***a gives the value. Hence, the first line of the output. for the second printf a+1 increases in the third dimension thus points to value at 114, *a+1 increments in second dimension thus points to 104, **a +1 increments the first dimension thus points to 102 and ***a+1 first gets the value at first location and then increments it by 1. Hence, the output. 48) main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; }

221 p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } } Answer: Compiler error: lvalue required. Explanation: Error is in line with statement a++. The operand must be an lvalue and may be of any of scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue. 49) main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); } Answer: 111 222 333 344 Explanation: Let us consider the array and the two pointers with some address a 0 1 2 3 4 100 102 104 106 108 p 100 102 104 106 108 1000 1002 1004 1006 1008 ptr 1000 2000

222 After execution of the instruction ptr++ value in ptr becomes 1002, if scaling factor for integer is 2 bytes. Now ptr – p is value in ptr – starting location of array p, (1002 – 1000) / (scaling factor) = 1, *ptr – a = value at address pointed by ptr – starting value of array a, 1002 has a value 102 so the value is (102 – 100)/(scaling factor) = 1, **ptr is the value stored in the location pointed by the pointer of ptr = value pointed by value pointed by 1002 = value pointed by 102 = 1. Hence the output of the firs printf is 1, 1, 1. After execution of *ptr++ increments value of the value in ptr by scaling factor, so it becomes1004. Hence, the outputs for the second printf are ptr – p = 2, *ptr – a = 2, **ptr = 2. After execution of *++ptr increments value of the value in ptr by scaling factor, so it becomes1004. Hence, the outputs for the third printf are ptr – p = 3, *ptr – a = 3, **ptr = 3. After execution of ++*ptr value in ptr remains the same, the value pointed by the value is incremented by the scaling factor. So the value in array p at location 1006 changes from 106 10 108,. Hence, the outputs for the fourth printf are ptr – p = 1006 – 1000 = 3, *ptr – a = 108 – 100 = 4, **ptr = 4. 50) main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); } Explanation: Here we have only one pointer to type char and since we take input in the same pointer thus we keep writing over in the same location, each time shifting the pointer value by 1. Suppose the inputs are MOUSE, TRACK and VIRTUAL. Then for the first input suppose the pointer starts at location 100 then the input one is stored as M O U S E \0 When the second input is given the pointer is incremented as j value becomes 1, so the input is filled in memory starting from 101. M T R A C K \0 The third input starts filling from the location 102 M T V I R T U A L \0 This is the final value stored . The first printf prints the values at the position q, q+1 and q+2 = M T V The second printf prints three strings starting from locations q, q+1, q+2 i.e MTVIRTUAL, TVIRTUAL and VIRTUAL. 51) main( ) {

223 void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); } Answer: g20fy Explanation: Since a void pointer is used it can be type casted to any other type pointer. vp = &ch stores address of char ch and the next statement prints the value stored in vp after type casting it to the proper data type pointer. the output is ‘g’. Similarly the output from second printf is ‘20’. The third printf statement type casts it to print the string from the 4 th value hence the output is ‘fy’. 52) main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); } Answer: ck Explanation: In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is ‘ck’. main() { int i, n; char *x = “girl”; n = strlen(x);

53)

224 *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } } Answer: (blank space) irl rl l Explanation: Here a string (a pointer to char) is initialized with a value “girl”. The strlen function returns the length of the string, thus n has a value 4. The next statement assigns value at the nth location (‘\0’) to the first location. Now the string becomes “\0irl” . Now the printf statement prints the string after each iteration it increments it starting position. Loop starts from 0 to 4. The first time x[0] = ‘\0’ hence it prints nothing and pointer value is incremented. The second time it prints from x[1] i.e “irl” and the third time it prints “rl” and the last time it prints “l” and the loop terminates. int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); } Answer: Runtime error: Abnormal program termination. assert failed (i<5), <file name>,<line number> Explanation: asserts are used during debugging to make sure that certain conditions are satisfied. If assertion fails, the program will terminate reporting the same. After debugging use, #undef NDEBUG and this will disable all the assertions from the source code. Assertion is a good debugging tool to make use of. main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); } Answer:

54)

55)

225 i = -1, +i = -1 Explanation: Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator). 56) What are the files which are automatically opened when a C file is executed? Answer: stdin, stdout, stderr (standard input,standard output,standard error).

57) what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR); Answer : a: The SEEK_SET sets the file position marker to the starting of the file. b: The SEEK_CUR sets the file position marker to the current position of the file. 58) main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute? Answer: First it checks for the leading white space and discards it.Then it matches with a quotation mark and then it reads all character upto another quotation mark. What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ; Answer & Explanation: fgets returns a pointer. So the correct end of file check is checking for != NULL. main() { main(); } Answer: Runtime error : Stack overflow. Explanation: main function calls itself again and again. Each time the function is called its return address is stored in the call stack. Since there is no condition to

59)

60)

226 terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error. 61) main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); } Answer: Compiler error (at line number 4): size of v is Unknown. Explanation: You can create a variable of type void * but not of type void, since void is an empty type. In the second line you are creating variable vptr of type void * and v of type void hence an error. main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); } Answer: 255 Explanation: In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof the name str2 indicates the name of the array whose size is 5 (including the '\0' termination character). The third sizeof is similar to the second one. main() { char not; not=!2; printf("%d",not); } Answer: 0 Explanation: ! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0. #define FALSE -1

62)

63)

64)

227 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); } Answer: TRUE Explanation: The input program to the compiler after processing by the preprocessor is, main(){ if(0) puts("NULL"); else if(-1) puts("TRUE"); else puts("FALSE"); } Preprocessor doesn't replace the values given inside the double quotes. The check by if condition is boolean value false so it goes to else. In second if -1 is boolean value true hence "TRUE" is printed.

65)

main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); } Answer: 1==1 is TRUE Explanation: When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE". main() { int y; scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 )

66)

228 printf("%d is a leap year"); else printf("%d is not a leap year"); } Answer: 2000 is a leap year Explanation: An ordinary program to check if leap year or not. 67) #define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); } Answer: Compiler error (in the line arr1 list = {0,1,2,3,4}) Explanation: arr2 is declared of type array of size 5 of characters. So it can be used to declare the variable name of the type arr2. But it is not the case of arr1. Hence an error. Rule of Thumb: #defines are used for textual replacement whereas typedefs are used for declaring new types.

68)

int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i);

229 } Answer: 30. After compilation is over the linker resolves it to global variable i (since it is the only variable visible there). main() { int i=-1. In the next block. -i. In printf first you just print the value of i. i is assumed of type int. so no storage space is allocated for it. In the innermost block i is declared as. So it prints i's value as 10. i has value 20 and so printf prints 20. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. i is declared as extern.*j). } Answer: 10 Explanation: The variable i is a block level variable and the visibility is inside that block only. Since the i is still allocated space.10 Explanation: '{' introduces new block and thus new scope. In the outermost block. printf("i = %d. So printf prints 30.20.-i). { int i=10.h> main() { 70) 71) . -i = 1 Explanation: -i is executed and this execution doesn't affect the value of i. 69) main() { int *j.i. const volatile unsigned which is a valid declaration. j=&i. } printf("%d". *j prints the value stored in i since j points i. } Answer: i = -1. -i = %d \n". #include<stdio. After that the value of the expression -i = -(-1) is printed.

now q is pointing to starting address of a.1 Explanation: p=&a[2][2][2] you declare only two 2D arrays. printf("%d". p=&a[2][2][2].. printf("%d. i value may be stored either in register or in memory.h> main() { register i=5. j = ++i. *q=***a starting address of a is assigned integer pointer.if you print *q meAnswer:it will print first element of 3D array.230 const int i=4. 73) 74) .2. int *p. #include<stdio.8} }. you cannot change the value of constant 72) #include<stdio.z.7. but you are trying to access the third 2D(which you are not declared) it will print garbage values..%d".*q. printf("%s %d".4}.h> main() { int a[2][2][2] = { {10. printf("%d %f".3.i+++j).6. main() { int i=5.++j).j=6. float j. } Answer: Compiler error Explanation: i is a constant. {5.*p.i). char j[]= "hello". } Answer: garbagevalue. i. } Answer: hello 5 Explanation: if you declare i as register compiler will treat it as ordinary integer and it will take integer value. *q=***a.*q).j.

struct point origin.0) 77) .x. } Answer: 2 Explanation: above all statements form a double circular linked list. ghi. } Answer: origin is(0. struct aaa *next. main() { struct aaa abc.y).*pp. abc.pp->x.next->next->prev->next->i.jkl. abc. abc.def.231 } Answer: 11 Explanation: the expression i+++j is treated as (i++ + j) 76) struct aaa{ struct aaa *prev. int i. main() { pp=&origin.ghi.prev=&def.next->next->prev->next->i this one points to "ghi" node the value of at particular node is 2.i=1.prev=&jkl.prev=&ghi.pp->y). struct point { int x.x).next=&def.i=0.prev=&abc.next=&jkl.(*pp).def.i=2. printf("%d". x=abc. int y.next=&abc. jkl.i=3. printf("origin is (%d%d)\n". def. printf("origin is(%d%d)\n".0) origin is(0. ghi. int x=100.next=&ghi. }. }.jkl.ghi.jkl.abc.def.(*pp).

.0002.e.232 Explanation: pp is a pointer to structure. printf("%c". getc(c).convert(z). } Answer: 0001.--i). } int _l_abc(int i) { return(i++). 10 will be returned. printf("%d\n". main() { char c=' '. main() { char *p. long *r. } Answer: 9 Explanation: return(i++) it will first return i and then increments. Note: Since structure point is globally declared x & y are initialized as zeroes 78) main() { int i=_l_abc(10)..x). p++. p=q=r=0. r++. printf("%p.q...%p".%p.. i. we can access the elements of the structure either with arrow mark or with indirection operator.p.x... } 79) 80) .0004 Explanation: ++ operator when applied to pointers increments address according to their corresponding data-types.. int *q. if((c>='a') && (c<='z')) x=convert(c).r). q++.

printf("%d". ptr+=3. } sum(num1. Explanation: argv[1] & argv[2] are strings.num2.num2) int num1.argv[2]). { return num1+num2. # include <stdio.3}. } Answer: Compiler error.h> aaa() { printf("hi"). getchar(). main() { int *ptr. char **argv) { printf("enter the character").*ptr). ptr=one_d. They are passed to the function sum without converting it to integer values. } bbb(){ 82) 83) .233 convert(z) { return z-32.2. } Answer: garbage value Explanation: ptr pointer is pointing to out of the array range of one_d. 81) main(int argc. sum(argv[1]. # include<stdio.h> int one_d[]={1. } Answer: Compiler error Explanation: declaration of convert and format of getc() are wrong.

85) #include<stdio. ptr[2]=ccc.0 Explanation: 86) .%d".j=0. Similarly ptr[1] and ptr[2] for bbb and ccc respectively.c". } Answer: contents of zzz.i++."r"). main() { int i =0.. ptr[2]() is in effect of writing ccc().j).c followed by an infinite loop Explanation: The condition is checked against EOF.234 printf("hello"). if(i && j++) printf("%d.. it should be checked against NULL. ptr[0]=aaa. ptr[1]=bbb.ptr[0] is assigned to address of the function aaa. while((i=fgetch(ptr))!=EOF) printf("%c". ptr=fopen("zzz. printf("%d.i.. ptr[2](). } ccc(){ printf("bye"). } main() { int (*ptr[3])(). } Answer: 0. char i.i).h> main() { FILE *ptr.j). } Answer: bye Explanation: ptr is array of pointers to functions of return type int.%d. since ptr[2] points to ccc.

the value of the accumulator is set 1000 so the function returns value 1000. } Answer: 1000 Explanation: Normally the return value from the function is through the information from the accumulator. } // If the inputs are 0.i). printf("%d".3 find the o/p Answer: 4--0 3--1 2--2 Explanation: Let us assume some x= scanf("%d".&i)-t the values during execution will be. i = abc(). 87) main() { int i. Hence. So the statement following the if statement is not executed.char x =1.2. Here _AH is the pseudo global variable denoting the accumulator. for ( t=4.int b = 20.y) 89) . } abc() { _AX = 1000.printf("%d\n".scanf("%d".b. 88) int i. t i x 4 0 -4 3 1 -2 2 2 0 main(){ int a= 0. main(){ int t. The values of i and j remain unchanged and get printed.235 The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. if(a.t--).i)) printf("%d--".&i)-t.1.x.char y =10.

i>-2. Thus the value of last variable y is returned to check in if. Since the both types doesn't match. "hello" will be printed. int abc(int a. signed is promoted to unsigned value. In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. } Answer: hello Explanation: The comma operator has associativity from left to right. float b. What are the following notations of defining functions known as? i. main(){ int * j. /* add a stmt here*/ } Answer: *k = &a Explanation: The argument of the function is a pointer to a pointer. Only the rightmost value is returned and the other values are evaluated and ignored.i--) printf("c aptitude"). } Explanation: i is an unsigned integer.float b) { /* some code */ } ii.236 printf("hello"). int abc(a. for(i=1. fun(&j). 90) main(){ unsigned int i. } void fun(int **k) { int a =0.b) int a. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop. Since it is a non zero value if becomes true so. void fun(int **). It is compared with a signed value. { /* some code*/ 91) 92) .

main(){ char a[100].237 } Answer: i.300). p++. p="%d\n". p++.val1. } process(pf. printf("%c". } main() { int process(). a++. a[0]='a'.*a). func(a.a[2]='c'. } Explanation: The base address is modified only in function and as a result a points to 'b' then after incrementing to 'c' so bc will be printed.process(func.6)).func(). { return( a= (a==b) ). it points to '%d\n' and 300 is printed. Kernighan & Ritche notation 93) main() { char *p.a[4]='d'. abc(a).3. printf("The value of process is %d !\n ".*a). printf(p-2. } abc(char a[]){ a++.b.b) int a. 94) 95) . } Answer: 300 Explanation: The pointer points to % since it is incremented twice and again decremented by 2.a[1]]='b'.val2) int (*pf) (). printf("%c". ANSI C notation ii.

{ return((*pf) (val1. return(ret). since 3 is not equal to 6.1. a==b returns 0. and since main() is recursively called. void main() { int k=ret(sizeof(float)).i). } Answer: The value if process is 0 ! Explanation: The function 'process' has 3 parameters . 3 for val1 and 6 for val2. a pointer to another function 2 and 3.++k). } int ret(int ret) { ret += 2..val2)).5.val2. if(--i){ main(). 96) void main() { static int i=5. printf("%d ". } Answer: Here value is 7 Explanation: 97) . printf("\n here value is %d". } } Answer: 0000 Explanation: The variable "I" is declared as static. therefore the function returns 0 which in turn is returned by the function 'process'.238 int val1. When this function is invoked from main. The function main() will be called recursively unless I becomes equal to 0. the following substitutions for formal parameters take place: func for pf. The formal parameters are substituted as 3 for a and 6 for b. integers. so the value of static I ie. hence memory for I will be allocated for only once. The function func has two integer parameters. This function returns the result of the operation performed by the function 'func'. as it encounters the statement. 0 will be printed every time the control is returned.

The ret is returned in main() it is printed after and preincrement. char a[]="\0". as ret is integer hence the value stored in ret will have implicit type conversion from float to int. printf("%u \n". the 6 will be printed. int gotit.++giveit).gotit=--giveit). printf("%u ".a)) printf("Ok here \n"). if(printf("%s\n". after the pre-increment in the printf statement.++i). } Answer: here in 3 6 Explanation: The char array 'a' will hold the initialized string. else printf("Forget it\n"). the function name and the argument name can be the same. whose length will be counted from 0 till the null character. the function ret() is called in which the sizeof(float) ie..239 The int ret(int ret).. Firstly. 4 is passed. } Answer: 0 65535 99) 100) void main() { int i. void main() { unsigned giveit=-1. after the first expression the value in ret will be 6. 98) void main() { char a[]="12345\0". } Answer: Ok here Explanation: . ie. Hence the 'I' will hold the value equal to 5. int i=strlen(a). printf("here in 3 %d\n".

k=k++. int *i=&integer. Explanation: Void pointer is a generic pointer type. i. } Answer: Garbage values. void main() { int i=i++. No pointer arithmetic can be done on it. Used when the exact pointer type will be known at a later point of time. Void pointers are normally used for. } Answer: i=1j=1k=1 .i. Garbage in is garbage out (GIGO).k). k). int integer=2. j and k are automatic variables and so they contain some garbage value. So expressions such as i = i++ are valid statements.240 Printf will return how many characters does it print. printf("%d". As a intermediate pointer type. printf(“i = %d j = %d k = %d”. 102) 103) void main() { static int i=i++. v=i.(int*)*v). thus "Ok here" is printed. j=j++. } Answer: Compiler Error. printf(“%d%d%d”. j.k=k++. 4. The i.j=j++. Explanation: An identifier is available to use in program code from the point of its declaration. Passing generic pointers to functions and returning such pointers. Hence printing a null character returns 1 which makes the if statement true. 6. 101) void main() { void *v. 5. We cannot apply indirection on type void*.j.

leading to an infinite loop..z.h> main() { int x. main() { unsigned int i=10. } } Answer: Garbage values Explanation: The inner printf executes first to print some garbage value.>=0 will always be true. So it encounters the break statement and comes out of the while statement.z. 104) void main() { while(1){ if(printf("%d".i). This value is assigned to x.y=2. printf("%d %d ". 104) . } Answer: 10 9 8 7 6 5 4 3 2 1 0 65535 65534….a.241 Explanation: Since static variables are initialized to zero by default. Explanation: Since i is an unsigned integer it can never become negative. while(i-->=0) printf("%u ". else continue. The condition reduces to if (x) or in other words if(0) and so z goes uninitialized. So the expression i-.x).printf("%d"))) break. Still the outer printf prints something and so returns a non-zero value. if(x=y%2) z=2. 105) #include<conio. a=2. The printf returns no of characters printed and this value also cannot be predicted. } Answer: Garbage-value 0 Explanation: The value of y%2 is 0.

242 Thumb Rule: Check all control paths to write bug free code. When the value of i becomes 0 it comes out of while loop. } Answer: 1 Explanation: Note the semicolon after the while statement. } Answer: 10 Explanation: The macro expands and evaluates to as: x+2*y-1 => x+(2*y)-1 => 10 main() { unsigned int i=65000. 106) main() { int a[10].b) a*b main() { int x=3. } Answer: 4 Explanation: *a and -*a cancels out. while(i++!=0).prod(x+2.i). Due to post-increment on i the value of i while printing is 1. 109) main() { int i=0.i). } Answer: -1 108) .*a+1-*a+3).y=4.y-1)). printf("%d". while(+(+i--)!=0) i-=i++. printf("%d". printf("%d". printf("%d". The result is as simple as 1 + 3 = 4 ! 107) #define prod(a.

243 Explanation: Unary + is the only dummy operator in C.f<<2). It means that the function follows Pascal argument passing mechanism in calling the functions. } Answer: Compiler error: unknown type integer Compiler error: undeclared function write Explanation: Pascal keyword doesn’t mean that pascal code can be used. The value –1 is printed due to the postdecrement operator.k). printf("%lf\n". enum{i=10.++k).int). } Answer: Line no 5: Error: Lvalue required Line no 6: Cannot apply leftshift to float Line no 7: Cannot apply mod to float Explanation: Enumeration constants cannot be modified.i). Bit-wise operators and % operators cannot be applied on float values. void pascal f(int. So it has no effect on the expression and now the while loop is.int k) { printf(“%d %d %d”. while(i--!=0) which is false and so breaks out of while loop.j.i++). 110) main() { int i=10. 113) main() { float f=5. . fmod() is to find the modulus values for floats as % operator is for ints.i.k=50}.i++.fmod(f.integer :k) { write(i. printf(" %d". printf("%lf\n". k).int j.f%g).g)). j. 111) void pascal f(int i. printf("%f\n". } void pascal f(integer :i.int.g=10. printf("%d\n". so you cannot apply ++.j=20. f(i++.integer:j.

i++. The inner loop executes to increment the value from 0 to 127 (the positive range of char) and then it rotates to the negative value of -128.i>=0. 112). What is the output of the program given below main() { signed char i=0. printf(" %d". } main() { int i=10. printf("%d\n". cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.i++. j. for(. k). The condition in the for loop fails and so comes out of the for loop. for(.i). } Answer -128 Explanation Notice the semicolon at the end of the for loop. It prints the current value of i that is -128.i++). 113) main() { unsigned char i=0.i>=0. f(i++.i++) . } Answer: 10 11 12 13 12 11 10 13 Explanation: Pascal argument passing mechanism forces the arguments to be called from left to right.int j. f(i++. } . THe initial value of the i is set to 0.244 } void cdecl f(int i.i).i).i.i). printf("%d\n". printf(" %d\n".int k) { printf(“%d %d %d”.i++) .i++). i=10.

} . error. g1=1. Apply clock-wise rule to find the meaning of this definition. 114) main() { char i=0.245 Answer infinite loop Explanation The difference between the previous question and this one is that the char is declared to be unsigned. So the i++ can never yield negative value and i>=0 never becomes false so that it can come out of the for loop. it goes to infinite loop. 116). If the implementation treats the char to be signed by default the program will print –128 and terminate. printf("%d\n". Find what does it mean? int (*x)[10]. printf("%d".g1).i++) . Rule: You can write programs that have implementation dependent behavior. 115) Is the following statement a declaration/definition. exception. Answer Definition. Explanation: The detail if the char is signed/unsigned by default is implementation dependent.}error. What is the output for the program given below typedef enum errorType{warning. But dont write programs that depend on such behavior. On the other hand if it considers char to be unsigned by default. x is a pointer to array of(size 10) integers. for(.i). } Answer: Behavior is implementation dependent. main() { error g1.i>=0.

error. g1=error. One means that it is a enumerator constant with value 1. // which error it refers in each case? When the compiler can distinguish between usages then it will not issue error (in pure technical terms. exception. An extra comma is valid and is provided just for programmer’s convenience.error =1.error). names can only be overloaded in different namespaces). typedef struct error{int warning. g1. } 1 Explanation The three usages of name errors can be distinguishable by the compiler at any instance.}error.g1. exception. error. Note: the extra comma in the declaration. error. This error can be used only by preceding the error by struct kayword as in: struct error someError. This can be used only after . error.}error. exception.error). typedef struct error{int warning.}error.246 Answer Compiler error: Multiple declaration for error Explanation The name error is used in the two meanings. printf("%d". enum errorType{warning. The another use is that it is a type name (due to typedef) for enum errorType. exception.}error.g1. error. This can be used to define variables without using the preceding struct keyword as in: error g1. Given a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used: error g1.error =1. so valid (they are in different namespaces). exception. printf("%d".} is not an error. main() { error g1. 117) typedef struct error{int warning. Typedef struct error{int warning. (dot) or -> (arrow) operator preceded by the variable name as in : g1. Answer .

It reduces the readability of the code. What is the output for the following program . Possible doesn’t mean that we should use it! 118) #ifdef something int some=0. some . effectively removed from the source code. printf("%d %d\n". 119) #if something == 0 int some=0.thing). #endif main() { int thing = 0.thing). it is perfectly legal and valid. } Answer 00 Explanation This code is to show that preprocessor expressions are not the same as the ordinary expressions. 120). printf("%d %d\n". } Answer: Compiler error : undefined symbol some Explanation: This is a very simple example for conditional compilation. Note This code is given here to just explain the concept behind. some .247 Since the compiler can perfectly distinguish between these three usages. The name something is not already known to the compiler making the declaration int some = 0. If a name is not known the preprocessor treats it to be equal to zero. #endif main() { int thing = 0. In real programming don’t use such overloading of names.

Similarly. –1 is represented in unsigned value as all 1’s and so both are equal. printf("%d\n". N dimensional arrays are made up of (N-1) dimensional arrays. ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ). Again arr2D[0] is the another way of telling *(arr2D + 0). *arr2D refers to the start of the first 1D array (of 3 integers) that is the same address as arr2D.248 main() { int arr2D[3][3]. adding a zero doesn’t change the value/meaning. . } Answer 1 Explanation This is due to the close relation between the arrays and pointers. *arr2D is nothing but *(arr2D + 0). Since both parts of the expression evaluates to true the result is true(1) and the same is printed. arr2D arr2D[1] arr2D[2] arr2D[3] The name arr2D refers to the beginning of all the 3 arrays. 121) void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”). So the expression (arr2D == *arr2D) is true (1). } Answer You can answer this if you know how values are represented in memory Explanation ~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. arr2D is made up of a 3 single arrays that contains 3 integers each . So the expression (*(arr2D + 0) == arr2D[0]) is true (1).

} Answer: b main() { int i=5. } Answer x = 20 y = 10 Explanation This is one way of swapping two values.y). printf("%d". Compiler error: Lvalue required in function main ++i yields an rvalue. } main() { int x=10. printf("x= %d y = %d\n".y=20. For postfix ++ to operate an 124) . swap(&x. Parenthesis just works as a visual clue for the reader to see which expression is first evaluated. Simple checking will help understand this. char c.++i++).*b=*a-*b.&y).249 122) int swap(int *a. 125) main() { char *p = “ayqm”. 123) main() { char *p = “ayqm”. printf(“%c”. printf(“%c”.c). } Answer: Explanation: lvalue is required.int *b) { *a=*a+*b. c = ++*p++. } Answer: b Explanation: There is no difference between the expression ++*(p++) and + +*p++.x.*a=*a-*b.++*(p++)).

So it results in printing "bye". p[1] = 'c'. printf(p. } Answer: bye Explanation: int (* ptr[3])() says that ptr is an array of pointers to functions that takes no arguments and returns the type int.} iny ccc(){printf(“bye”). because == is of higher precedence than = operator. 127) main() { int i=5.65). ptr[1] = bbb. Hence the result. Similarly. ptr[0] = aaa. the other two array elements also get initialized with the addresses of the functions bbb and ccc.i=++i ==6). ptr[2]().} int bbb(){printf(“hello”). Since ptr[2] contains the address of the function ccc. In the inner expression. By the assignment ptr[0] = aaa. it means that the first function pointer in the array is initialized with the address of the function aaa. 128) main() { char p[ ]="%d\n". the call to the function ptr[2]() is same as calling ccc(). ++i is equal to 6 yielding true(1). printf(“%d”.250 126) int aaa() {printf(“Hi”). } Answer: A Explanation: . } Answer: 1 Explanation: The expression can be treated as i = (++i==6).} main() { int ( * ptr[3]) (). ptr[2] =ccc.

’m’. } Answer: No output Explanation: Ending the string constant with \0 explicitly makes no difference. “%c\n”.’\0’}.(a). char str2[] = {‘s’. So “some” and “some\0” are equivalent.’e’. Since str1 doesn’t have null termination. 129) void ( * abc( int. the same gets printed. Explanation: Apply the clock-wise rule to find the result. void ( *def) () ) ) ().”some\0”)) printf(“Strings are not equal\n”). hence the result. ‘\0’ is not appended automatically to the string. an integer variable. it treats whatever the values that are in the following positions as part of the string until it randomly reaches a ‘\0’. 132) main() { 131) .’o’. } Answer: “Strings are not equal” “Strings are not equal” …. Answer:: abc is a ptr to a function which takes 2 parameters . while (strcmp(str1. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’.str2)) printf(“Strings are not equal\n”). the return type of the function is void.’m’.’o’. main() { char str1[] = {‘s’.’e’}.251 Due to the assignment p[1] = ‘c’ the string becomes. So. a ptrto a funtion which returns void. Explanation: If a string constant is initialized explicitly with characters. 130) main() { while (strcmp(“some”.(b). So str1 and str2 are not the same. strcmp returns 0 (false) hence breaking out of the while loop.

Inside the while loop the conditional operator evaluates to false.j)?i:j:j. executing i--. mptr = (int*)malloc(sizeof(int)). whereas calloc returns the allocated memory space initialized to zeros. for (.252 int i = 3.i++=0. void main() { static int i.) printf(“%d”. j = i. while(i<=10) (i>2)?i++:i--.1). printf(“%d”. } Answer: garbage-value 0 Explanation: The memory space allocated by malloc is uninitialized. main() { int i=10. } Answer: 32767 Explanation: Since i is static it is initialized to 0.j).*mptr). printing the i value. int *cptr = (int*)calloc(sizeof(int). printf("%d %d". } Answer: 10 10 134) 135) . i). *cptr. } Answer: Explanation: Compiler Error: Lvalue required. 133) void main() { int *mptr. j?(i. comes out of the while loop.*cptr). printf(“%d”. The while condition becomes false and hence.i). This continues till the integer value rotates to positive value (32767).j=20.i. As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation. printf(“%d”.

2. The inner expression (j&&10) evaluates to 1 because j==10.253 Explanation: The Ternary operator ( ? : ) is equivalent for if-then-else statement. 'const' applies to char * rather than 'a' ( pointer to a constant char ) *a='F' : illegal a="Hi" : legal 2. 136) 1.j) j = i.i. else j = j. Answer: 1. -Differentiate the above declarations. char* const a.j=10. const char *a. 3. printf("%d %d". i=i&=j&&10. } Answer:1 10 Explanation: The expression can be written as i=(i&=(j&&10)).j) { if(i. 'const' applies to 'a' rather than to the value of a (constant pointer to char ) *a='F' a="Hi" 3. i is 5. Hence the result. 138) main() { : legal : illegal . 137) main() { int i=5. } else j = j.j). So the question can be written as: if(i. char const *a. Same as 1. i = 5&1 is 1.

printf("Address of a = %d". printf("Value of a = %d". So the remaining expression is not evaluated and so the value of i remains the same.&a). false && (anything) => false where (anything) will not be evaluated.5.a). default : printf("0"). j = j || i++ && printf("YOU CAN"). Because it is followed by || and true || (anything) => true where (anything) will not be evaluated. } } Answer: Compiler Error: switch expression not integral Explanation: Switch statements can be applied only to integral types. case 2: printf("2"). 141) main() . the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated. when any of the operands become false. 139) main() { register int a=2. printf("%d %d". j is not equal to zero itself means that the expression’s truth value is 1. i. Similarly when && operator is involved in an expression. } Answer: Compier Error: '&' on register variable Rule to Remember: & (address of ) operator cannot be applied on register variables. } Answer: 41 Explanation: The boolean expression needs to be evaluated only till the truth value of the expression is not known.j=7. j). 140) main() { float i=1.254 int i=4. switch(i) { case 1: printf("1").

printf("%d\n". sizeof(*p) = %d. sizeof(*p).*f2. { int i=20. *f2+=*f2+=a+=2. Here the sizeof(a) where a is the character array and the size of the array is 5 because the . printf("%d\n". sizeof(*p) = 1.*f1. sizeof(p). strlen(a) = 4 Explanation: sizeof(p) => sizeof(char*) => 2 sizeof(*p) => sizeof(char) => 1 Similarly.*f2). strlen(p)). strlen(a)).i). } } Answer: Linker Error : Unresolved external symbol i Explanation: The identifier i is available in the inner block and so using extern has no use in resolving it. sizeof(a) => size of the character array => 5 When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable. printf("\n sizeof(p) = %d. printf("\n sizeof(a) = %d.255 { extern i. printf("\n%d %d %d". f1=f2=&a. 143) main() { char *p="GOOD". strlen(p) = %d". So changes through f1 and f2 ultimately affects only the value of a. } Answer: 16 16 16 Explanation: f1 and f2 both refer to the same memory location a.i).*f1. } Answer: sizeof(p) = 2. 142) main() { int a=2. char a[ ]="GOOD".a. sizeof(a). strlen(p) = 4 sizeof(a) = 5. strlen(a) = %d".5.

int i. type) sizeof(array)/sizeof(type) main() { int arr[10]. DIM(arr)).a+1.j++) printf("%d\t%d\t%d\t%d\n". The return statement becomes.*(*(i+p)+j).8.i++) { for(j=0.7.4. int DIM(int array[]) { return sizeof(array)/sizeof(int ).j<3. *(*(j+p)+i). DIM(arr.i<3.*(*(p+j)+i)). printf(“The dimension of the array is %d”.6.256 space necessary for the terminating NULL character should also be taken into account.5. printf(“The dimension of the array is %d”.j.3. The macro expands to sizeof(arr)/sizeof(int) => 10 * sizeof(int) / sizeof(int) => 10. sizeof(int *)/ sizeof(int) that happens to be equal in this case. int)). } } 145) 146) . } Answer: 10 Explanation: The size of integer array of 10 elements is 10 * sizeof(int). So the argument is equivalent to int * array (this is one of the very few places where [] and * usage are equivalent). 144) #define DIM( array.*(*(p+i)+j). } Answer: 1 Explanation: Arrays cannot be passed to functions as arguments and only the pointers can be passed. } main() { int arr[10].a+2}.9}. main() { static int a[3][3]={1. static *p[]={a. for(i=0.2.

void swap() which means the swap can take any number of arguments.&y). void swap(). that has two arguments. } Answer: x=10 y=8 Explanation: Using ^ like this is a way to swap two variables without using a temporary variable and that too in a single statement. means that swap is a function that may take any number of arguments (not no arguments) and returns nothing. In that style. Inside main(). .y=8. So naturally the declaration for swap will look like. void swap() int *a. *a ^= *b. the swap function will be defined as follows.x.y).&y). This convention is historically due to pre-ANSI style (referred to as Kernighan and Ritchie style) style of function declaration.257 Answer: 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9 Explanation: *(*(p+i)+j) is equivalent to p[i][j]. *a ^= *b. int *b { *a ^= *b. *b ^= *a. int *b) { *a ^= *b. } where the arguments follow the (). *b ^= *a. int x=10. swap(&x. 147) main() { void swap(). printf("x=%d y=%d". } void swap(int *a. So this doesn’t issue a compiler error by the call swap(&x.

The integer value 258 is stored in memory as: 00000001 00000010. } Answer: 21 Explanation: The integer value 257 can be represented in binary as. So the integer corresponding to it is 00000010 00101100 => 556. 149) main() { int i = 258. *((char*)iPtr). char *ptr = &i. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. Remember that the INTEL machines are ‘small-endian’ machines. int *iPtr = &i. *((char*)iPtr+1) ). *((char*)iPtr). printf("%d". 151) #include <stdio. 150) main() { int i=300. *++ptr=2. 00000001 00000001. Small-endian means that the lower order bytes are stored in the higher memory addresses and the higher order bytes are stored in lower addresses. 00000001 00000001. *((char*)iPtr+1) ). printf("%d %d". It is stored in memory (small-endian) as: 00101100 00000001. } Answer: 556 Explanation: The integer value 300 in binary notation is: 00000001 00101100.h> main() . } Answer: 11 Explanation: The integer value 257 is stored in the memory as. printf("%d %d". so the individual bytes are taken by casting it to char * and get printed.i). int *iPtr = &i.258 148) main() { int i = 257.

year.month. char least = 127.dob.least). struct date { int day. stud.year). scanf("%s%d%d%d". struct student { char name[30]. &student. }. So the value of ‘str’ is less than that of ‘least’. struct date dob. &student. The compiler doesn’t have the definition of date structure (forward reference is not allowed in C in this case) so it issues an error.rollno. }stud.dob. &student.259 { char * str = "hello". main() { struct student { char name[30]. 153) 154) . main() { struct date. 152) Declare an array of N pointers to functions returning pointers to functions returning pointers to characters? Answer: (char*(*)( )) (*ptr[N])( ). So the value of ‘least’ finally is 0. } Answer: Compiler Error: Undefined structure date Explanation: Inside the struct definition of ‘student’ the member of type struct date is given. } Answer: 0 Explanation: After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘\0’.month. printf("%d".day.dob. while (*ptr++) least = (*ptr<least ) ?*ptr :least. char * ptr = str.

So it prints the last record again. FILE *fp = fopen(“somefile. int foo(int *arr[]) and 4. hence comes out of the while loop. while(!feof(fp)) { fread(&stud. &student. After this only the condition feof(fp) becomes false. }stud.month.day.rollno. }. } } Explanation: fread reads 10 records and prints the names successfully.260 struct date dob.dat” but the following program printed 11 names. It will return EOF only when fread tries to read another record and fails reading EOF (and returning EOF).dat”.dob.year. 155) There were 10 records stored in “somefile. int foo(int *arr[2]) Answer: No Explanation: 156) .year). Is there any difference between the two declarations. puts(stud.dob. What went wrong? void main() { struct student { char name[30]. sizeof(stud). 1 . scanf("%s%d%d%d". &student. stud. } Answer: Compiler Error: Undefined structure date Explanation: Only declaration of struct date is available inside the structure definition of ‘student’ but to have a variable of type struct date the definition of the structure is required.name). rollno[6]. struct date { int day. &student. }stud. 3. fp).”r”).month.dob.

} Answer & Explanation: If the body of the loop never executes p is assigned no address. 157) What is the subtle error in the following code segment? void fun(int n. } Answer & Explanation: assert macro should be used for debugging and finding out bugs. In assert. *p = 0. The numbers that are allowed inside the [] is just for more readability. the experssion involves side-effects. So the behavior of the code becomes different in case of debug version and the release version thus leading to a subtle bug. return s. A plain if and the corresponding remedy statement has to be given. Rule to Remember: Don’t use expressions that have side-effects in assert statements. So there is no difference between the two declarations. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program). The check s != NULL is for error/exception handling and for that assert shouldn’t be used. assert(s != NULL). while(i++<n) p = &arr[i].261 Functions can only pass pointers and not arrays. 158) 159) . What is the hidden bug with the following statement? assert(val++ != 0). Answer & Explanation: Assert macro is used for debugging and removed in release version. int arr[]) { int *p=0. What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100). int i=0.

__FILE__. This type of pointer in which the non-availability of the implementation of the referenced location is known as 'incomplete type'. #define assert(cond) if(!(cond)) \ (fprintf(stderr. "assertion failed: \ %s. line %d \n". line %d \n". Hence nothing is printed. #define assert(cond) ((cond)?(0): (fprintf (stderr. // set the value of memory location pointed by i. "assertion failed: %s.__LINE__).__LINE__). else printf("This statement becomes else for if in assert macro"). 161) . "assertion failed: %s. The solution is to use conditional operator instead of if statement.#cond.__LINE__). if(i==0) assert(i < 100). #define assert(cond) { \ if(!(cond)) \ (fprintf(stderr.#cond. abort()) void main() { int i = 10. // i points to the address 400 *i = 0. file %s. file %s.\ __FILE__. line %d \n". file %s.\ __FILE__. } Answer: No output Explanation: The else part in which the printf is there becomes the else for if in the assert macro.#cond. abort()) \ } 162) Is the following code legal? struct a { int x.262 160) void main() { int *i = 0x400. } Answer: Undefined behavior Explanation: The second statement results in undefined behavior because it points to some location whose value may not be available for modification. abort())) Note: However this problem of “matching with nearest else” cannot be solved by the usual method of placing the if statement inside a block like this.

Explanation: *b is a pointer to type struct a and so is legal. aType *b. }. struct a *b. }aType Answer: No Explanation: The typename aType is not known at the point of declaring the structure (forward references are not made for typedefs). the size of the pointer to a structure even before the size of the structure is determined(as you know the pointer to any type is of same size). Answer: Yes Explanation: The typename aType is known at the point of declaring the structure. because it is already typedefined. struct a { int x. } Answer: No Explanation: Is it not legal for a structure to contain a member that is of the same type as in this case. Is the following code legal? typedef struct a aType. Is the following code legal? typedef struct a { int x. This type of structures is known as ‘self-referencing’ structure. Because this will cause the structure declaration to be recursive without end. 164) 165) . aType *b. 163) Is the following code legal? struct a { int x. The compiler knows.263 struct a b. } Answer: Yes.

// or the more curt one 167) 168) 169) . sizeof(inputString). Which version do you prefer of the following two. } Answer : sizeof (void *) = 2 sizeof (int *) = 2 sizeof (double *) = 2 sizeof(struct unknown *) = 2 Explanation: The pointer to any type is of same size. This is known as ‘incomplete types’. fp) Answer & Explanation: The second one is better because gets(inputString) doesn't know the size of the string passed and so.264 166) Is the following code legal? void main() { typedef struct a aType. is encountered body of struct a is not known. sizeof(struct unknown *)). sizeof(double *)). 1) printf(“%s”. more than 100 chars) the charactes will be written past the input string. aType *b. struct a { int x. aType someVariable. void main() { printf(“sizeof (void *) = %d \n“. printf(“sizeof (int *) = %d \n”. sizeof(int *)). typedef struct a aType. }. char inputString[100] = {0}.str). if a very big input (here. printf(“sizeof(struct unknown *) = %d \n”. } Answer: No Explanation: When the declaration. When fgets is used with stdin performs the same operation as gets but is safe. printf(“sizeof (double *) = %d \n”. sizeof( void *)). To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString.

If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. int k = *ip/*jp. the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. 170) 171) 172) . for(ch=0. int k = *ip/ *jp. but by the “maximum munch” rule. j=2. Answer: Yes Explanation: The pointer ptr will point at the integer in the memory location 0x400. // give space explicity separating / and * //or int k = *ip/(*jp). // put braces to force the intention will solve the problem. printf(“%d”. Explanation: The programmer intended to divide two integers. If the str contains any format characters like %d then it will result in a subtle bug. void main() { char ch. } Answer: Compiler Error: “Unexpected end of file in comment started in line 5”. ptr = (int *) 0x400.ch<=127.265 2) printf(str). int *ip= &i. *jp = &j. Is this code legal? int *ptr. To force what is intended by the programmer. ch. Thus ch is always smaller than 127. ch). void main() { int i=10.k). } Answer: Implementaion dependent Explanation: The char type may be signed or unsigned by default.ch++) printf(“%c %d \n“. Answer & Explanation: Prefer the first one.

int i=20.a). j=k=&a. const volatile unsigned i=30. void *k. j++. main() { int a=10. 176) main() { { { } extern int i. k++. printf("%s". } Answer: Compiler error: Cannot increment a void pointer Explanation: Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type.k). No pointer arithmetic can be done on it and you cannot apply indirection operator (*) on void pointers. main() { char a[4]="HELL".*j. } Answer: HELL%@!~@!@???@~~! Explanation: The character array has the memory just enough to hold the string “HELL” and doesnt have enough space to store the terminating null character. So it prints the HELL correctly and continues to print garbage values till it accidentally comes across a NULL character. 174) 175) . printf("%d".a).j. printf("%s". } Answer: Compiler error: Too many initializers Explanation: The array a is of size 4 but the string constant requires 6 bytes to get stored. printf("\n %u %u ".i).266 173) main() { char a[4]="HELLO".

’i’. } int main() { puts(someFun1()). 177) Printf can be implemented by using __________ list. Explanation: Both the functions suffer from the problem of dangling pointers. } printf("%d". return temp. } Answer: string constant Explanation: The program suffers no problem and gives the output correctly because the character constants are stored in code/data area and not allocated in stack. return temp. return temp. ‘t’. } int i. Answer: Variable length argument lists 178) char *someFun() { char *temp = “string constant". puts(someFun2()). 179) char *someFun1() { char temp[ ] = “string". } Answer: Garbage values.i).267 printf("%d". so this doesn’t lead to dangling pointers. } char *someFun2() { char temp[ ] = {‘s’. This is created dynamically as the function is called. so is also . } int main() { puts(someFun()).’g’}.’n’.’r’. In someFun1() temp is a character array and so the space for it is allocated in heap and is initialized with character string “string”.i).

The function someFun2() also suffers from the same problem but the problem can be easily identified in this case. .268 deleted dynamically on exiting the function so the string data is not available in the calling function main() leading to print some garbage values.

269 C++ Aptitude and OOPS C++ Aptitude and OOPS Note : All the programs are tested under Turbo C++ 3. 4. It is assumed that.  Program is compiled using Turbo C/C++ compiler.  The underlying machine is an x86 based system. } ~Sample() { delete ptr. Sample(int i) { ptr = new int(i). } }. The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).0.PrintVal(). void SomeFunc(Sample x) { cout << "Say i am in someFunc " << endl. } Answer: Say i am in someFunc Null pointer assignment(Run-time error) Explanation: .0 compilers. } int main() { Sample s1= 10. SomeFunc(s1). s1. } void PrintVal() { cout << "The value is " << *ptr. 1) class Sample { public: int *ptr.5 and Microsoft VC++ 6.  Programs run under Windows environment.

2) Which is the parameter that is added to every non-static member function when it is called? Answer: ‘this’ pointer 3) class base { public: int bval. cout<<endl. i<size. base(){ bval=0. class deri:public base { public: int dval.5). So when PrintVal is called it meets up with ptr that has been freed.270 As the object is passed by value to SomeFunc the destructor of the object is called when the control returns from the function.5). } int main() { base BaseArr[5]. SomeFunc(DeriArr. deri DeriArr[5]. SomeFunc(BaseArr.} }. } Answer: . void SomeFunc(base *arr.} }. while returning from the function. i++. } because when we pass objects by refernece that object is not destroyed. deri(){ dval=1.The solution is to pass the Sample object by reference to SomeFunc: void SomeFunc(Sample &x) { cout << "Say i am in someFunc " << endl.int size) { for(int i=0.arr++) cout<<arr->bval.

So when arr++ is met. the size of base class object is taken into consideration and is incremented by sizeof(int) bytes for bval (the deri class objects have bval and dval as members and so is of size >= sizeof(int)+sizeof(int) ). SomeFunc(&baseObject). SomeFunc() knows nothing about this and just treats the pointer as an array of base class objects.} }. SomeFunc expects a pointer to a base class. } Answer: from base from base Explanation: As we have seen in the previous case.271 00000 01010 Explanation: The function SomeFunc expects two arguments.The first call of someFunc calls it with an array of bae objects. it treats the argument only as a base class pointer and the corresponding base function is called. deri deriObject. void SomeFunc(base *baseObj) { baseObj->baseFun(). So the derived class pointer is promoted to base class pointer and the address is sent to the function. class deri:public base { public: void baseFun(){ cout<< "from derived"<<endl.} }. When Somefunc is called the second time the argument passed is the pointeer to an array of derived class objects and not the array of base class objects. 5) class base { .The first one is a pointer to an array of base class objects and the second one is the sizeof the array. SomeFunc(&deriObject). 4) class base { public: void baseFun(){ cout<<"from base"<<endl. so it works correctly and prints the bval of all the objects. Since a pointer to a derived class object is passed. But that is what the function expects to be sent. } int main() { base baseObject.

*/ const int size = 5.} }. whereas references can only be initialized. So this code issues an error. ra = a. pa = &a.} }. So the function corresponding to the derived class object is called. } /* Answer : Compiler Error: 'ra'. } Answer: from base from derived Explanation: Remember that baseFunc is a virtual function. void SomeFunc(base *baseObj) { baseObj->baseFun(). deri deriObject.reference must be initialized Explanation : Pointers are different from references. *pa. } int main() { base baseObject. SomeFunc(&baseObject). SomeFunc(&deriObject). One of the main differences is that the pointers can be both initialized and assigned. void print(int *ptr) . cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra .272 public: virtual void baseFun(){ cout<<"from base"<<endl. That means that it supports runtime polymorphism. &ra. class deri:public base { public: void baseFun(){ cout<< "from derived"<<endl. void main() { int a.

} void print(int ptr[size]) { cout<<ptr[0]. both the functoins have the same signature and so cannot be overloaded.5}. } void main() { int a[size] = {1. only pointers (for arrays.3. print(b).~some()' explicitly calls the . print(a). s. In other words.~some(). Here 's.4. } }. base addresses) can be passed.2. } /* Answer: some's destructor some's destructor Explanation: Destructors can be called explicitly.273 { cout<<ptr[0]. } /* Answer: Compiler Error : function 'void print(int *)' already has a body Explanation: Arrays cannot be passed to functions. void main() { some s. int *b = new int(size). So the arguments int *ptr and int prt[size] have no difference as function arguments. */ class some{ public: ~some() { cout<<"some's destructor"<<endl.

} /*class fig3d : public fig2d { int dim3. destructor of s is called again. */ #include <iostream.h> class fig2d { int dim1. }. }. // fig3d obj2.274 destructor of 's'. public: fig2d() { dim1=5. public: fig3d() { dim3=7. rhs<<this->dim3. } /* Answer : . obj1 << cout. void fig3d::operator<<(ostream &rhs) { fig2d::operator <<(rhs). } */ void main() { fig2d obj1. When main() returns. dim2=6.} virtual void operator<<(ostream &rhs). void fig2d::operator<<(ostream &rhs) { rhs <<this->dim1<<" "<<this->dim2<<" ". // obj2 << cout.} virtual void operator<<(ostream & rhs). hence the result. int dim2.

a2. but it doesn't mean that 'cout' is not possible to be overloaded as member function. where friend's are not inherited. } else{ cout<<"The both are different\n". public: complex() : re(1). } Answer : Runtime Error: Stack Overflow Explanation : Just like normal functions.5) {} . */ class opOverload{ public: bool operator==(opOverload temp). class complex{ double re. a1= =a2. }. This program just illustrates that point. leading to an infinite loop. This is as opposed to global friend functions.275 56 Explanation: In this program. double im. and this becomes available to be overrided. Overloading << as virtual member function becomes handy when the class in which it is overloaded is inherited. 'cout' is implemented as global function. } } void main(){ opOverload a1. Normally. the << operator is overloaded with ostream as argument. return true. bool opOverload::operator==(opOverload temp){ if(*this == temp ){ cout<<"The both are same objects\n". return false. by calling the operator == function recursively.im(0. This enables the 'cout' to be present at the right-hand-side. operator functions can be called recursively.

276 bool operator==(complex &rhs).} void print() { cout<<re. bool complex::operator == (complex &rhs){ if((this->re == rhs. void main(){ complex c3. double im.} }. class complex{ double re.print(). double i=5. } Answer: 5.But the compiler instead of giving an error sees the conversion function and converts the user defined object to standard object and prints some garbage value. else return false.im=n. c3.5 Explanation: . complex(int m.im)) return true. } int main(){ complex c1. cout<<im.im(0) {} complex(double n) { re=n.im=n.which he has not defined for his lass. cout<< c1.}.int n) { re=m.re) && (this->im == rhs. c3 = i. } Answer : Garbage value Explanation: The programmer wishes to print the complex object using output re-direction operator. public: complex() : re(0). operator int(){} }.

void main() { int a. } Answer : Compiler Error: 'ra'. base *bp = (base*)dp. i<3. } }. } 2) Justify the use of virtual constructors and destructors in C++. the double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue. for (int i=0. One of the main differences is that the pointers can be both initialized and assigned. So this code issues an error.reference must be initialized Explanation : Pointers are different from references. double is defined.277 Though no operator= function taking complex. ra = a. class deri{ public : out() { cout<<"deri ". } }. class base { public : out() { cout<<"base ". &ra. *pa. whereas references can only be initialized. cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra . void main() { deri dp[3].i++) (bp++)->out(). . Try it Yourself 1) Determine the output of the 'C++' Codelet. pa = &a.

} }. value2 = 10. mutable int value2. } }. public: something(){ st = new char[10].278 3) Each C++ object possesses the 4 member fns. } ~something() { delete str. public : void fun(int val) const{ ((temp*) this)->value1 = 10. 5) Inheritance is also known as -------. . 8) Is there anything wrong with this C++ class declaration? class temp { int value1. What are those 4 functions? 4) What is wrong with this class declaration? class something { char *str.(which can be declared by the programmer explicitly or by the implementation if they are not available). Containership as relationship.relationship. ________ 6) When is it necessary to use member-wise initialization list (also known as header initialization list) in C++? 7) Which is the only operator in C++ which can be overloaded but NOT inherited.

.  output iterators. It’s jargon for plain templates. Furthermore. Answer: It is a feature in c++ to minimize name collisions in the global name space. an operation that modifies the state of an object. there is a fair chance that you will be unable to compile or link the program because of name clashes. 2. There are five categories of iterators:  input iterators. also called a modifying function is a member function that changes the value of at least one data member. What is an Iterator class? Answer: A class that is used to traverse through the objects maintained by a container class. For example. Answer: A using declaration makes it possible to use a name from a namespace without the scope operator. What is a modifier? Answer: A modifier. . Define namespace. Differentiate between a template class and class template.279 1. What is the use of ‘using’ declaration. If you try to use many class libraries at the same time. 5. What is an accessor? Answer: An accessor is a class operation that does not modify the state of an object. 6. In other words. When does a name clash occur? Answer: A name clash occurs when a name is defined in more than one place. the compiler uses the namespace signature for differentiating the definitions. 7. This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. Modifiers are also known as ‘mutators’. Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. Answer: Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. two different class libraries could give two different classes the same name. The accessor functions need to be declared as const operations 3. 4. It’s jargon for plain classes.

.  bidirectional iterators. Access to the contents is granted on a one-ata-time basis in order.  Object Modelling Techniques (OMT) (Rumbaugh 1991).  random access. cont_iter is the name of the iterator. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). In this example. while x/=none do . Iterators hide the details of access to and update of the elements of a container class.  Object Oriented Software Engineering (Objectory) (Jacobson 1992). (Here. s(x). there is s(x) an operation on x.  Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991).. 9. none)In the middle of the loop. Answer:  Object Oriented Development (OOD) (Booch 1991. yields either the next element in the container. which provides an interface that. Succesive elements from the container are carried to x. List out some of the object-oriented methodologies. It is created on the first line by instantiation of cont_iterator class. x:=cont_iter.  ONTOS of Ontos.  POET of POET software. cont.  Objectivity of Objectivity inc.next().  Versant of Versant object technology. Answer:  GEMSTONE/OPAL of Gemstone systems.  ARDENT of ARDENT software. The following code fragment shows how an iterator might appear in code: cont_iter:=new cont_iterator(). or some value denoting the fact that there are no more elements to examine.. when called. The next element of the container is obtained at the bottom of the loop. the current element from the container. end. an iterator class defined to iterate over some container class.. List out some of the OODBMS available. The iterator is a construct.  Object store of Object Design.1994). 10. .280  forward iterators. The simplest and safest iterators are those that permit read-only access to the contents of a container class.next(). x:=cont_iter. The loop terminates when x is bound to some empty value. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. .

What is an adaptor class or Wrapper class? Answer: A class that has no functionality of its own. Example: int *i=0x400 // i points to address 400 *i=0. The Fusion Method (Coleman 1991). What is an incomplete type? Answer: Incomplete types refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification. Class invariants must hold when an object is created. 13. What is a dangling pointer? Answer: A dangling pointer arises when you use the address of an object after its lifetime is over. to each other. and they must be preserved under all operations of the class. 11. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.oriented implementation. It is an implementation of an operation. What is class invariant? Answer: A class invariant is a condition that defines all valid states for an object.281   Object Oriented Analysis (OOA) (Shlaer and Mellor 1992). 16. 15. 14. //set the value of memory location pointed by i. What is a Null object? Answer: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. It is a logical condition to ensure the correct working of a class. Incomplete types are otherwise called uninitialized pointers. Differentiate between the message and method. In . A message is sent to invoke a method. Its member functions hide the use of a third party software component or an object with the non-compatible interface or a nonobject. Answer: Message Method Objects communicate by sending messages Provides response to a message. 12.

What are proxy objects? Answer: Objects that stand for other objects are called proxy objects or surrogates. Answer: Precondition: A precondition is a condition that must be true on entry to a member function. An operation is not responsible for doing anything sensible if its precondition fails to hold. This is a post-condition of the push operation. }. What do you mean by Stack unwinding? Answer: It is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.. 19. For example.282 particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class. the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full.. We say that isful() is a precondition of the push operation. after pushing an element on the stack. . A class is used correctly if preconditions are never false. we know that isempty() must necessarily hold. For example. A class is implemented correctly if post-conditions are never false. . Post-condition: A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function.  The condition should hold at the end of every mutator(non-const) operation. 17. 20. Define precondition and post-condition to a member function. What are the conditions that have to be met for a condition to be an invariant of the class? Answer:  The condition should hold at the end of every constructor. Example: template<class T> class Array2D { public: class Array1D { public: T& operator[] (int index). const T& operator[] (int index) const. 18.

do not exist.. }. conceptually.. // fine Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3.  relies primarily on virtual functions in its public interface  depends on all its direct and indirect base class  can be understood only in the context of the base class  can be used as base for further derivation  can be used to create objects.6) of the original two dimensional array.  Sather. What is an orthogonal base class? Answer: . 21. . Name the operators that cannot be overloaded. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. A node class is a class that has added new services or functionality beyond the services inherited from its base class. live. The following then becomes legal: Array2D<float>data(10. What is a node class? Answer: A node class is a class that. Array1D is a proxy class. two-dimensional arrays. do not exist for clients of Array2D. Its instances stand for one-dimensional arrays that. ..  provides a wider interface to te users than its base class. In the above example. Answer:  Smalltalk.  Eiffel..-> :: ?: 23.20). Such clients program as if they were using real.  relies on the base class for services and implementation.. conceptually.. cout<<data[3][6]. . 22.. const Array1D operator[] (int index) const. Name some pure object oriented languages.* .. Answer: sizeof . 24. Clients of the Array2D class need not be aware of the presence of the Array1D class.. Objects of this latter class stand for one-dimensional array objects that.283 Array1D operator[] (int index).  Java.

What is a protocol class? Answer: An abstract class is a protocol class if:  it neither contains nor inherits from classes that contain member data. or private (or protected) members of any kind. the container is called a homogeneous container. User code . A container class has a predefined behavior and a well-known interface. when the container is holding a group of objects that are all the same.284 If two base classes have no overlapping methods or data they are said to be independent of. 26. unless one manipulates the objects of these classes through pointers and references.  it has a non-inline virtual destructor defined with an empty implementation. Mixin classes typically don't share common bases.What is the handle class? Answer: A handle is a class that maintains a pointer to an object that is programmatically accessible through the public interface of the handle class. the benefits of the virtual functions are lost. 29. Explanation: In case of abstract classes. A container class acts as a generic holder. The concrete class is not intended to be a base class and no attempt to minimize dependency on other classes in the implementation or behavior of the class. What is a mixin class? Answer: A class that provides some but not all of the implementation for a virtual base class is often called mixin. the container is called a heterogeneous container. What is a concrete class? Answer: A concrete class is used to define a useful object that can be instantiated as an automatic variable on the program stack. The implementation of a concrete class is defined. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. Derivation done just for the purpose of redefining the virtual functions in the base classes is often called mixin inheritance. 28. are declared pure virtual functions and left undefined.  all member functions other than the destructor including inherited functions. 27. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. What is a container class? What are the types of container classes? Answer: A container class is a class that is used to hold objects in memory or external storage. or orthogonal to each other. 25. The same derived class may inherit such classes with no difficulty. nonvirtual functions. When a container class contains a group of mixed objects.

we can write code say a member that can store actions for later execution without using pointers to functions. 30. . Often. Another limitation of abstract class object is of fixed size. Classes however are used to represent concepts that require varying amounts of storage to implement them."Continue". even when the representation changes and also that handles are small enough to move around relatively freely so that the user needn’t use the pointers and the references. However. Using pointers or references implies that the burden of memory management falls on the user. handles have a bit more data than the simple representation pointer. class error_message: public Action { response_box db(message. A popular technique for dealing with these issues is to separate what is used as a single object in two parts: a handle providing the user interface and a representation holding all or most of the object's state. virtual ~Action( ). Manipulators used with iostreams is an obvious example. For example: class write_file : public Action { File& f. The connection between the handle and the representation is typically a pointer in the handle."Cancel". } Given this. without knowing anything about the objects involved.suceed( ). requires its own data. What is an action class? Answer: The simplest and most obvious way to specify an action in C++ is to write a function.cstr( ). but not much more. class Action { public: virtual int do_it( int )=0. Hence the layout of the handle is typically stable. Explanation: A common form of action class is a simple class containing just one virtual function."Retry"). public: int do_it(int) { return fwrite( ). has to be combined with other actions. } }.285 may become dependent on details of implementation classes because an abstract type cannot be allocated statistically or on the stack without its size being known. if the action has to be delayed. etc then it often becomes attractive to provide the action in the form of a class that can execute the desired action and provide other services as well. has to be transmitted 'elsewhere' before being performed. and without even knowing the name of the operation it invokes.

Explanation: Using a copy constructor we simply copy the data values member by member. Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. the copy of the object with all its data is popped off the stack.286 switch (db. case 1: abort(). The overloaded assignment operator would create a deep copy of objects. It is called parameterized because an actual type is a parameter of the code body. Parameteric polymorphism is the mechanism by which the same code is used on different types passed as parameters. A user of the Action class will be completely isolated from any knowledge of derived classes such as write_file and error_message. Owing to straight copying of references and pointers. 32. The data values of the object would then be inadvertently altered by the function. the destruction of either object will not affect the remaining object. When can you tell that a memory leak will occur? Answer: A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory. This type of polymorphism is called parameteric polymorphism. If the object is a simple class.return 1. only the addresses of pointers that are members are copied and not the value the address is pointing to. In a deep copy. the two objects may contain ht same information but the target object will have its own buffers and resources.redo( ).getresponse( )) { case 0: return 0. comprised of built in types and no pointers this would be acceptable. This method of copying is called shallow copy. Polymorphism may be achieved through parameterized types. . case 2: current_operation.What is a parameterized type? Answer: A template is a parameterized construct or type containing generic code that can use or manipulate any type. Differentiate between a deep copy and a shallow copy? Answer: Deep copy involves using the contents of one object to create another instance of the same class. This function would use the values and the objects and its behavior would not be altered with a shallow copy. the two objects will share the same externally contained contents of the other object to be unpredictable. } }. 33. 31. When the function goes out of scope.

Example: template <class X> class smart_pointer { public: smart_pointer().287 If the object has any pointers a deep copy needs to be executed. looks and feels like a normal pointer but offers more functionality. They have a number of advantages over regular pointers. Like other overloaded operators. In C++. memory is allocated for the object in free store and the elements pointed to are copied. They are guaranteed to be initialized as either null pointers or pointers to a heap object. cout<<*p. Here is how to use it: smart_pointer <employee> p= employee("Harris". With the deep copy of an object. A deep copy is used for objects that are returned from a function. }. const smart_pointer <X> & operator =(const smart_pointer<X>&). One significant problem with these smart pointers is that unlike regular pointers. A translation unit is the result of merging an implementation file with all its headers and header files.5). This class implement a smart pointer to an object of type X. const X& operator*( ) const.. What is an opaque pointer? Answer: A pointer is said to be opaque if the definition of the type to which it points to is not included in the current translation unit. 34. The object itself is located on the heap. smart_pointer(const smart_pointer <X> &). ~smart_pointer(). // makes a null pointer smart_pointer(const X& x) // makes pointer to copy of x X& operator *( ). p->raise_salary(0. . private: //.. Indirection through a null pointer is checked. they don't respect inheritance. What is a smart pointer? Answer: A smart pointer is an object that acts. Smart pointers are unattractive for polymorphic code. smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. Objects are automatically freed when the last pointer to them has gone away. No delete is ever necessary. 35. p will behave like a regular pointer.1333). X* operator->() const. Given below is an example for the implementation of smart pointers.

. In C++. Name mangling is a concession to the fact that linker always insists on all function names being unique. given the declaration: class Bar { public: int ival. 37. What is name mangling? Answer: Name mangling is the process through which your c++ compilers give each function in your program a unique name. What is slicing? Answer: Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object. One reason to pass objects of classes in a hierarchy is to avoid slicing.g. } As base copy functions don't know anything about the derived only the base part of the derived is copied. . } void fun( ) { base e=m.. e=m. Example: In general. For example: Printer is-a printer.. base (const base&). }.288 36. 38.. This is commonly referred to as slicing. What is reflexive association? Answer: The 'is-a' is called a reflexive association because the reflexive association permits classes to bear the is-a association not only with their super-classes but also with themselves. Other reasons are to preserve polymorphic behavior and to gain efficiency. Explanation: Consider the following class declaration: class base { .. member names are made unique by concatenating the name of the member with that of the class e. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class. all programs have at-least a few functions with the same name. base& operator =(const base&).

type. Member functions. Declarations can be repeated in a given scope. because they can be overloaded. Differentiate between declaration and definition in C++.. 39. A definition is a declaration unless: . A declaration is a definition unless:  it declares a function without specifying its body. it introduces a name in a given scope.  it is a typedef declaration..g.  it is the declaration of a static class data member without a class definition. . } The internal representation of a Foo object is the concatenation of its base and derived class members. // Pseudo C++ code // Internal representation of Foo class Foo { public: int ival__3Bar.289 ival becomes something like: // a possible member name mangling ival__3Bar Consider this derivation: class Foo : public Bar { public: int ival. function or class used in a C++ program. instance. Answer: A declaration introduces a name into the program. 40. it routes data to the true server object and sends back the return value to the object.. a definition provides a unique description of an entity (e. During a method invocation. . require an extensive mangling to provide each with a unique name. and function). What are proxy objects? Answer: Objects that points to other objects are called proxy objects or surrogates.  it is a class name definition. Its an object that provides the same interface as its server object but does not have any functionality.. Unambiguous access of either ival members is achieved through name mangling. There must be exactly one definition of every object. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique). }.  it contains an extern specifier and no initializer or function body. int ival__3Foo.

 It is without the a this pointer. Answer: The main characteristics of static functions include. you use the placement new. Because the global namespace doesn’t have a name. Answer: An inline function is a request and not a command. it can set itself to be a copy of another object.  it defines a non-inline member function. Operator new's special version placement new allows you to do it. Explanation: Inline-expansion could fail if the inline function contains loops. the compiler simple searches the current scope. 41. Will the inline function be compiled as the inline function always? Justify. and you need to construct an object in the memory you have. or it can return a copy of itself. Hence it won't be compiled as an inline function always. class Widget { . 44. and any scopes in which the current scope is nested. 46. What is placement new? Answer: When you want to call a constructor directly. to find the declaration for the name. 43.e. it may. What is cloning? Answer: An object can carry out copying in two ways i. This can be useful for referring to members of global namespace whose names have been hidden by names declared in nested local scope. The rules for inlining are compiler dependent.  It doesn't need to be invoked through an object of its class. How can a '::' operator be used as unary operator? Answer: The scope operator can be used to refer to members of the global namespace. or an inline function is called in a complex expression. 42. 45. Unless we specify to the compiler in which namespace to search for a declaration. The latter process is called cloning.290  it defines a static class data member.  It can't directly access the non-static members of its class  It can't be declared const. the notation :: member-name refers to a member of the global namespace. Answer: The function must be defined inside the class. Define a way other than using the keyword inline to make a function inline. although for convenience. volatile or virtual. Describe the main characteristics of static functions. the address of an inline function is used. Sometimes you have some raw memory that's already been allocated.

The identity . Since every object has the above three. What do u meant by "SBI" of an object? SBI stands for State. Design: It is the process of adopting/choosing the one among the many. What are the steps involved in designing? Before getting into the design the designer should go through the SRS prepared by the System Analyst. Such a function might be useful for applications using shared memory or memory-mapped I/O. OOAD 1. inheritance and polymorphism are the main concepts of object orientation. it is compromising mechanism. } }. 2. What are the main underlying concepts of object orientation? Objects. 3. because objects in such applications must be placed at specific addresses or in memory allocated by special routines. messages. In Architectural Design we find what are the main modules in the problem domain. 4. So.. So. which best accomplishes the users needs. In Detailed Design we find what should be done within each module. Behavior and Identity. it is the process of determining what needs to be done before how it should be done. simply it is an art of discovery. simply. In order to accomplish this. ..291 public : Widget(int widgetsize).int widgetsize) { return new(buffer) Widget(widgetsize). class.  Behaviour: It describes the actions and their reactions of that object.  Identity: An object has an identity that characterizes its own existence.  State: It is just a value to the attribute of an object at a particular time. Widget* Construct_widget_int_buffer(void *buffer. The main tasks of design are Architectural Design and Detailed Design. This function returns a pointer to a Widget object that's constructed within the buffer passed to the function. What do you mean by analysis and design? Analysis: Basically. the developer refers the existing systems and documents.

What are models and meta models? Model: It is a complete description of something (i. It is represented by sequence. methods that are used to represent ones' thinking using graphical notations. . Meta model: It describes the model elements. How to represent the interaction between the modeling elements? Model element is just a notation to represent (Graphically) the entities that exist in the problem domain.e. 8. object and USECASE diagrams. which passively waits for the message to be processed. activity. system).g. 5. 6. syntax and semantics of the notation that allows their manipulation. What do you meant by static and dynamic modeling? Static modeling is used to specify structure of the objects that exist in the problem domain. Passive objects are one. collaboration and statechart diagrams. In simple words it can be referred as client. Differentiate persistent & non-persistent objects? Persistent refers to an object's ability to transcend time or space. The following are the Relationships. for modeling element is class notation. What is meant by software development method? Software development method describes how to model and build software systems in a reliable and reproducible way. A persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object. By default objects are considered as non-persistent. e. Diagram: client server (Active) (Passive) 7.292 makes it possible to distinguish any object in an unambiguous way. What do you meant by active and passive objects? Active objects are one which instigate an interaction which owns a thread and they are responsible for handling control to other objects. 9. To put it simple. But Dynamic modeling refers representing the object interactions during runtime. Relationships are used to represent the interaction between the modeling elements. object notation etc. and independently from its state. These are expressed using class. 10. A non-persistent object is said to be transient or ephemeral. In simple words it can be referred as server. It waits for another object that requires its services.

class A class B class C . It is represented as line with diamond in the master area. It is represented as darked diamond at the whole part. // some code for class B. car car wheels  Containment: This relationship is applied when the part contained with in the whole part. so the object class A dies when the object class B dies. which has captured the common states. which captures the common states of objects of different classes. In the above example we see that an object of class A is instantiated with in the class B.: uses class B class A  Aggregation: Its' the relationship between two classes which are related in the fashion that master and slave. example: class A{ //some code }. Since the slave works under the master. e. It is represented as arrow line pointed at the class. class B { A aa. etc. class A class B  Generalization: This relationship used when we want represents a class.293  Association: Its' just a semantic connection two classes.we can represnt it in diagram like this. The master takes full rights than the slave. dies when the whole part dies. }. ex: car contains wheels. // an object of class A.g.

But Association is used represent the relationship between the two classes. 12. This particular span was called as "method-wars" 15. Can link and Association applied interchangeably? No. The human body is an apt example for this relationship. Best example is Car. Note: All the other relationships satisfy all the properties like Structural properties. Booch. but all Bs’ not A. is the fusion of Rumbaugh. 13. Even though the parts are not there we can call it as car. You cannot apply the link and Association interchangeably. link :: student:Abhilash course:MCA Association:: student course 14. The developers were in a dilemma to choose the method which best accomplishes their needs. Person. We can add/subtract some properties in the part (slave) side. Antisymmetric: employee is a person. But. Interface properties. Meyer etc who followed their own notations to model the systems. Why generalization is very strong? Even though Generalization satisfies Structural. Its' the superset of all the methodologies. what is meant by "method-wars"? Before 1994 there were different methodologies like Rumbaugh. Employee. B. Whether unified method and unified modeling language are same or different? Unified method is convergence of the Rumbaugh and Booch. DIAGRAM: class A class B 11. which contains the wheels and some extra parts. Transitive: A=>B. A. C. When the whole body dies the parts (heart etc) are died. Since link is used represent the relationship between the two objects. Behaviour properties. Jacobson. Salesman. Mathematically all As’ are B. as it is Antisymmetric and Transitive. It is mathematically very strong. Interface. It won't affect the whole part. but not all persons are employees. Differentiate Aggregation and containment? Aggregation is the relationship between the whole and a part. Booch and Jacobson as well as Betrand Meyer (whose contribution is "sequence diagram"). Who were the three famous amigos and what was their contribution to the object .294  Dependency: It is the relationship between dependent and independent classes. 16. Any change in the independent class will affect the states of the dependent class. Unified modeling lang. Behaviour properties. in the case of containment the whole part is affected when the part within that got affected. B=>c then A=>c.

What is an USECASE? Why it is needed? A Use Case is a description of a set of sequence of actions that a system performs that yields an observable result of value to a particular action. In SSAD process <=> In OOAD USECASE. Differentiate the class representation of Booch. Diagram: Booch: In this method classes are represented as "Clouds" which are not very easy to draw as for as the developer's view is concern. Diagram: 18. It is represented elliptically.  Grady Booch: A veteran in design who came up with an idea about partitioning of systems into subsystems.  James Rumbaugh (OMT): A veteran in analysis who came up with an idea about the objects and their Relationships (in particular Associations).  Ivar Jacobson (Objectory): The father of USECASES. Diagram: . It is represented as a stickman like this.295 community? The Three amigos namely. who described about the user and system interaction. Who is an Actor? An Actor is someone or something that must interact with the system. It is some what similar and both are very easy to draw. Rumbaugh and UML? If you look at the class representaiton of Rumbaugh and UML. Representation: OMT UML. 17.In addition to that an Actor initiates the process(that is USECASE). Representation: 19.

in class there are two guys with same name. The access from a particular object can be made only when the particular condition is met. customer check customer number ATM. Suppose a class acts an Actor in the problem domain. The name alone does not necessarily identify a unique function. Or example. How will the designer give the implementation details of a particular USECASE to the programmer? This can be accomplished by specifying the relationship called "refinement” which talks about the two different abstraction of the same thing. Here the object on the customer accesses the ATM facility only when the guard condition is met. 24. Differentiate the following notations? I: :obj1 :obj2 II: :obj1 :obj2 In the above representation I. USECASE is an implementation independent notation. 21.296 20. but they . how to represent it in the static model? In this scenario you can use “stereotype”. For Example. Why does the function arguments are called as "signatures"? The arguments distinguish functions with the same name (functional polymorphism). class A << Actor>> attributes methods. But in the case of II the data is transferred from obj1 to obj2. What is guard condition? Guard condition is one. In real life we see suppose. the name and its arguments (signatures) will uniquely identify a function. which acts as a firewall. It is given with in the << >>. However. Since stereotype is just a string that gives extra semantic to the particular entity/model element. 22. calculate pay calculate class1 class2 class3 23. obj1 sends message to obj2.

state the reason. Determine which of the following are VALID identifiers. The same concept is applied here. since an identifier must begin with a letter or an underscore (f) VALID (g) Invalid. Playing with scanf function Operators & Expressions _____ _____________________________________ [Q001]. (a) sample1 (b) 5sample (c) data_7 (d) return (e) #fine (f) variable (g) 91-080-100 (h) name & age (i) _val(j) name_and_age Ans. void setsex(char). }. (a) 'y' (b) '\r' (c) 'Y' (d) '@' (e) '/r' (f) 'word' (g) '\0' (h) '\?' (i) '\065' (j) '\'' (k) ' ' Ans. since an identifier must begin with a letter or an underscore (c) VALID (d) Invalid. (a) VALID (b) VALID (c) VALID (d) VALID . since an identifier must begin with a letter or an underscore (h) Invalid. If invalid. ex: class person { public: char getsex(). since return is a reserved word (e) Invalid. (a) VALID (b) Invalid. state the reason. since blank spaces are not allowed (i) VALID (j) VALID _______________________________________________________________________ __________________________ [Q002]. void setsex(int). Determine which of the following are VALID character constants. If invalid. In the above example we see that there is a function setsex() with same name but with different signature.297 can be easily identified by their signatures.

. since illegal character(blank space) (h) Invalid. Determine which of the following numerical values are valid constants.) (b) VALID (c) VALID (d) VALID (e) VALID (f) VALID (g) Invalid. F).007 (d) 5. (a) 'Hi Friends' (b) "abc.e. specify the base for each valid integer constant. (a) Invalid.2e-0. if intended as an octal constant. "You\'re great" (g) "" (h) " " (i) "Rs.76e-8" (e) "Don\'t sleep" (f) "He said. Also. specify whether it is integer or real. since a string constant must be enclosed in double quotation marks (b) VALID (c) Invalid.298 (e) Invalid. state the reason. (a) Invalid.3 (g) 0.ghi" (c) "Qualification (d) "4325. since illegal character(s) (i) VALID (j) Invalid. since the quotation marks and (optionally) apostrophe within the string cannot be expressed without the escape sequences.def. (g) VALID (h) VALID (i) VALID _______________________________________________________________________ __________________________ [Q004]. Determine which of the following are VALID string constants. since escape sequences must be written with a backward slash (i. If invalid.3 (h) 0xaf9s82 (i) 0XABCDEFL (j) 0369CF (k) 87654321l (l) 87654321 Ans. since illegal character(. \) (f) Invalid.6e7 (e) 5.100/-" Ans. If a constant is valid. (a) 10.6e-7 (f) 0. C. since a character constant cannot consist of multiple characters (g) VALID (null-character escape sequence) (h) VALID (i) VALID (Octal escape sequence) (j) VALID (k) VALID _______________________________________________________________________ __________________________ [Q003].2e 0.500 (b) 080 (c) 0. since trailing quotation mark is missing (d) VALID (e) VALID (single-quote escape sequence) (f) Invalid. since illegal characters (9.

(b) since there is no such data type called 'integer'.).sizeof(integer)). _______________________________________________________________________ __________________________ [Q008].0E+5 (k) All of the above (l) None of these Ans. What will be the output of the following program : void main() { char str[]="C For Swimmers". } (a)123 (b)Compile-Time Error (c)123.123.E+4 (j) 5. (a)--c .299 (k) VALID (l) VALID _______________________________________________________________________ __________________________ [Q005].sizeof str). (a) 500000 (b) 0. Determine which of the following floating-point constants are VALID for the quantity (5 * 100000). What will be the output of the following program : void main() { printf("%d".5E6 (h) 50e4 (i) 50. (d) _______________________________________________________________________ __________________________ [Q007]. } (a)2 (b)Compile-Time Error (c)4 (d)None of these Ans.5e6 (c) 5E5 (d) 5e5 (e) 5e+5 (f) 500E3 (g) . (k) _______________________________________________________________________ __________________________ [Q006].000000 Ans. printf("%d". } (a)14 (b)Compile-Time Error (c)15 (d)None of these Ans.00 (d)123. What will be the output of the following program : void main() { printf("%f".

(c) (d)1 . What will be the output of the following program : void main() { printf("%d".++(sizeof(str))). } (a)Compile-Time Error (b)2 (c)0 Ans. (c) _______________________________________________________________________ __________________________ [Q012].-sizeof(str)). printf("%d". } (a)14 (b)Compile-Time Error (c)-15 (d)-14 Ans. What will be the output of the following program : void main() { char str[]="C For Swimmers".z=2.300 _______________________________________________________________________ __________________________ [Q009]. (b) _______________________________________________________________________ __________________________ [Q010].y=6. z/=y/z==3?y/z:x*y. printf("%d". } (a)14 (b)Compile-Time Error (c)15 (d)None of these Ans. What will be the output of the following program : void main() { int x=5. (c) _______________________________________________________________________ __________________________ [Q011]. } (a)100 (b)0 (c)1 (d)2 Ans. printf("%d".z).!(100==100)+1). What will be the output of the following program : void main() { char str[]="C For Swimmers".

e=19.5.25 .b. } (a)VALID : Success (b)VALID : Failure (c)INVALID (d)None of these Ans. (d) _______________________________________________________________________ __________________________ [Q015].e=19.d=40.b=100.e). (c) _______________________________________________________________________ __________________________ [Q014].d=4.!5.c=30. (b) _______________________________________________________________________ __________________________ [Q016]. What will be the output of the following program : void main() { int a=1. } (a)5 10 22 (b)5 5 25 (c)5 0 25 (d)5 1 24 Ans.c. } (a)500 100 30 40 4 (b)Run-Time Error (c)700 200 300 10 4 (d)300 -200 300 10 4 Ans.!25). else printf("Failure").d=40.b=2. What will be the output of the following program : void main() { int a=500.c=30.301 _______________________________________________________________________ __________________________ [Q013]. What will be the output of the following program : int main() { int a=500.a. } (a)1 (b)2 (c)3 (d)4 .c=3. printf("%d".b=100.!a?b?!c:!d:a).d. printf("%d %d %d %d %d". What will be the output of the following program : void main() { printf("%d %d %d". if ((((a > b) ? c : d) >= e) && !((e <= d) ? ((a / 5) == b) : (c == d))) printf("Success"). a+=b-=c*=d/=e%=5.

j.sx.i.i.sx.k). printf("\n\n%08d %08d\n%08d %015ld\n%08d %08u".i. printf("\n\n%+8d %+8d\n%+8d %+15ld\n%+8d %8u". 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555 +12345 -13579 -24680 +123456789 -2222 5555 00012345 -0013579 -0024680 000000123456789 -0002222 00005555 _______________________________________________________________________ __________________________ [Q018].ix.j.j.k). printf("\n\n%8d %8d %8d\n%15ld %8d %8u".i.j. short sx=-2222. printf("\n\n%3d %3d %3d\n%3ld %3d %3u".i. What will be the output of the following program : void main() { int i=12345.302 Ans.ux).k. } Ans.ix.i.j=0xabcd9. long ix=123456789.i.k=077777.ix.sx.k.ux).ix.j.ux).ix. (a) _______________________________________________________________________ __________________________ [Q017].k.ix. printf("\n\n%-8d %-8d\n%-8d %-15ld\n%-8d %-8u".k.k. printf("%d %x %o".j.j. printf("\n%3d %3x %3o". unsigned ux=5555. What will be the output of the following program : void main() { int i=12345.k.ux).sx. . printf("\n%d %d %d %ld %d %u".ux).j.j=-13579.k=-24680.sx.ux).sx.i.

printf("\n%3f %3f %3f".c2. printf("\n%-8f %-8f %-8f". printf("\n%8. c2='B'. printf("\n%3e %3e %3e". c=3000.j.k).b.3f %8.b.303 printf("\n%8d %8x %8o"i.3f %8.c2.a.b.a.4f".b.5.c).c).c). printf("\n%12e %12e %12e". printf("\n%c%c%c".c).a.a. What will be the output of the following program : void main() { char c1='A'.c). .a. printf("\n%+8d %+8x %+8o".a.a.j.c3).c3).c2. printf("\nc1=%c c2=%c c3=%c".b. 12345 abcd9 77777 12345 abcd9 77777 12345 abcd9 77777 12345 abcd9 77777 +12345 abcd9 77777 00012345 0xabcd9 077777 _______________________________________________________________________ __________________________ [Q019].c2. c3='C'. printf("\n%e %e %e".i.b.k).c1. printf("\n%08d %#8x %#8o". printf("%f %f %f".c3).a.k).i.c1. What will be the output of the following program : void main() { float a=2.c1.j. } Ans.k). A B C ABC A B C A B C c1=A c2=B c3=C _______________________________________________________________________ __________________________ [Q020].c).b. printf("\n%3c%3c%3c".i.4f %8.b.4f %8.c3). } Ans.c).2e %8. printf("\n%8. printf("\n%8f %8f %8f". printf("%c %c %c".a.c3).c2. printf("\n%-8d %-8x %-8o".c1. printf("\n%8..3f".j.0005.2e".b.a.c).2e %8.c). b=0.c1.c).b. printf("\n%3c %3c %3c".

000000e+003 2.c).00e-004 3.000000 2.000 2.a.000500 3000.c).000000 2. printf("\n%.000500 +3000.500000 0.50e+000 5.str).500000e+000 5.000000 2.500000 0. printf("%s".000000 +2.000000e-004 3. What will be the output of the following program : void main() { int a=1.b.str+6. printf("\n%08f %08f %08f".500000e+000 5.c).5000 0.000500 3000.001 3000.000500 3000.000500 3000.0000e-004 3.str).b.str).5000e+000 5.500000 0.000500 3000.b. printf("\n%8. .0005 3000 2.000000e-004 3. printf("\n%-10s %. } Ans. } Ans.*s".str).500000 +0.b=2. C For Swimmers C For C For Swimmers C _______________________________________________________________________ __________________________ [Q022]. printf("\n%#8f %#8f %#8f".000000e-004 3. What will be the output of the following program : void main() { char str[]="C For Swimmers".b.000000 _______________________________________________________________________ __________________________ [Q021].304 printf("\n%+8f %+8f %+8f".5 0.000000e+003 2.1s".000000 2.c).b.000500 3000.000500 3000.500000e+000 5.5s". 2.c).00e+003 2.a.5.a.0000e+003 2.500000 0. printf("\n%#g %#g %#g"a.000000 2.500 0.500000 0.000000 2.500000 0.000000e+003 2.c=3. printf("\n%g %g %g".0005 3000.0000 2.500000 0.a.

} .&b. scanf("%d a %f". // Max.b. printf("\n%s". printf("a=%c b=%c c=%c". What will be the output of the following program : void main() { int i=1.c).f).line).a. } [NOTE : THE USER INPUT IS :A B C] (a)a=A b=B c=C (b)a=A b= c=B (c)a=A b= c=C (d)None of these Ans. printf("%d %.&a.&c).&c).c). (b) _______________________________________________________________________ __________________________ [Q025].&a.a.2f".b.line). scanf("%c%c%c".&i. } [NOTE : 3 values entered by the user are:100 200 300] (a)1 2 3 (b)100 200 300 (c)100 200 3 (d)100 300 3 Ans.305 scanf("%d %*d %d".b. printf("a=%d b=%d c=%d".i. What will be the output of the following program : void main() { char a.25. length=80 Chars scanf("%[^. What is the output?] (a)Compile-Time Error (b)Dear Friends (c)What is the output? (d)None of these Ans.&b.c.]s". What will be the output of the following program : void main() { char line[80]. } [NOTE : THE USER INPUT IS:Dear Friends. float f=2. (b) _______________________________________________________________________ __________________________ [Q024]. (d) _______________________________________________________________________ __________________________ [Q023].&f).

What will be the output of the following program : void main() { int a.b.c).25 (d)None of these Ans. (b) _______________________________________________________________________ __________________________ [Q027].b. printf("%s %s %s". scanf("%1s %5s %3s".a.&c).b.b. printf("Sum=%d".25 (b)5 5.c.b[80]. } [NOTE : THE USER INPUT IS :ABC DEF GHI] (a)a=ABC b=DEF c=GHI (b)a=A b=B c=C (c)a=A b=D c=G (d)None of these Ans. What will be the output of the following program : void main() { char a. scanf("%1d %2d %3d".306 [NOTE : THE USER INPUT IS:5 5. scanf("%c %c %c".c[80].&a.&a.c).&b.c.c). (a) (d)None of .a. (c) _______________________________________________________________________ __________________________ [Q026]. } [NOTE : THE USER INPUT IS :123456 44 544] (a)Sum=480 (b)Sum=594 (c)Sum=589 these Ans.a+b+c). } [NOTE : THE USER INPUT IS:CMeansSea Ocean Vast] (a)C O V (b)C Means Sea (c)C Ocean Vas (d)None of these Ans.&b. (b) _______________________________________________________________________ __________________________ [Q028].75] (a)1 2.b. printf("a=%c b=%c c=%c".75 (c)5 2.&c). What will be the output of the following program : void main() { char a[80].a.

line).line). } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these Ans.307 _______________________________________________________________________ __________________________ [Q029]. (d)None of these Ans. (c) _______________________________________________________________________ __________________________ [Q030]. (c)Accepts the string that contains anything other than the DIGITS and NEWLINE characters. } (a)Accepts the string that contains DIGITS & ALPHABETS only. scanf("%[^1234567890\n]". (b)Accepts the string that contains * or asterisk characters only. What will be the output of the following program : void main() { printf(). scanf("%[^*]". (c)Accepts the string that contains anything other than the * or asterisk character. (c) _______________________________________________________________________ __________________________ [Q001]. } (a)Accepts the string that contains DIGITS only. What happens when the following program is executed : void main() { char line[80]. _____________________________________________________ [Q002]. (b) Since there must be enough arguments for the format. What will be the output of the following program : void main() { printf(NULL). . What happens when the following program is executed : void main() { char line[80]. (b)Accepts the string that contains DIGITS and NEWLINE characters. (d)None of these Ans.

(a) since"%d"+0 has no effect on the output operation. (c) Since % is a format specifier & excess arguments (more than required by the format) are merely ignored. } (a)5 (b)Compile-Time Error (c)/ Ans.123). } (a)7 (b)Compile-Time Error (c)% (d)%% Ans. ____________________________________________________ [Q003].8). What will be the output of the following program : void main() { printf("%d"+0.7). } (a)123 (b)Compile-Time Error (c)No Output (d)None of these Ans. __________________________________________________________ [Q006]. (c) Since NULL is a constant value or NULL pointer value or a NULL string. (d) Since // is taken as string _____________________________________________________________ (d)// [Q005]. What will be the output of the following program : void main() { printf("//".308 } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these Ans. __________________________________________________________________ . What will be the output of the following program : void main() { printf("%%". What will be the output of the following program : void main() { printf("d%". __________________________________________________________ [Q004]. } (a)8 (b)Compile-Time Error (c)d% (d)None of these Ans.5). (c) Since excess arguments (more than required by the format) are merely ignored.

} (a)0 (b)No Output (c)Compile-Time Error (d)None of these Ans. (b) Since L->R priority & the length of the strings 'Hi!' & 'Bye' is 3+3=6 ____________________________________________________________ [Q009]. What will be the output of the following program : void main()-----------------doubt { printf("%d"+1. 2nd character in the array or string "%d". What will be the output of the following program : void main() { printf("%d". } . _______________________________________________________________ [Q008].e.printf("Hi!")*printf("Bye")). (a) Since L->R priority & the length of the 2 empty strings are : 0+0=0 ____________________________________________________________ [Q011].printf("Hi!")+printf("Bye")).123). What will be the output of the following program : void main() { printf("Hi Friends"+3).printf("")+printf("")). What will be the output of the following program : void main() { printf("%d". } (a)ByeHi!6 (b)Hi!Bye9 (c)Hi!Bye (d)None of these Ans. } (a)123 (b)Compile-Time Error (c)d (d)No Output Ans.e 1 or > 0) affects the program output by considering "%d" as string and ignores 123 Where 1 refers to the index i. (b) Since L->R priority & the length of the strings 'Hi!' & 'Bye' is 3*3=9 ________________________________________________________ [Q010]. What will be the output of the following program : void main() { printf("%d". } (a)ByeHi!6 (b)Hi!Bye6 (c)Compile-Time Error (d)None of these Ans. (c) since "%d"+1 (i.309 [Q007].

(d) It is a VALID C statement. _______________________________________________________________ [Q014]. What will be the output of the following program : int main() { int main=7. } (a)Run-Time Error (b)\/*-*\/ (c)/*-*/ (d)None of these Ans. (c) Since \ is an escape sequence character. What will be the output of the following program : void main() { printf("\/\*\-*\/"). ___________________________________________________________ [Q012].main). Be careful while analyzing such statements. } (a)Compile-Time Error (b)C For Swimmers (c)Run-Time Error (d)None of these Ans.310 (a)Hi Friends (b)Friends (c)Hi Friends3 (d)None of these Ans. ________________________________________________________ [Q015]. { printf("%d". Prints 7 and returns the same to the OS. } printf("Bye"). (b) Since (base adress)+0 points to the value 'H'. ____________________________________________________________ [Q013]. What will be the output of the following program : void main() . What will be the output of the following program : void main() { printf("C For ") + printf("Swimmers"). (b) It is a VALID C statement. Thus it prints the string from 'F' onwards. return main. Now the NEW (base address) equals (base address)+3 that points to the character 'F'. NOTE: Last printf statement will not be executed. } (a)Compile-Time Error (b)Run-Time Error (c)7Bye (d)7 Ans.

). (All compilers will not support) _____________________________________________________________ [Q016].311 { main(). (d) Since L->R priority.val. What will be the output of the following program : void main()---------------------doubt { int val=10. } . First parameter contains the format specifier & the Second parameter contains the actual value 25. } (a)Compile-Time Error (b)Run-Time Error (c)25 (d)None of these Ans. printf("%d".val+1. It is like a recursive function & the statements get executed infinite number of times. What will be the output of the following program : void main() { int val=75. But it is a VALID C statement. ____________________________________________________ [Q019]. (c) It is a VALID C statement. What will be the output of the following program : void main() { char str[]="%d". What will be the output of the following program : void main() { printf("Work" "Hard").val). First it prints the word 'Work' & then 'Hard'.. (c) It is a VALID C statement. printf("%d". } (a)Compile-Time Error (b)Run-Time Error (c)Infinite Loop (d)None of these Ans. int val=25. ________________________________________________________ [Q018]."%d".. printf(str. (b) Output is Unpredictable B'coz there are not enough arguments for the format. } (a)Compile-Time Error (b)Unpredictable (c)75 (d)None of these Ans.val--).. ______________________________________________________________ [Q017]. } (a)Work (b)Hard (c)No Output (d)WorkHard Ans.

_______________________________________________________________________ __________________________ [Q022].scanf("%d %d".val. What will be the output of the following program : void main() { int val=5.&num)). What will be the output of the following program : void main() { int val=5.val--). (c) Since R->L priority. ______________________________________________________________ [Q020].z) (x+y-z)---------------doubt .] (a)1 (b)2 (c)5 (d)None of these Ans. converted & stored. The second format specifier “%d” is an excess argument and it is ignored.&val.++val. (b) Since scanf statement returns the number of input fields successfully scanned. What will be the output of the following program : #define Compute(x.num. printf("%d %d %d %d".--val.y. printf("%d". ___________________________________________________________ [Q021]. } (a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of these Ans. } [NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively. (a) Since R->L priority.312 (a)10 (b)11 10 (c)11 9 (d)10 9 Ans.

} (a)Run-Time Error (b)10 20 200 (c)Compile-Time Error (d)None of these Ans.. (d) Since alphabet 'a' is the ASCII equivalent of 97.. } (a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error (d)None of these Ans..y=3.. NOTE : Be careful while doing such type of calculations. _______________________________________________________________________ __________________________ [Q025].n=20.*/ are ignored by the compiler. What will be the output of the following program : void main() { int m=10.z. "Printing.z=4.n=20. printf("%d".val).x./* n-value */n. _______________________________________________________________________ __________________________ [Q023]. /* printf("%d".m*/* Compute m*n */n). } (a)40 (b)30 (c)Compile-Time Error (d)None of these Ans. (b) Since it is macro function. What will be the output of the following program : void main() { int val=97. What will be the output of the following program : void main() { int m=10."+printf("%c".m/* m-value */. } (a)Printing.97 (b)97 (c)Compile-Time Error Ans. _______________________________________________________________________ __________________________ [Q024].(-x+y)) * Compute(z. (b) Since comments /*.Compute(y..313 void main() { int x=2..e */ is missing in the above program.m*n). (c) Since COMMENT statement not ended properly i. (d)a .(-y+z))). printf("%d %d %d".

} (a)TestFailure (b)TestSuccess (c)Compile-Time Error (d)Test Ans.val).e. _______________________________________________________________________ __________________________ . val=printf("C") + printf("Skills"). printf("%*d". (a) VALID Since '*' specifies the precision (i. if ((printf("%s". What will be the output of the following program : void main() { char str[]="Test".314 _______________________________________________________________________ __________________________ [Q026]. What will be the output of the following program : void main() { int val=5. } (a) 5 (b)5 (c)Compile-Time Error (d)None of these Ans. of bytes output. else printf("Failure"). (d) VALID Since 'printf' function return the no.val). _______________________________________________________________________ __________________________ [Q027]. of bytes output.str)) == 4) printf("Success"). (b) VALID Since 'printf' function return the no. printf("%d". What will be the output of the following program : void main() { int val=5. Thus it prints 5 BLANK SPACES & then the value 5. If no precision is specified then the value itself will be the precision value. _______________________________________________________________________ __________________________ [Q028]. } (a)Skills5 (b)C1 (c)Compile-Time Error (d)CSkills7 Ans. the next argument in the precision).

315 [Q029]. Correct usage : Each compound statement should be enclosed within a pair of braces. if (-1) printf("Bye"). { (a)Compile-Time Error (b)5 (c)10 (d)11 Ans. printf("%d". if (0 || -1) printf("Bye"). What will be the output of the following program : void main() { printf("Hi!"). (a) Since incorrect usage of pair of braces } and {.5+val++). Branching.e { and }. _______________________________________________________________________ __________________________ Topic : Decision-making. What will be the output of the following program : void main()--------------------------doubt { int val=5. } (a)No Output (b)Hi! (c)Bye (d)Hi!Bye Ans. } (a)Compile-Time Error (b)5 (c)55 (d) 5 Ans. What will be the output of the following program : void main() { printf("Hi!"). printf("%d5". . (c) _______________________________________________________________________ __________________________ [Q030]. Looping & Bit-wise operations [Q001]. (d) _______________________________________________________________________ __________________________ [Q002]. i. What will be the output of the following program : void main() } int val=5.val).

(d) _______________________________________________________________________ __________________________ [Q003]. } (a)Compile-Time error (b)Hi! (c)Bye (d)Hi! Bye Ans. What will be the output of the following program : void main() { printf("Hi!"). if (-1+1+1+1-1-1-1+(-1)-(-1)) printf("Bye"). (a) _______________________________________________________________________ __________________________ [Q005]. What will be the output of the following program : void main() { printf("Hi!"). if (!1) printf("Bye").316 } (a)No Output (b)Hi! (c)Bye (d)Hi!Bye Ans. (b) _______________________________________________________________________ __________________________ [Q004]. What will be the output of the following program : void main() . if !(0) printf("Bye"). (d) _______________________________________________________________________ __________________________ [Q006]. } (a)Compile-Time error (b)Hi! (c)Bye (d)Hi! Bye Ans. What will be the output of the following program : void main() { printf("Hi!"). } (a)No Output (b)Hi! (c)Bye (d)Hi!Bye Ans.

(c) . if (~val) printf("%d".317 { if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int)) printf("Testing"). } (a)0 (b)7 (c)3 (d)No Output Ans. } (a)No Output (b)0xe75f (c)0xefff these Ans.b=0x0EF4.(d)None of .c). if (e=(a & b | c ^ d)) printf("%d".b=2. What will be the output of the following program : void main() { unsigned val=0xffff. What will be the output of the following program : void main() { unsigned a=0xe75f.c. printf("%d".e. } (a)No Output (b)OK (c)Testing (d)TestingOK Ans.c=3. printf("OK"). (b) _______________________________________________________________________ __________________________ [Q008].e). } (a)Compile-Time error (b)-1 (c)0 (d)-1 0 Ans.~val). (b) _______________________________________________________________________ __________________________ [Q007]. if ((c > a) && (c > b)) printf("%x".val). c=(a|b). What will be the output of the following program : void main() { int a=1.d=4. (c) _______________________________________________________________________ __________________________ [Q009].

a.y=5.z.318 _______________________________________________________________________ __________________________ [Q010].(b) _______________________________________________________________________ __________________________ [Q011]. What will be the output of the following program : void main() { unsigned x=0xf880. return. printf("%d %d". } printf("Failure"). (d) _______________________________________________________________________ __________________________ [Q012].z.*b). z=x<<y. printf("%#x %#x". } (a)1000 f87 (b)8800 0xf88 (c)1000 f88 (d)0x1000 0xf88 Ans.x>>y-1). What will be the output of the following program : void main() { unsigned val=0xabcd. int *b=&a. (a) _______________________________________________________________________ __________________________ . if (val>>16 | val<<16) { printf("Success"). } (a)Compile-Time error (b)Run-Time error (c)5 5 (d)Unpredictable Ans. } (a)No Output (b)Success (c)Failure (d)SuccessFailure Ans. What will be the output of the following program : void main() { register int a=5.

(c) _______________________________________________________________________ __________________________ [Q015]. void main() { printf("%d".c=3.c. if (d > c) if (c > b) printf("%d %d". What will be the output of the following program : .b=2. (a) _______________________________________________________________________ __________________________ [Q014]. } (a)Compile-Time error (b)Run-Time error (c)5 (d)Unpredictable Ans. What will be the output of the following program : void main() { int a=1.b.a). (c) _______________________________________________________________________ __________________________ [Q016].d. What will be the output of the following program : void main() { auto int a=5.d=4.c.d).c). printf("%d".319 [Q013]. else if (b < c) printf("%d %d".a). if (c > a) if (b < a) printf("%d %d".c). } (a)4 3 3 4 (b)4 3 3 2 (c)4 32 3 (d)4 33 1 Ans. else if (c > a) printf("%d %d". } (a)Compile-Time error (b)Run-Time error (c)5 (d)Unpredictable Ans.a). What will be the output of the following program : auto int a=5.

if (d > c) if (c > b) printf("%d %d". What will be the output of the following program : void main() { int a=1.d=4. if (c > a) printf("%d %d".320 void main() { int a=1. printf("C Program").c). (b) _______________________________________________________________________ __________________________ [Q018].d.c.c. (d) .c=3. } (a)No Output (b)C Program (c)Compile-Time Error Ans.b.c). if (c > a) if (b < a) printf("%d %d". if (a == 2). else.b=2. } (a)4 32 3 (b)4 33 42 3 (c)4 3 3 4 2 3 (d)None of these Ans.a). What will be the output of the following program : void main() { int a=1. if (a) printf("Test"). } (a)Again (b)Test (c)Compile-Time Error (d)TestAgain Ans. (b) _______________________________________________________________________ __________________________ [Q017]. printf("Again").d). if (b < c) printf("%d %d".

for (i=0.1. a++). for (a=0.1) printf("%.3 (b)Compile-Time Error (c)Run-Time Error (d)No Output Ans. a<10.321 _______________________________________________________________________ __________________________ [Q019]. } (a)No Output (b)1 (c)4 (d)None of these 2 3 Ans. (c) _______________________________________________________________________ __________________________ [Q020].10. b>9. i<4. (c) _______________________________________________________________________ __________________________ [Q021]. printf("%d %d". What will be the output of the following program : void main() { int i=1. for (. i+=0.20. What will be the output of the following program : .b. What will be the output of the following program : void main() { int a. for (b=25. b-=3). What will be the output of the following program : void main() { float i. printf("%d\n".b). i++).1f". (a) _______________________________________________________________________ __________________________ [Q022]. } (a)Compile-Time error (b)10 9 (c)10 7 (d)None of these Ans.a. } (a)0. i<0.i).i).4.

i=7) printf("%d".i--). What will be the output of the following program : void main() { int i=5.i+=2. printf("%d". } (a)Compile-Time error (b)2468 (c)468 (d)None of these Ans.i++).322 void main() { int i. while (i>0). } . } (b)Compile-Time Error (a)0 (c)10 (d)No Output Ans. i<=9. i<7. i+=2) printf("%d". What will be the output of the following program : void main() { int i.-i). (c) _______________________________________________________________________ __________________________ [Q023].i). (c) _______________________________________________________________________ __________________________ [Q024]. } (a)5 (b)54321 (c)Compile-Time Error (d)None of these Ans. printf("%d". What will be the output of the following program : void main() { int i=3. for (i=-10. do. for (i=2. for (i--. (c) _______________________________________________________________________ __________________________ [Q025]. !i. i++).

break. --i. } (a)No Output (b)54321 (c)4321 (d)None of these Ans.i). (c) _______________________________________________________________________ __________________________ [Q027]. case 2: printf("Choice2"). break. } } (a)No Output (b)Default (c)DefaultChoice1 (d)None of these Ans. (d) _______________________________________________________________________ __________________________ [Q026]. What will be the output of the following program : void main() { . case 1: printf("Choice1"). What will be the output of the following program : void main() { int choice=3. (c) _______________________________________________________________________ __________________________ [Q028]. for (i=5. switch(choice) { default: printf("Default").) printf("%d". What will be the output of the following program : void main() { int i.323 (a)No Output (b)3456 (c)23456 (d)None of these Ans.

) printf("%d". case 2: printf("Choice2").i).choice-1. } (a)Compile-Time error (b)4 (c)Infinite Loop (d)No Output Ans. (d) _______________________________________________________________________ __________________________ [Q031]. default: printf("Default").choice+=2) { case 1: printf("Choice1"). break. switch(--choice. break.). (b) _______________________________________________________________________ __________________________ [Q030].(i=4)?(i-4):i++.324 static int choice. What will be the output of the following program : . for (.choice-1. } } (a)Choice1 (b)Choice2 (c)Default (d)None of these Ans. What will be the output of the following program : void main() { int i. } (a)Compile-Time error (b)Executes ONLY once (c)Executes INFINITELY (d)None of these Ans. (a) _______________________________________________________________________ __________________________ [Q029]. What will be the output of the following program : void main() { for (.printf("").

while(1). (iii)None of these (iv)All of . i--. (c) & (d) (c)do. } (a)9 6 3 (b)Compile-Time Error (c)7 5 3 1 (d)Infinite Loop Ans. i--) printf("%d ". _______________________________________________________________________ __________________________ [Q033]. } (a)024 (b)Compile-Time Error (c)01234 (d)No Output Ans. What will be the output of the following program : void main() { int i=9. (b)do. What will be the output of the following program : void main() { int i.325 void main() { static int j. } (a)6 4 2 (b)Compile-Time Error (c)6 3 1 (d)Infinite Loop Ans. j+=j<5) printf("%d". for (i=5. (d)do{}while(1). for (j<5. i-=3) printf("%d ". j<5. _______________________________________________________________________ __________________________ [Q032].i). _______________________________________________________________________ __________________________ [Q034]. while(1). for (i--.j++). Which of the following code causes INFINITE Loop : (a)do while(1). (i)Only (a) these (ii)Only (b).i). ++i.

sum=0. j<i. What will be the output of the following program : #define Loop(i) for (j=0.sum). for (i=0. j++){ \ sum += i+j. printf("%d".326 Ans. \ } void main() { int i. i<=3. } (a)Run-Time Error (b)Compile-Time Error (c)18 (d)0 Ans. _______________________________________________________________________ __________________________ [Q035].j. _______________________________________________________________________ __________________________ (1) What will be output if you will compile and execute the following c code? void main(){ int i=320.*ptr). i++) Loop(i) printf("%d". char *ptr=(char *)&i. } (a)320 (b)1 (c)64 (d)Compiler error (e)None of above Output: (c) .

content of first byte is 01000000 and its decimal value is 64. Memory representation of int i=320 So char pointer ptr is pointing to only first byte as shown above figure.i). *ptr i.327 Explanation: As we know size of int data type is two byte while char pointer can pointer one byte at time. int and float data in memory? Data type tutorial. } (a)343 (b)27 (c)133 (d)Compiler error (e)None of above Output: (b) . (2) What will be output if you will compile and execute the following c code? #define x 5+2 void main(){ int i. i=x*x*x.e. How to represent char. printf("%d".

c 7: You can absorb #define only pastes the 5+2 in place of x in program.c 3: int i. test. i=5+2*5+2*5+2 =5+10+10+2 =27 What is intermediate file and how to see intermediate file? Preprocessor tutorial.c 6: } test.c 4: i=5+2*5+2*5+2.328 Explanation: As we know #define is token pasting preprocessor it only paste the value of micro constant in the program before the actual compilation start. So. test.c 1: test.c 2: void main(){ test. If you will see intermediate file you will find: test. (3) What will be output if you will compile and execute the following c code? void main(){ . test.i).c 5: printf("%d".

c=c+10. } (a)135 (b)+INF (c)-121 (d)-8 (e)Compiler error Output: (c) Explanation: As we know char data type shows cyclic properties i.e.c). if you will increase or decrease the char variables beyond its maximum or minimum value respectively it will repeat same value according to following cyclic order: So.329 char c=125. printf("%d". 125+1= 126 125+2= 127 125+3=-128 125+4=-127 125+5=-126 125+6=-125 125+7=-124 125+8=-123 125+9=-122 .

else if(a<5. So double constant 5.2 is double constant in c.2) printf("Less than"). else printf("Greater than"). if(a==5.330 125+10=-121 What is cyclic nature of data type? Data type tutorial. } (a)Equal (b)Less than (c)Greater than (d)Compiler error (e)None of above Output: (b) Explanation: 5. (4) What will be output if you will compile and execute the following c code? void main(){ float a=5. Size of float variable is 4 byte. In c size of double data is 8 byte while a is float variable.2) printf("Equal").2 is stored in memory as: .2.

3.00 11001100 11001100 11001100 11001100 11001100 11001101 Content of variable a will store in the memory as: 101.5.00110 01100110 01100110 It is clear variable a is less than double constant 5. printf("%d". If you want to see actual memory representation goes to question number (60) and (61).x).331 101. Number likes 4. 5. Data type tutorial.2 Since 5. } (a)21 (b)18 (c)12 (d)Compiler error (e)None of above Output: (a) Explanation: .0 will store same values in float and double data type. (5) What will be output if you will compile and execute the following c code? void main(){ int i=4.25.2 is recurring float number so it different for float and double. x=++i + ++i + ++i. Note: In memory float and double data is stored in completely different way.x.

332 In ++a. if(a==2){ a=~a+2<<1. Step 2: Start assigning final value 7 to all variable i in the expression. (b)-3 (c)-2 . So. ++ is pre increment operator. (6) What will be output if you will compile and execute the following c code? void main(){ int a=2. i=7+7+7=21 What is break point? Operator tutorial. } else { break. In any mathematical expression pre increment operator first increment the variable up to break point then starts assigning the final value to all variable. Step 1: Increment the variable I up to break point.a). printf("%d". } } (a)It will print nothing.

Hence it will show compiler error: Misplaced break Where we can use break keyword? Control statement tutorial (7) What will be output if you will compile and execute the following c code? void main(){ int a=10.333 (d)1 (e)Compiler error Output: (e) Explanation: Keyword break is not part of if-else statement.a++. } (a)12 11 11 (b)12 10 10 (c)11 11 12 (d)10 10 12 (e)Compiler error Output: (a) Explanation: In c printf function follows cdecl parameter passing scheme. So first ++a will pass and value of variable will be a=10 then a++ will pass now .a. In this scheme parameter is passed from right to left direction.++a). printf("%d %d %d".

What is cedecl and pascal parameter passing convention? Function tutorial.printf("%s". So. } (a) 11Hello world (b) 10Hello world (c) Hello world10 (d) Hello world11 (e) Compiler error Output: (d) Explanation: Return type of printf function is integer and value of this integer is exactly equal to number of character including white space printf function prints. printf(“Hello world”) will return 13.334 value variable will be a=10 and at the end a will pass and value of a will be a=12. (8) What will be output if you will compile and execute the following c code? void main(){ char *str="Hello world". printf("%d". What is prototype of printf function? .str)).

h" void main(){ char *str=NULL. More questions of string. strcpy(str.str). printf("%s". } (a)cquestionbank (b)cquestionbank\0 (c)(null) (d)It will print nothing (e)Compiler error Output: (c) Explanation: We cannot copy any thing using strcpy function to the character pointer pointing to NULL. (9) What will be output if you will compile and execute the following c code? #include "stdio. String tutorial.h" #include "string.335 Formatted I/O tutorial."cquestionbank"). .

(11) What will be output if you will compile and execute the following c code? . Complete tutorial of looping in C. for(.h" #include "string.336 (10) What will be output if you will compile and execute the following c code? #include "stdio.++i).h" void main(){ int i=0. } (a)0 1 2 (b)0 1 2 3 (c)1 2 3 (d)Compiler error (e)Infinite loop Output: (c) Explanation: In for loop each part is optional.) printf(" %d".i<=2.

Looping tutorial. . printf("%d".x++).x). for(x=1.337 void main(){ int x.x<=5. } (a)4 (b)5 (c)6 (d)Compiler error (e)None of above Output: (c) Explanation: Body of for loop is optional. In this question for loop will execute until value of variable x became six and condition became false.

(13) What will be output if you will compile and execute the following c code? . Detail explanation of all types of constant in C.338 (12) What will be output if you will compile and execute the following c code? void main(){ printf("%d".2)). } (a)2 (b)4 (c)8 (d)10 (e)Compiler error Output: (c) Explanation: Default type of floating point constant is double. So 5.2 is double constant and its size is 8 byte.sizeof(5.

2. As we know octal digits are: 0. 4. (14) What will be output if you will compile and execute the following c code? #define call(x. Hence ‘\08’ is invalid octal character constant. 6. } (a)8 (b)’8’ (c)9 (d)null (e)Compiler error Output: (e) Explanation: In c any character is starting with character ‘\’ represents octal number in character.y) x##y .h" #include "string. Hexadecimal character constant. 5. and 7.339 #include "stdio. printf("%d". So 8 is not an octal digit. 1. 3.h" void main(){ char c='\08'. Octal character constantan.c).

xy+xy). Intermediate file: test. printf("%d".c 5: } .y=10.340 void main(){ int x=5. test.c 4: printf("%d".c 3: int x=5. } (a)35 (b)510 (c)15 (d)40 (e)None of above Output: (d) Explanation: ## is concatenation c preprocessor operator.xy=20.c 2: void main(){ test.e.xy=20. test. a##b=ab If you will see intermediate file then you will find code has converted into following intermediate code before the start of actual compilation.xy+call(x.y)). It only concatenates the operands i.c 1: test.y=10.

a++. ptr=call(). } int * call(){ int a=25. What is macro call? Preprocessor tutorial. clrscr(). void main(){ int *ptr. } (a)25 (b)26 (c)Any address (d)Garbage value (e)Compiler error Output: (d) Explanation: .c 6: It is clear call(x. (15) What will be output if you will compile and execute the following c code? int * call(). printf("%d". return &a. y) has replaced by xy.*ptr).341 test.

Complete pointer tutorial. Output: (c) Explanation: It is necessary to assign name of inner structure at the time of declaration . struct inner{ char c. }. (a)Nesting of structure is not allowed in c. (b)It is necessary to initialize the member variable.342 In this question variable a is a local variable and its scope and visibility is within the function call. (16) What is error in following declaration? struct outer{ int a. (e)There is not any error. This problem is known as dangling pointer problem. (d)Outer structure must have name. }. (c)Inner structure must have name. After returning the address of a by function call variable a became dead while pointer ptr is still pointing to address of variable a.

20. Union tutorial.30. }name. So correct declaration is: struct outer{ int a.-2[array]). } (a)-60 (b)-30 (c)60 . }.343 other wise we cannot access the member of inner structure. struct inner{ char c. Structure tutorial. (17) What will be output if you will compile and execute the following c code? void main(){ int array[]={10.40}. printf("%d".

. How to read complex pointers. array[2]=*(array+2)=*(2+array)=2[array]=30 Array tutorial. Array of pointer.344 (d)Garbage value (e)Compiler error Output: (b) Explanation: In c. (18) What will be output if you will compile and execute the following c code? void main(){ int i=10.

if(x==i) printf("Equal"). else printf("Less than"). We can not initialize any load time variable by the run time variable.345 static int x=i. In this example i is run time variable while x is load time variable. else if(x>i) printf("Greater than"). What is storage class? (18) What will be output if you will compile and execute the following c code? void main(){ . } (a)Equal (b)Greater than (c)Less than (d)Compiler error (e)None of above Output: (d) Explanation: static variables are load time entity while auto variables are run time entity.

Hence i= 6 and j=3 .i+j). In C logical OR operator doesn’t check second operand if first operand is true.346 int i=5.j=2. if(++i>j++||i++>j++) printf("%d". ++i>j++ || i++>j++ First operand: ++i>j++ Second operand: i++>j++ First operand ++i > j++ => 6 > 2 Since first operand is true so it will not check second operand. } (a)7 (b)11 (c)8 (d)9 (e)Compiler error Output: (d) Explanation: || is logical OR operator.

i++). If you will see intermediate file: test.347 Properties of && operator. (19) What will be output if you will compile and execute the following c code? #define max 5. Operator tutorial with examples. void main(){ int i=0.i . i=max++. } (a)5 (b)6 (c)7 (d)0 (e)Compiler error Output: (e) Explanation: #define is token pasting preprocessor. printf("%d".

What is Lvalue and Rvalue? How to see intermediate file? Preprocessor questions and answer.c 6: } test. printf("%d".c 1: test. . Hence compiler will show Lvalue required. It is illegal to increment the constant number. test. test.c 2: void main(){ test.sizeof(p)+sizeof q).c 5: printf("%d". test. (20) What will be output if you will compile and execute the following c code? void main(){ double far* p.c 3: int i=0.348 test.c 4: i=5++.c 7: It is clear macro constant max has replaced by 5.i++).q.

What is near pointer? What is far pointer? What is huge pointer? Complete pointer tutorial.349 } (a)12 (b)8 (c)4 (d)1 (e)Compiler error Output: (a) Explanation: It is clear p is far pointer and size of far pointer is 4 byte while q is double variable and size of double variable is 8 byte. .

printf(" %d". printf("%d". Hence value of variable a will remain 5. Value of any variable doesn’t modify inside sizeof operator.350 (21) What will be output if you will compile and execute the following c code? void main(){ int a=5.a). float b.sizeof(++a+b)). . } (a)2 6 (b)4 6 (c)2 5 (d)4 5 (e)Compiler error Output: (d) Explanation: ++a +b =6 + Garbage floating point number =Garbage floating point number //From the rule of automatic type conversion Hence sizeof operator will return 4 because size of float data type in c is 4 byte.

351 Properties of sizeof operator. char huge *q=(char *)0XC2551341. else if(p>q) printf("Greater than"). if(p==q) printf("Equal"). else printf("Less than"). Operators tutorial (22) What will be output if you will compile and execute the following c code? void main(){ char huge *p=(char *)0XC0563331. } (a)Equal (b)Greater than (c)Less than (d)Compiler error (e)None of above .

Physical address of huge pointer p Huge address: 0XC0563331 Offset address: 0x3331 Segment address: 0XC056 Physical address= Segment address * 0X10 + Offset address =0XC056 * 0X10 +0X3331 =0XC0560 + 0X3331 =0XC3891 Physical address of huge pointer q Huge address: 0XC2551341 Offset address: 0x1341 Segment address: 0XC255 .352 Output: (a) Explanation: As we know huge pointers compare its physical address.

(c)It will accept a paragraph as a string from user. What is huge pointer? What is normalization? Pointer tutorial. (23) What will be output if you will compile and execute the following c code? void main(){ char *str.353 Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 =0XC2550 + 0X1341 =0XC3891 Since both huge pointers p and q are pointing same physical address so if condition will true.str). (d)Compiler error . } (a)It will accept a word as a string from user. (b)It will accept a sentence as a string from user.str). scanf("%[^\n]". printf("%s".

354

(e)None of above Output: (b) Explanation: Task of % [^\t] is to take the stream of characters until it doesn’t receive new line character ‘\t’ i.e. enter button of your keyboard.

General meaning of %[^ p]

String tutorial.

(24) What will be output if you will compile and execute the following c code?

void main(){ int a=5,b=10,c=15; int *arr[]={&a,&b,&c}; printf("%d",*arr[1]); }

(a)5 (b)10 (c)15 (d)Compiler error (e)None of above

355

Output: (d) Explanation: Array element cannot be address of auto variable. It can be address of static or extern variables.

What is auto variable?

What is extern variable?

What is static variable?

Array tutorial.

(25) What will be output if you will compile and execute the following c code?

void main(){ int array[3]={5}; int i; for(i=0;i<=2;i++) printf("%d ",array[i]); }

(a)5 garbage garbage

356 (b)5 0 0 (c)5 null null (d)Compiler error (e)None of above tput: (b) Explanation: Storage class of an array which initializes the element of the array at the time of declaration is static. Default initial value of static integer is zero.

Properties of static storage class.

How to read complex array.

(26) What will be output if you will compile and execute the following c code?

void main(){ int array[2][2][3]={0,1,2,3,4,5,6,7,8,9,10,11}; printf("%d",array[1][0][2]); }

(a)4 (b)5 (c)6 (d)7

357 (e)8

Output: 8 Explanation: array[1][0][2] means 1*(2*3)+0*(3)+3=9th element of array starting from zero i.e. 8.

Questions on two dimension array.

Complete tutorial of array.

(27) What will be output if you will compile and execute the following c code?

void main(){ int a[2][4]={3,6,9,12,15,18,21,24}; printf("%d %d %d",*(a[1]+2),*(*(a+1)+2),2[1[a]]); }

358

(a)15 18 21 (b)21 21 21 (c)24 24 24 (d)Compiler error (e)None of above

Output: (b) Explanation: In c, a [1][2] =*(a [1] +2) =*(*(a+1) +2) =2[a [1]] =2[1[a]] Now, a [1] [2] means 1*(4) +2=6th element of an array staring from zero i.e. 21.

359 Concept of complex array.

Concept of complex pointer.

Concept of complex function.

(28) What will be output if you will compile and execute the following c code? void call(int,int,int); void main(){ int a=10; call(a,a++,++a); } void call(int x,int y,int z){ printf("%d %d %d",x,y,z); } (a)10 10 12 (b)12 11 11 (c)12 12 12 (d)10 11 12 (e)Compiler error

360

Output: (b) Explanation: Default parameter passing scheme of c is cdecl i.e. argument of function will pass from right to left direction.

First ++a will pass and a=11 Then a++ will pass and a=11 Then a will pass and a=12

What is pascal and cedecl parameter passing scheme?

Concept of variable numbers of argument.

(29) What will be output if you will compile and execute the following c code?

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

361 (a)Garbage Garbage Garbage (b)5 10 15 (c)15 10 5 (d)Compiler error (e)Run time error

Output: (c) Explanation: Auto variables are stored in stack as shown in following figure.

Stack follow LIFO data structure i.e. last come and first out. First %d will print then content of two continuous bytes from the top of the stack and so on.

Memory map tutorial.

More questions based on memory map.

362

(30) What will be output if you will compile and execute the following c code?

void main(){ register int i,x; scanf("%d",&i); x=++i + ++i + ++i; printf("%d",x); }

(a)17 (b)18 (c)21 (d)22 (e)Compiler error

Output: (e) Explanation:

363

In c register variable stores in CPU it doesn’t store in RAM. So register variable have not any memory address. So it is illegal to write &a.

Complete tutorial of storage class with examples.

Properties of register storage class.

(31) What will be output if you will compile and execute the following c code? void main(){ int a=5; int b=10; { int a=2; a++; b++; } printf("%d %d",a,b); } (a)5 10 (b)6 11 (c)5 11 (d)6 10 (e)Compiler error

Output: (c)

364

Explanation: Default storage class of local variable is auto. Scope and visibility of auto variable is within the block in which it has declared. In c, if there are two variables of the same name then we can access only local variable. Hence inside the inner block variable a is local variable which has declared and defined inside that block. When control comes out of the inner block local variable a became dead.

Complete tutorial of storage class with examples.

What is auto storage class?

(32) What will be output if you will compile and execute the following c code?

void main(){ float f=3.4e39; printf("%f",f); }

(a)3.4e39 (b)3.40000… (c)+INF (d)Compiler error (e)Run time error

365

Output: (c) Explanation: If you will assign value beyond the range of float data type to the float variable it will not show any compiler error. It will store infinity.

Data type tutorial with examples.

Concept of float data type.

(33) What will be output if you will compile and execute the following c code?

void main(){ enum color{ RED,GREEN=-20,BLUE,YELLOW }; enum color x; x=YELLOW; printf("%d",x); } (a)-22

(34) What will be output if you will compile and execute the following c code? void main(){ asm{ .366 (b)-18 (c)1 (d)Compiler error (e)None of above Output: (b) Explanation: Default value of enum constant = value of previous enum constant +1 Default value of first enum constant=0 Hence: BLUE=GREEN+1=-20+1=-19 YELLOW=BLUE+1=-19+1=-18 Complete tutorial of enum data type with examples.

in bx._BX). .367 mov bx.8. mov command stores the constants in the register bx.e. add command stores the content of register and stores in first register i.10 add bx.cx. } printf("%d". } (a)18 (b)8 (c)0 (d)Compiler error (e)None of above Output: (a) Explanation: asm keyword is used to write assembly language program in c. mov cx. cx etc.

(35) What will be output if you will compile and execute the following c code? void main(){ enum xxx{ a.c=32767.e }. printf("%d".b.d. } (a)0 (b)1 (c)32766 (d)Compiler error (e)None of above .b).368 How to write assembly language program by c? Advance c tutorial.

} (a)-1 -1 (b)-1 32767 (c)-1 -32768 (d)Not equal (e)Compiler error . Tutorial of data type with examples. else printf("Not equal").b). (36) What will be output if you will compile and execute the following c code? void main(){ signed int a=-1.369 Output: (d) Explanation: Size of enum constant is size of sign int. Hence value of d will be 32767+1=32768 which is beyond the range of enum constant. if(a==b) printf("%d %d".a. Since value of c=32767. unsigned int b=-1.

500000 (b)1. float x.000000 (c)5.5f.x).370 Output: (a) Explanation: What is automatic type conversion? (37) What will be output if you will compile and execute the following c code? void main(){ float f=5.500000 (d)Compiler error (e)None of above . printf("%f". x=f%2. } (a)1.

371 Output: (d) Explanation: Modular division is not allowed with floating number. int b=-3.a%b). printf("%d". Properties of modular division. } (a)2 (b)-2 . Operators tutorial with examples. (38) What will be output if you will compile and execute the following c code? void main(){ int a=-20.

} (a)1 1 .sizeof(c).372 (c)18 (d)-18 (e)Compiler error Output: (b) Explanation: Sign of resultant of modular division depends upon only the sign of first operand. Operator’s tutorial with examples. (39) What will be output if you will compile and execute the following c code? void main(){ char c='0'.sizeof('0')). printf("%d %d". Properties of modular division.

Why character constant is of two byte in c? (40) What will be output if you will compile and execute the following c code? void main(){ char *url="c:\tc\bin\rw. printf("%s". } .373 (b)2 2 (c)1 2 (d)2 1 (e)None of above Output: (c) Explanation: Size of char data type is one byte while size of character constant is two byte.url).c".

3.c (b)c:/tc/bin/rw. Properties of escape characters. 2. \t is tab character which moves the cursor 8 space right.c (d)c:cinw.c (c)c: c inw. \b is back space character which moves the cursor one space back.c (e)w. . \r is carriage return character which moves the cursor beginning of the line. Complete string tutorial with examples.c in Output: (e) Explanation: 1.374 (a)c:\tc\bin\rw.

} void dispaly(){ abc : printf("display"). printf("main"). getch().375 (41) What will be output if you will compile and execute the following c code? void main(){ clrscr(). goto abc. } (a)main (b)display (c)maindisplay (d)displaymain (e)Compiler error Output: (e) .

376 Explanation: Label of goto cannot be in other function because control cannot move from one function to another function directly otherwise it will show compiler error: unreachable label What is goto keyword. } (a)1 (b)48 (c)24 (d)Not equal (e)Compiler error . Complete function tutorial with examples. if(3==i) printf("%d".i<<2<<1). (42) What will be output if you will compile and execute the following c code? void main(){ int i=3. else printf("Not equal").

(43) What will be output if you will compile and execute the following c code? . From rule of associative leftmost operator will execute first.2) =3* What is associative? What is precedence? Tutorial of bitwise operators.377 Output: (c) Explanation: Associative of bitwise left shifting operator is left to right. i <<><<> After execution of leftmost bitwise left shifting operator: so i=i*pow(2. In the following expression: i<<2<<1 There are two bitwise operators.

} (a)True (b)False (c)Compiler error: Lvalued required (d)Compiler error: Invalid expression (e)None of above Output: (a) Explanation: Expression x+y<=5 => 2+3 <=5 . if(x+y<=5) printf("True"). else printf("False").y=3.378 void main(){ int x=2.

(44) What will be output if you will compile and execute the following c code? void main(){ const int i=5.379 => 5<=5 is true because 5 is either greater than 5 or equal to 5. } (a)5 (b)6 (c)0 (d)Compiler error (e)None of above Output: (d) . printf("%d".i). i++. Operator tutorial with examples.

Data type tutorial with examples. int * const p=&x. } (a)25 (b)50 (c)0 (d)Compiler error (e)None of above . Properties of volatile keyword.x). *p=2*x. Properties of const keyword. printf("%d". (45) What will be output if you will compile and execute the following c code? void main(){ const int x=25.380 Explanation: We cannot modify the const variable by using increment operator.

What is constant pointer? Data type tutorial with examples. With the help of pointer we can modify the const variable. p is constant pointer while content of p i.e. *p is not constant. (46) What will be output if you will compile and execute the following c code? void main(){ . Properties of const keyword. In the following line: int * const p=&x.381 Output: (b) Explanation: const keyword in c doesn’t make any variable as constant but it only makes the variable as read only. In this example pointer p is pointing to address of variable x. *p=2*x put the value 50 at the memory location of variable x.

*p i.e.382 int i=11. content of p is constant pointer p is not constant pointer. After incrementing the pointer it will point next memory location and its content will any garbage value. printf("%d". int const * p=&i. p++. } (a)11 (b) 12 (c)Garbage value (d)Compiler error (e)None of above Output: (c) Explanation: In the following line: int const * p=&i. . So we can modify the pointer p.*p).

} .b=10.c=5. Properties of volatile keyword. Properties of const keyword. (47) What will be output if you will compile and execute the following c code? void main(){ int a=15.383 Note: We have assumed arbitrary memory address. To make pointer p as constant pointer write: int const * const p=&i. else printf("False"). if(a>b>c ) printf("Trre").

Now expression became: . So in the following expression a>b>c Associative of relational operators are left to right order of execution will be following manner: Hence in this expression first solve bolded condition: a > b > c Since condition a>b is true so result will be 1.384 (a)True (b)False (c)Run time error (d)Compiler error (e)None of above Output: (b) Explanation: Relation operator in c always returns 1 when condition is true and 0 when condition is false.

} (a)1. What is associative? What is precedence? (48) What will be output if you will compile and execute the following c code? void main(){ float f.385 1>c Since this condition is false so result will be 0.000000 (d)Compiler error (e)None of above Output: (c) Explanation: .f). f=3/2.5 (b)1.500000 (c)1. Thus else part will execute. printf("%f".

1. } int modify(int x){ int y=3. return. Properties of floating type numbers. } (a)2 (b)3 (c)5 (d)Garbage value (e)None of above . (49) What will be output if you will compile and execute the following c code? void main(){ int a=sizeof(a). _AX=x+y. a=modify(a).386 In the following expression: f=3/2 both 3 and 2 are integer constant hence its result will also be an integer constant i. printf("%d".e.a).

void main(){ float a=5. It stores return type of function. } (a)c c++ (b)Not equal (c)c c++ . What is register pseudo variable? What is global identifier? (50) What will be output if you will compile and execute the following c code? #define PRINT printf("c").printf("c++"). if(a==5.5) PRINT else printf("Not equal").5.387 Output: (c) Explanation: _AX is register pseudo variable.

c 8: } try.c 9: try.5.388 (d)Compiler error (e)None of above Output: (d) Explanation: First see intermediate file: try.c 7: printf("Not equal").c 4: if(a==5.c 1: try.printf("c++").c 3: float a=5.c 2: void main(){ try.c 10: .c 6: else try. try.5) try.c 5: printf("c"). try. try.

. Preprocessor tutorial with examples. Links to this post 2 comments C questions and answer (51) What will be output if you will compile and execute the following c code? struct marks{ int p:3.5}. int m:2.389 If there are more than one statement in if block then it is necessary to write inside the { } otherwise it will show compiler error: misplaced else More questions on preprocessors.-6. }. void main(){ struct marks s={2. int c:3.

s.m).p. } (a) 2 -6 5 (b) 2 -6 1 (c) 2 2 1 (d) Compiler error (e) None of these Answer: (c) Explanation: Binary value of 2: 00000010 (Select three two bit) Binary value of 6: 00000110 Binary value of -6: 11111001+1=11111010 (Select last three bit) Binary value of 5: 00000101 (Select last two bit) Complete memory representation: Structure tutorial More questions (52) What will be output if you will compile and execute the following c code? void main(){ .s.c.s.390 printf("%d %d %d".

p2+=1.&p2.391 static char *s[3]={"math"."che"}."phy". printf("%s". char * (*(*array[3]))[3]={&p1.&p3}. static ppp p1=&s.(***ptr[0])[2]). typedef char *( *ppp)[3]. } (a) math (b) phy (c) che (d) Compiler error (e) None of these Answer: (c) . char * (*(*(*ptr)[3]))[3]=&array.p2=&s.p3=&s. p3+=2.

392 Explanation: Here ptr: is pointer to array of pointer to string. p2. Pictorial representation: Note: In the above figure upper part of box represent content and lower part represent memory address. p3: are pointers to array of string. P1. array[3]: is array which contain pointer to array of string. As we know p[i]=*(p+i) (***ptr[0])[2]=(*(***ptr+0))[2]=(***ptr)[2] =(***(&array))[2] //ptr=&array =(**array)[2] //From rule *&p=p =(**(&p1))[2] //array=&p1 =(*p1)[2] =(*&s)[2] //p1=&s =s[2]=”che” How to read complex pointer? . We have assumed arbitrary address.

return x++.(**ptr)()). ptr=&array. void main(){ array[0]=display. int(*array[3])(). (53) What will be output if you will compile and execute the following c code? #include"conio. array[1]=getch. } (a)5 (b)6 (c)0 . } int display(){ int x=5.h" int display(). int(*(*ptr)[3])(). (*(*ptr+1))(). printf("%d".393 Pointer tutorial.

ptr: It is pointer to array which contents are pointer to such function which parameter is void and return type is int type data. (**ptr)() = (** (&array)) () //ptr=&array = (*array) () // from rule *&p=p =array [0] () //from rule *(p+i)=p[i] =display () //array[0]=display (*(*ptr+1))() =(*(*&array+1))() //ptr=&array =*(array+1) () // from rule *&p=p =array [1] () //from rule *(p+i)=p[i] .394 (d)Compiler error (e)None of these Answer: (a) Explanation: In this example: array []: It is array of pointer to such function which parameter is void and return type is int data type.

*ptr='A'. *(ptr+1)=1. char far *ptr=(char *)0XB8000000. *(ptr+5)=4. *(ptr+4)='C'. *(ptr+3)=2. } . *(ptr+2)='B'.395 =getch () //array[1]=getch How to read complex array? Array tutorial. (54) What will be output if you will compile and execute the following c code? void main(){ int i.

o.h. green and red color respectively. (55) What will be output if you will compile and execute the following c code? #include "dos. i. As shown in following figure: What is far pointer? Advance c tutorial? Working with text video memory. char far *ptr=(char *)0XA0000000. .396 Answer: It output will be A.h.h" void main(){ int j. union REGS i.al=0x13. B and C in blue. i.ah=0.

397 int86(0x10.&i. } } Answer: One red color line in the graphics console as shown in the following figure What is union REGS? Advance c tutorial.&o). . for(j=1.j++){ *(ptr+j)=4.j<=100.

(56) What will be output if you will compile and execute the following c code? void main(){ int huge*p=(int huge*)0XC0563331. printf("%d".398 Working with graphics video memory. *p=200.*q). int huge*q=(int huge*)0xC2551341. } (a)0 (b)Garbage value (c)null (d) 200 (e)Compiler error .

399 Answer: (d) Explanation: Physical address of huge pointer p Huge address: 0XC0563331 Offset address: 0x3331 Segment address: 0XC056 Physical address= Segment address * 0X10 + Offset address =0XC056 * 0X10 +0X3331 =0XC0560 + 0X3331 =0XC3891 Physical address of huge pointer q Huge address: 0XC2551341 Offset address: 0x1341 Segment address: 0XC255 Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 .

y coordinate)? Answer: #include”dos. What is huge pointer? Pointer tutorial. (57) Write c program which display mouse pointer and position of pointer. //show mouse pointer . int x.o.h” #include”stdio.(In x coordinate.y.k.h” void main() { union REGS i.400 =0XC2550 + 0X1341 =0XC3891 Since both huge pointers p and q are pointing same physical address so content of q will also same as content of q.

. y=o.x. //get mouse position x=o. while(!kbhit()) //its value will false when we hit key in the key board { i.cx. } What is int86? Advance c tutorial. clrscr().ax=3. int86(0x33.x. } getch().&i.ax=1.401 i.&o).&o). delay(250).y). (58) Write a c program to create dos command: dir. printf("(%d .&i.x. %d)".dx. Answer: Step 1: Write following code.x. int86(0x33.x.

if(a==0) { while (!a) { printf(" %s\n". } } else { printf("File not found"). } } . a = _dos_findnext(&q).1.*". int a.h” void main(int count. a = _dos_findfirst(argv[1]. if(count==1) argv[1]="*.char *argv[]) { struct find_t q .402 #include “stdio.&q). q.name).h” #include “dos.

c (You can give any name) Step 3: Compile and execute the file. Command line argument tutorial. (59) What will be output if you will compile and execute the following c code? . Step 5: Select Advanced -> Environment Variables Step 6: You will find following window: Click on new button (Button inside the red box) Step 7: Write following: Variable name: path Variable value: c:\tc\bin\list.403 Step 2: Save the as list.c (Path where you have saved) Step 8: Open command prompt and write list and press enter. Step 4: Write click on My computer of Window XP operating system and select properties.

404 void main(){ int i=10. } (a) Equal (b) Greater than (c) Less than (d) Compiler error (e) None of above . if(x==i) printf("Equal"). else if(x>i) printf("Greater than"). else printf("Less than"). static int x=i.

i++) printf("%d ". We can not initialize any load time variable by the run time variable.i<=3. char *ptr. (60) What will be output if you will compile and execute the following c code? void main(){ int i.*ptr++). for(i=0.405 Answer: (d) Explanation: static variables are load time entity while auto variables are run time entity. } (a)0 0 0 0 (b)Garbage Garbage Garbage Garbage (c)102 56 -80 32 (d)102 102 -90 64 . In this example i is run time variable while x is load time variable. ptr=(char *)&a. float a=5.2. Properties of auto variables. Properties of static variables.

Content of fourth byte: Binary value=01100110 Decimal value= 64+32+4+2=102 Content of third byte: Binary value=01100110 Decimal value=64+32+4+2=102 .406 (e)Compiler error Answer: (d) Explanation: In c float data type is four byte data type while char pointer ptr can point one byte of memory at a time. Memory representation of float a=5.2 ptr pointer will point first fourth byte then third byte then second byte then first byte.

2. char *ptr. for(i=0.407 Content of second byte: Binary value=10100110 Decimal value=-128+32+4+2=-90 Content of first byte: Binary value=01000000 Decimal value=64 Note: Character pointer treats MSB bit of each byte i.*ptr++). How to represent float data type in memory? (61) What will be output if you will compile and execute the following c code? void main(){ int i. } . double a=5.e. left most bit of above figure as sign bit.i++) printf("%d ". ptr=(char *)&a.i<=7.

2 ptr pointer will point first eighth byte then seventh byte then sixth byte then fifth byte then fourth byte then third byte then second byte then first byte as shown in above figure.408 (a) -51 -52 -52 -52 -52 -52 20 64 (b) 51 52 52 52 52 52 20 64 (c) Eight garbage values. Memory representation of double a=5. (d) Compiler error (e) None of these Answer: (a) Explanation: In c double data type is eight byte data type while char pointer ptr can point one byte of memory at a time. .

409 Content of eighth byte: Binary value=11001101 Decimal value= -128+64+8+4+1=-51 Content of seventh byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of sixth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of fifth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of fourth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of third byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of second byte: Binary value=000010100 Decimal value=16+4=20 Content of first byte: Binary value=01000000 .

"c" "question" "bank"). left most bit of above figure as sign bit. How to represent double data type in memory? (62) What will be output if you will compile and execute the following c code? void main(){ printf("%s". } (a) c question bank (b) c (c) bank (d) cquestionbank (e) Compiler error .e.410 Decimal value=64 Note: Character pointer treats MSB bit of each byte i.

411 Answer: (d) Explanation: In c string constant “xy” is same as “x” “y” String tutorial.__DATE__). (63) What will be output if you will compile and execute the following c code? void main(){ printf("%s". } (a) Current system date (b) Current system date with time (c) null (d) Compiler error (e) None of these .

7.*s". } (a) c-pointer (b) c-pointer (c) c-point (d) cpointer null null (e) c-point . printf("%*. What is global identifier? (64) What will be output if you will compile and execute the following c code? void main(){ char *str="c-pointer".str).412 Answer: (a) Explanation: __DATE__ is global identifier which returns current system date.10.

*s in the printf function: First * indicates the width i.e. void main(){ . (65) What will be output if you will compile and execute the following c code? void start(). how many spaces will take to print the string and second * indicates how many characters will print of any string.413 Answer: (e) Explanation: Meaning of %*. void end(). #pragma startup start #pragma exit end int static i. Following figure illustrates output of above code: Properties of printf function.

printf("\nstart function: %d". } void end(){ printf("\nend function: %d". } void start(){ clrscr().++i).++i). getch().414 printf("\nmain function: %d".++i). } (a) main function: 2 start function: 1 end function:3 (b) start function: 1 main function: 2 end function:3 (c) main function: 2 .

(66) What will be output if you will compile and execute the following c code? . But #pragma startup can call function just before main function and #pragma exit What is pragma directive? Preprocessor tutorial.415 end function:3 start function: 1 (d) Compiler error (e) None of these Answer: (b) Explanation: Every c program start with main function and terminate with null statement.

printf("%d". .e. } (a) -4 (b) -3 (c) -2 (d) -96 (e) Compiler error Answer :( c) Explanation: Binary value of 12 is: 00000000 00001100 Binary value of -12 wills 2’s complement of 12 i.416 void main(){ int a=-12.a). a=a>>3.

Rule 2: If number is negative the fill vacant spaces in the left side by 1. Hence final out put will be: . In this case number is negative.417 So binary value of -12 is: 11111111 11110100 Right shifting rule: Rule 1: If number is positive the fill vacant spaces in the left side by 0. So right shift all the binary digits by three space and fill vacant space by 1 as shown following figure: Since it is negative number so output will also a negative number but its 2’s complement.

Operator tutorial.h" void main(){ clrscr(). printf("%d %d".418 And its decimal value is: 2 Hence output will be:-2 More questions on shifting operator.strlen("string")). } (a) 6 6 (b) 7 7 (c) 6 7 . (67) What will be output if you will compile and execute the following c code? #include "string.sizeof("string"). getch().

x=call(main). Library functions of string. int x. (68) What will be output if you will compile and execute the following c code? void main(){ static main. .419 (d) 7 6 (e) None of these Answer: (d) Explanation: Sizeof operator returns the size of string including null character while strlen function returns length of a string excluding null character. clrscr(). String tutorial.

x). return address. Word main can be name variable in the main and other functions.420 printf("%d ". } int call(int address){ address++. What is main function in c? (69) What will be output if you will compile and execute the following c code? . } (a) 0 (b) 1 (c) Garbage value (d) Compiler error (e) None of these Answer: (b) Explanation: As we know main is not keyword of c but is special type of function. getch().

printf("%d ". clrscr(). a=1.15. b=(2. getch().421 void main(){ int a.b.4.6). } (a) 3 (b) 21 (c) 17 (d) 7 (e) Compiler error Answer: (d) Explanation: .a+b).3.

15. Assigning the priority of each operator in the second statement: . 3. a=1. Comma enjoys least precedence and associative is left to right. 4. b= (2. Assigning the priority of each operator in the first statement: Hence 1 will assign to a. In the above two statements comma is working as operator. 6).422 In c comma behaves as separator as well as operator.

. printf("%d %d ".)..10.x.4. void main(){ int x. s=*(int *)ptr. return s... ptr=..){ void *ptr.. y=dynamic(3.12.6.9. x=dynamic(2.14).8. } int dynamic(int s. } . (int *)ptr+=2..y.12). getch()...6. (70) What will be output if you will compile and execute the following c code? int dynamic(int.423 Operator tutorial. clrscr().y).

424 (a) 8 12 (b) 14 12 (c) 2 3 (d) Compiler error (e) None of these Answer: (a) Explanation: In c three continuous dots is known as ellipsis which is variable number of arguments of function. In this example ptr is generic pointer which is pointing to first element of variable number of argument. What is variable number of argument? (71) What will be output if you will compile and execute the following c code? int extern x. After incrementing it will point third element. void main() .

Properties of extern storage class. . x=2. (a) 0 (b) 2 (c) 23 (d) Compiler error (e) None of these Answer: (c) Explanation: extern variables can search the declaration of variable any where in the program. } int x=23.x). getch().425 printf("%d".

printf("%d". } (a) 5 (b) 3 (c) 1 (d) equal (e) None of above Answer: (c) .(i=3)). } else printf("equal").i=1). if(i==0){ i=((5.i).426 (72) What will be output if you will compile and execute the following c code? void main(){ int i=0.

a. getch(). printf("%o %x". (73) What will be output if you will compile and execute the following c code? void main(){ int a=25. Operator tutorial.427 Explanation: Comma operator. } (a) 25 25 (b) 025 0x25 (c) 12 42 (d) 31 19 (e) None of these .a). clrscr().

getch().428 Answer: (d) Explanation: %o is used to print the number in octal number format. Note: In c octal number starts with 0 and hexadecimal number starts with 0x. printf("%s".message). What is octal number? What is hexadecimal number? (74) What will be output if you will compile and execute the following c code? #define message "union is\ power of c" void main(){ clrscr(). . %x is used to print the number in hexadecimal number format.

Preprocessor tutorial.429 } (a) union is power of c (b) union ispower of c (c) union is Power of c (d) Compiler error (e) None of these Answer: (b) Explanation: If you want to write macro constant in new line the end with the character \. (75) What will be output if you will compile and execute the following c code? .

First see the intermediate file: test. It converts the macro function call argument in the string.call(c/c++)). } (a)c (b)c++ (c)#c/c++ (d)c/c++ (e)Compiler error Answer: (d) Explanation: # is string operator.430 #define call(x) #x void main(){ printf("%s".c 1: test.c 2: void main(){ .

431 test.c 3: printf("%s"."c/c++"). What is # and ##? Preprocessor tutorial? (75) What will be output if you will compile and execute the following c code? void main(){ if(printf("cquestionbank")) printf("I know c").c 5: It is clear macro call is replaced by its argument in the string format. else printf("I know c++").c 4: } test. test. } (a) I know c (b) I know c++ (c) cquestionbankI know c (d) cquestionbankI know c++ .

So printf function inside if condition will return 13. Any of the following programs in c has access to three standard files: 1) standard input file.zero number means true so else part will not execute.the appearance of the output of the output can be affected by 1) field with 3) flag 2) conversion character 4) all of the above 3. In if condition any non. In printf(). Which of the following does not have an unary operator? 1) -7 3) j 2) ++i 4) all of the above 2. standard output file.432 (e) Compiler error Answer: (c) Explanation: Return type of printf function is integer which returns number of character it prints including blank spaces. standard error file . Prototype of printf function. 1.

stderr 3) keyboard.screen 4) all the above 5) A variable can be declared static using the keyword.stdout. 1) extern 2) static 3) stat 4) auto 6) A program can be terminated at any time by calling the function 1) fflush() 3) exit() 7) Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above 8) A function can 1) perform a task 2) return a value 3) change value of actual arguments in call by reference 4) all of the above 2) ferror() 4) clearerr() 9) Function definition void check(int i .screen.char*j) is 1) call by value 2)call by reference 3) both (1) and (2) 4)in valid function definition 10) A union consists of a number of elements that 1) all occupy the same space in memory 2) must be structure 3) are grouped next to each other in memory 4) all have the same type 11) Which of the following array is defined in the statements Char name[30]? 1) name is one dimensiona.433 2) stdin.30-element integer array .

Char c=’c’.j=5. and the second is an integer 3) f accepts three arguments and returns nothing. {2.2.1 2) 1.0005.1.y=-0.d=’d’.2.3}.30-element floating point array 3) name is one dimensional . The first arguments is a double-precision quantity.434 2) name is one dimensional.2 4) 2. float x=0.3} }.2. What would be the value of the following expression? (3*i-2*j)%(2*d-3) 1)14 3) 1 2)18 4) 0 14) The declaration : int f(int).1.3 13) A c program contains the following declarations and initial Assignments: int i=8.01. What is the value of *(*(table+1)+1)? 1) 2.2 3) 2. means 1) f accepts an integer argument and returns an integer quantity 2) f accepts two arguments and returns a double precision quantity. and the second is an integer 4) f does not accepts any arguments but returns a single character 16) The arguments of a function are included between 1) The parenthesis 2) double quotes 3) curly braces 4) # 17) The int type of constraints are whole numbers in the range 1) -23677 to 23678 3) -32767 to 32768 2) -32768 to 32767 4) -32864 to 32864 .2.1.30-elements string array 12) c program contains the following declaration: Static float table[2][3]={ {1.1.30-element character array 4) name is one dimensional.

1) 2) 3) 4) assigns an integer to the variable i gives an error message. 1) gives an error message 3) assigns a value 18 to i 2) assigns a value 16 to i 4) assigns a value 19 to i 19) In a relational expression involving characters. 3) pointer *p. 25)The null character is represented by 1) \n 2)\0 3)\o 4)\t . does not assign any value to i assigns an float to the variable i 24) A pointer is declared by using a statement such as 1) int *p.&i). we actually Compare 1) 2) 3) 4) the ASCII codes of the characters the characters themselves neither of the two binary code and hexadecimal code 21) The word case used in the switch statement represents a 1) 2) 3) 4) function in the c language data type in the c language keyword in the c language global variable in the c language 22)The logical NOT operator represented by ! is a 1) unary operator 3) ternary operator 2) binary operator 4) octal operator 23) The statement : scanf(“%d”. 4) int &p.3 and 2 respectively.435 18) If the variables i. then the expression i=j+(k++ =6)+7.j and k are assigned the values 5. 2) point.

square brackets [ ] are used in 1) functions 2) arrays 3) statements 4) all of the above 30) A fields width specifier in a printf() function 1) specifies the maximum value of a number 2) controls the size of type used to print numbers 3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number 31) The two operators && and || are 1) arithmetic operators 3) logical operators 2) equality operators 4) relational operators 32) The library files that come with c are 1) text editor for program development 2) the compiler and liker 3) program examples 4) files that contain functions which carry out various commonly Used operations and calculations 33) Precedence determines which operator .436 26) The members in the union 1) have different memory locations 2) share the memory with a structure 3) have the same memory location 4) have different memory variable 27) The global variables by default belong to 1) the register type 3) the auto type 2) the static type 4) the dynamic type 28) The bit fields are the members of a/an 1) array 2) structure 3) union 4) both 2 and 3 29) In c.

437 1) is evaluated first 3) is fastest 2) is most important 4) operates on the largest number 37) The malloc() function 1) returns a pointer to the allocated memory 2) returns a pointer to the first byte of region of memory 3) changes the size of the allocated memory 4) deallocates the memory 38) which of the following expressions will return a 1 if both bits have A value of 1. otherwise will return a value of 0? 1) AND 2)OR 3)XOR4)1’stderr complement 39) If an error occurs while opening a file the file pointer is assigned a value 1) NULL 2) stdout 3) sstderr 4) not defined 40) Which of the following backslash codes used for bell? 1) \b 2) \a 3) \r 4) \s 41) One is not the valid keywords in the c language is 1) printf 2) CHAR 3) auto 4) scanf 42) The comments in a c language program are placed between 1) \* and /* 2) / and .* 3) /*and*/ 4) # and # 43) If p and q are assigned the values 2 and 3 respectively then the statement p=q++ 1) gives an error message 3) assigns a value 3 to p 2) assigns a value 4 to p 4) assigns a value 5 to p 44) A compound statement is a group of statement included between a pair of 1) double quots 3) parentesis 2) curly braces 4) / and/ .

438 45) The number of the relational operators in the c language is 1) four 2) six 3) three 4)one 46) In the c language. a hexadecimal number is represented by writing 1) x 2) xo 3) 0x 4)h 48) A string in the c language is represented by enclosing a series of characters in 1) single quotes 3) parenthesis 49) One structure can be 1) 2) 3) 4) a member of some other structure a member of the same structure a member of a union all of the above 2) double quotes 4) / and / 51) Almost every c program begins with the statement 1) main() 2) printf() 3) #include<stdio. ‘3’ represents 1) a digit 2)an integer 3)a character 4)a word 47) In the c language.h> 4) scanf() 52) A single character input from the keyboard can be obtained by using the function 1) printf( ) 2) getchar( ) 53) An expression 1) 2) 3) 4) is a collection of data objects and operators that can be evaluated to a single value is a name that substitutes for a sequence of characters causes the computer to carry out some action all of the above 3) putchar( ) 4) scanf( ) 54) The expression c=i++ causes .

439 1) 2) 3) 4) the value of I assigned to c and then I incremented by 1 I to be incremented by 1 and then the value of I assigned to @ Value of I assigned to c I to be incremented by 1 55)The single character input/output functions are 1) scanf( ) and printf( ) 3) scanf( ) and putchar( ) 2) getchar( ) and printf( ) 4) getchar( ) and putchar( ) 56) The conversion character ‘I’ for data output means that the Data item is displayed as 1) 2) 3) 4) a floating point value with an exponent an unsigned decimal integer a signed decimal integer an octal integer 58) In a circular linked list 1) 2) 3) 4) components are all linked together in some sequential manner there is no beginning and no end components are arranged hierarchically forward and backward transversal within the list is permitted 60) A c function contain 1)function body 2)argument declaration 3)a function header 4)all of the above C QUESTIONS ON ARRAYS 1. a[2]=1. printf(“%d”. a[-2]=10. main() { Int a[5]. } a) compilation error b)10 c)-1 d)none of the above Ans c .-2[a]).

} a) al b) bg c) lg d) none of the above ans b 6) main() { Int n[25].”xy”}. Printf(“%c”. Printf(“%c”. main() { char a[3][3]={“abc”. } b) bcdef b) abcdef c)compilation error d) none of the above Ans c 5) main() { Char *p=”algc”. } .”xyz”}. } a) a b)compilation error c)abcpqrxy d)abc Ans c 3.*++p).’c’}. main() { Char a[3][3]={{‘a’. Printf(“%s\n”. printf(“%d%d”.’b’.&a[0][0]). printf(“%s”.*n.a[2][2]). a++.*(n+24)+*(n+0)). n[0]=100. printf(“%c”.&a[1]).440 2.”pqr”. } a) q b) r c) z d) compilation error Ans c 4) main() { Char a[100]={“abcdef”}.++*(p++)). n[24]=200.”pqr”.

3.1}. p=”%d\n”. ) . Printf(“%d%d%d”.a).n[3][1]).3. } a) a b) b c) ab d) error ans a) 10) main() { Char *p.n[1][1].100 d) 0.a[1]).4. } a)5 8 garbage value b) 845 c)623 d)825 ans a) 9) main() { Char a=’ab’. Printf(“%d”.5. } a) 1 b) 0 c) compillation error d) none of the above Ans b main() { Static int n[3][3]={2.6.65).8. printf(p. Printf(“%c”. } a) A b) c c) 65 d) error ans a 11) main() { int a=1.5. p[1]=’c’.441 a) 100 200 b) 100 300 c) 0.n[2][1].200 Ans b 7)main() { Int a[3]={1}.

Ans b 2) what does the last node link contain a) address of first node b) address of that node c) null d) address of previous node ans c 3) steps involved in insertion of a node . b) data & pointer to hold the address of next node.a.break.442 switch(a==5) { Case 1: pf(“hi”).a). Break. } Ans:: hell0009 DATA STRUCTURES ON SINGLE LINKED LIST 1) each structure in a single linked list contains ---------&------------a) data & pointer to hold the address of that node. Case 0:pf(“hello”). Printf(“%s %d %d\n”. } } a) Hi b)hello c) hi d)wipro Ans: b 12) main() { Char a[]={“\012345\”}. } 13) main() { Char a[]=”hell0009”. d) pointer to hold the address of next and previous node. Default : pf(“wipro\n”). Printf(“%s\n”.sizeof(*a)). c) data & pointer to hold the address of previous node.sizeof(a).

2) if the node to be deleted is the start then start is made to point to the next node.443 a) Creating a new node. Move the temporary pointer pointer to the next node. 4) if the node to be deleted is in the middle of the list the previous node is made to point to the next node. 3) searching for the node to be deleted by comparing the data with the data entered by the user. Repeat steps 2 & 3 until the the temporary pointer points to null. e) f) g) h) Ans 1234 3241 1324 2431 f 6) if a node (q) is to be inserted at the beginning the operations which are performed is 1) q->next =start->next start =q. b) Accepting data into the node c) If the list does not exist. . 2) start=q. Print data in the node. a) 1 2 3 4 b) 1 4 3 2 c) 1 3 4 2 d) 2 3 1 4 Ans c 1) 5) steps involved in traversing the list Free the memory occupied by the deleted node. a) 1 2 3 4 b) 1 3 2 4 c) 4 3 2 1 d) 3 1 2 4 Ans a) 4) 1) 2) 3) 4) steps involved in traversing the list store the address of the start node in a temporary variable. q=start. d) If the list exists insert the new node at the end of the list. assign start to the new node. 3) q->next=start. q->next=start.

printf(“%d%d”.a[3].m. n[0]=100. main() { int i=-3.a[4]).k.200 4) main() { char str[]="I am in wipro".a[2].444 4) q->next =start.m). n[24]=200. . main() { int a[5]={2. ans 4 7) when start and last points to same node.100 d) 0. } (a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0 ans::d 2). } a)100 200 b) 100 300 c) 0. Ans : a 1).What would be the output of the following program.*(n+24)+*(n+0)). } (a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) error ans::a 3) main() { Int n[25].i.how many elements are present 1) 0 2)1 3)2 4)3 Ans 2 8)memory is allocated in single linked list a) dynamically b)compile time c)statically d) linking time.j=2. printf("\n %d %d %d %d".k=0.*n. start =q.3}.What would be the output of the following program. m=++i&&++j||++k.j. printf("\n %d %d %d".

e.age.++*p++)..e. int age. main() { struct emp { char name[20].What would be the output of the following program.. Printf(“%c”. fun(--n). printf("%d".bg 6)main() { void fun(int). printf("\n %d %f". int n=3. } ans::in wipro 5) { main() Char *p=”algc”.. }.sal). } void fun(int n) { if(n>0) { fun(--n).n).. Printf(“%c”. float sal. fun(n). } } ans::0120 7). } (a) 0 0. struct emp e = {"tiger"}.&str[5]). } a)al b) mg c) lg d) none ans::none.*++p).000000 (b) Garbage values (c) Error (d) none of the above .445 printf("%s\n".

++q.*a).40.*p=c.4.main( ) { int a[ ] = {10. j++) { printf(“%d ” ..50}.j++) { printf(" %d ".446 ans::a 8).j++) { printf(" %d ".3. } } ans::222223465 10.*p). #define ABC 20 #define XYZ 10 #define XXX ABC . .j<5.XYZ void main() { int a. for(j=0.20. j++) { printf(“%d” . } p = a. int j.6.j.*q=c. j<5.main() { int c[ ]={2.*p).5}. } for(j=0. p++.30.j<5.can't change the base address a++ 9. j<5. for(j=0. a = XXX * 10. ++p.*p). a++.*p. } } Ans::Error Lvalue Required.. for(j=0.

abc). } ans::-80 11. printf ("%d\n". if (++k < 5 && k++/5 || ++k <= 8) printf("%d\n". } ans::40 0 14. abc = a*b+c. } . abc = 0. abc = %d\n". b) (a * b) / (a . #define calc(a. b = 10. printf("%d\n". } while (cnt --). a). } printf ("c = %d. c. calc(a + 4. c.447 printf("%d\n".. a. b -2)).b) void main() { int a = 20. if (c) { int abc. b. k).main() { int k = 5. a = b = c = 40. } 12. } ans::Error. do { a /= cnt. a). void main() { int a.void main() { int cnt = 5.divide error 13.

.y)..4 c) 4.pointer as 4 byter and character as 1 byte. x=x++ + y++."fortran". names[4]=t.Assume that integer is 4 bytes.sizeof(s1).18 b)18.i++) printf("%s".main() { static char names[5][20]={"pascal".18 d) 4. } main() { int a=20. int *p."ada". } ans::Error.. a) 18."perl"}.base address can't be changed names[3]=names[4] 16..y=35. y=++y + ++x. for (i=0. int i.int fun(int x) { int y=55. return((x-y)?y:x).x. printf("%d%d". . t=names[3]. names[3]=names[4]. } ans::57 94 17.sizeof(*s2)). char name[10].*s2.4 18.448 ans::7 15."cobol". char *t.main() { int x=20.. printf("x=%d y=%d\n".names[i]).i<=4.then predict the output struct student { int a. }s1.

return(n). } void main() { printf("%d".compute(5)). sptr=ptr+5. } ans::fgh 1.int compute(int n) { if(n>0) { n=compute(n-3)+compute(n-1).449 fun(a).sizeof(25. 8 2 2 ans::d . 2 2 2 b. 4 2 2 c. } ans::20 19.sptr).75). printf("%d %d %d".sizeof(‘p’)) a. printf("%s".sizeof(123). char *sptr.y). printf("%d". 8 4 1 d. } 20.int main() { char *ptr="abcdefgh". } return(1).

printf(" %d". e. } } b. { int i = 3. 1 50 0 c. 29 Ans::-7 4.a=50. 9 c. 13 d. i * 3). fun( ) { printf("%d\n". fun(). int i=5. printf(“%d\n”. void main() . #define xsq(x) x*x main( ) { int i. main( ) { int a=35.a>40). j. a == 35. 0 50 0 d. d. 0 50 1 ans::c 5. } main( ) { int i= 2. –7 b. j). } a. 1 50 1 b. i). c. i = 5. j = xsq(i-2).450 2. printf(“ %d %d %d\n”. 3. } a. 15 3. 6 3 0 Ans::a 3.

} } a. 5 4 3 2 1 d. getch(). Compiler Error ans::d 8. break. clrscr().strlen(a)). } 6 7 8 5 Ans::7 6. 4 3 2 1 0 b. main() { static int var=5. if(var--) { printf("%d". default: printf(“Default”). 4 3 2 1 c.var). void main() { int i=1.451 { char a[]="123abcd".j=2. printf("%d". Default d. switch(i) { case 1: printf("One"). One b. Two c. main(). break. case j: printf("Two"). } } a. break. void main() { switch('a') { . 5 4 3 2 1 0 ans::a 7.

int modifyvalue() { return(x+=10). clrscr(). One c. } } break. 100 c. modifyvalue(). Compiler Error ans::b 9. Zero b. . break.sum=0. a. 120 b. while(p<20) { p++. int x. Error ans::A 10. } printf("\nsum=%d". x++. x++. } void main() { int x=10.452 case 'A': printf("Zero"). } a. case 97: printf("One"). Error d. void main() { int p=1. sum+=p++. break.sum). 110 d. changevalue(x). } int changevalue(int x) { return(x+=1). default: printf("Error").

ptr++.i--). 12 12 b. return i>0?main():0. Garbage Value ans::c 14. printf("\nSecond output : %d". 3 2 1 c. } a. 3 2 1 0 b. printf("%d". void main() . *p=5. 12 13 d. void main() { char *ptr="Hello World". int const *p. } a.453 printf("First output : %d". changevalue(x).ptr). printf("%d". Hello World ello World c. 13 13 11. ello World ello World d. ello World llo World 13. } a. main() { static i=3. printf("%s".x). 11 12 c. Compiler Error d.ptr). a. 2 1 0 d. printf("%s". 2 1 12.*p++). *ptr++.x). 5 b. 6 c. Iello World Iello World b.

4 5 3 c. .sizeof(*p)). 1 1 ans::b 16.*p++). printf("%d %d".sizeof(str2).++*p).454 { char *str1="abcd". } a. 1 5 3 ans::c 15. 2 1 c. printf("\n%s". char **p. harma harma hewlet-packard ans::d 17. 5 5 3 b. harma hewlet-packard siemens d. dharma harma ewlet-packard c. printf("\n%s". printf("%s". 1 2 b. harma harma ewlet-packard b.sizeof(p).++*p). p=s. void main() { char *ptr="Ramco Systems"."ibm"}. } a. a. char str2[]="abcd".sizeof(str1). P is a character pointer variable then.sizeof("ab"))."hewlet-packard"."siemens". 2 2 d. void main() { char *s[]={"dharma". what will be the output of the following statement. printf("%d %d %d". 2 5 3 d.

i=64/square(4). 16 c.k).i). amco Systems amco Systems d. int x:3. ptr++. Samco Systems amco Systems c.ptr).ptr). 64 d. } a. 16 17 11 2 b. }. . printf(" %d %d %d". #define man(x.j=10. } a.455 (*ptr)++.j. 16 16 11 2 d. 7 b. } a. #define square(x) x*x void main() { int i=7. k=man(i++. printf("%s\n".k=0. printf("%s". 17 17 11 2 c.i. 4 ans::c 19. Samco Systems Samco Systems b. clrscr().++j). struct one { int no:1.y) (x)>(y)?(printf("%d". int pl:2.x)):(y) void main() { int i=15. 16 17 12 2 ans::a 20. amco Systems mco Systems ans::b 18. printf("%d".

a.x=3. printf("%d %u".pl=1.no=0. struct emp emp1.pl). } a.a.a.x).456 void main() { struct one a. 1 1 2 2 3 3 d. void main() { struct emp { struct e { int *a. } a. 0 0 1 1 3 3 b. a.e1)). printf("\n%d %u". struct emp .pl. struct emp emp1.x. 2 2 c. }e1. }.a.sizeof(emp1. 4 4 d. 2 4 b. a.no).a. printf("%d %d". printf("\n%d %u". 1 1 2 2 2 2 Ans:a 21. 0 0 2 2 3 3 c.sizeof(emp1). int a. 4 2 ans::d 22.no.a. a.

emp1. 25 25 c. 10 10 d. main() { printf("Enter 1 values:").&emp1.emp1. a) b c a b) c b a c) a b c d) both a and b ans::d 24.457 { int a.a). temp ->next -> prev = temp -> prev. if temp is pointing to a node other than first and last node temp -> prev ->next = temp ->next. 10 25 b. Compiler Error ans::b 23.a.a. a) b) c) d) no effect inserts a node deletes a node shuffling of pointers ans::c 25. //The given input is 10 and 25 printf("a=%d a=%d". } a. which is the faster traversable dynamically growing list a) Binary Search Tree b) Singly Linked List c) Doubly Linked List d) Using Array ans::c . What does below code do. Arrange the code in order to delete a node being pointer by temp. scanf("%d%d".a). a) b) c) free(temp) temp->prev->next = temp->next temp->next->prev = temp->prev.&emp1. }.

if (a > b) swap(a.++i). } (a)0 3 -3 0 Ans::3 2.a.c=3. void main() { int i=5.i++.b. (b)10 9 8 7 6 (c)9 8 7 6 6 (d)10 8 (b)a=6 b=5 (c)a=6 b=0 (d)None of (b)Compile-Time Error (c)0 3 -1 (d)0 3 . } (a)a=5 b=6 these Ans::c 3. printf("%d %d %d".i++.b). b++)-c.b=6. #define swap(a.b=2.458 1.++i.b). a=b.c).i++.a. } (a)Compile-Time Error 766 Ans:d 4.temp. c=(--a. void main() { static int a=5. printf("a=%d b=%d". b=temp. void main() { int a=1. printf("%d %d %d %d %d".b) temp=a.

What is the output of the program? #include <stdio. } } B.459 void main() { int i. printf("Hello Genesis")). n-i). for (i=1. default: printf(" 10 "). D. } A.h> int main(int argc. 5 10 6 Hello Genesis 13 Hello Genesis Hello Genesis 13 None of the above (b)840 (c)852 (d)864 . n =10. B. case 6: printf(" 6 "). } (a)84 Ans:c 5. return 0. 6. 5 C. char *argv[]) { printf(" %d". i+=2) printf("%d".h> main() { switch (5) { case 5: printf(" 5 "). i<n--. C. #include <stdio.

integer B. C. B. B. 5 6 Ans::b 7. union It assigns the pointer a NULL value It erases the contents of any type and cleans the pointer It places the memory address with the pointer in free store It disables the memory address with the pointer Stack Register Extern Static first second between 2 strings third . Which of the following is not a storage class in C? B. What is the data type of FILE? A. C. Ans::a 9. Which argument of function 'strncmp()' specifies number of characters to be compared? A. 5 10 E. ans::d 8. E. D. D. C.460 D. Ans::a 10. D. What is the significance of the free() function? A.

C. B.461 C. D. Which of the following is a non-linear data structure? A. sq(3 + 2)). D. pointer D. Ans::d 13. C. structure ans::d 11. E. printf scanf strcpy strlen Stack Queue Linked List Tree 25 11 10 Compilation error . #include <stdio. Ans::b 12. ans:c 14.h> #define sq(a) a * a void main() { printf("%d". C. B. Which of the following function does not return an integer value? B. D. } A.

} A. printf("%d". Ans::c 16. D. C. D. B. C. 1. printf(" %d ". What is the output of the program if the input is 103? main() { int p = 234. scanf("%d".462 Which of the following function does not support dynamic memory allocation? A. Where do we use a 'continue' statement? B. D. ans::a 15. Queue is _________________ a) b) c) d) Ans::d LIFO LILO FIFO Both b & c In 'if' statement In 'switch' statement In 'goto' labels None of the above 3 103 103 103 3 103 2 alloc realloc malloc free . B. Ans::d 17. C. &p)). E. p).

int abc(int z) { return i/2. Write one statement equivalent to the following two statements: x=sqr(a). int i=5.sqr(a)).463 18. Choose from one of the alternatives (a) return(sqr(a)). what is the size of ob in bytes. a) 4 b) 2 . What is the postfix expression for A + B * C / D – E * F / G e) ABC*D/+EFG*/f) ABC*D/+EF*G/g) ABCD/*+EF*G/h) None of these. }. return(x). Ans::b 20. (b) printf("sqr(a)"). union U ob. Ans::b 19. printf("%d". } a) error b) 5 c) 2 d) 0 ans::c 21.abc(i=i/4)). (d) printf("%d". union U { int x. (c) return(a*a). char s[2]. float y. } main() { int i=4.

14. 16.B * C / D + E * F / G Ans:c 24. while (temp->next->next!=NULL) { . 72. What is the Infix expression for -+A/*BCD/*EFG a) A + B * C / D – E / F * G b) A + B / C * D – E * F / G c) A + B * C / D – E * F / G d) A .464 c) 8 d) 7 ans::a 22. delete c.push .insert. 10 be the number of nodes temp = head. delete d. 36. 11. pop e.add . 21. 88. 9. front . What would be the root node if we enter the following data set (in the respective order) into a standard program to construct a Binary search tree? 25. 69 a) 69 b) 25 c) 26 d) 9 Ans::b 25. what does the code below do. The operation for adding and deleting an entry to a stack is traditionally called: a. rear ans::d 23. 26. delete b. where head is pointing to first node & temp is a temporary pointer. 45.append .

} temp -> prev -> next = temp -> next.--val. printf("%d %d %d %d".z) (x+y-z) int main() { int x=2. What will be the output of the following program : int main() { int val=5.val. val=printf("C") + printf("Skills").z=4. return(0). temp -> next -> prev = temp -> prev.(-x+y)) * Compute(z. What will be the output of the following program : int main() { int val=5.++val.Compute(y. printf("%d". } (a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of these Ans::c 2. return(0).y=3. What will be the output of the following program : int main() no effect deletes some node deletes 2nd last node deletes last node . return(0). free(temp).x.val). #define Compute(x.y.z. a) b) c) d) ans::c 1.val--). } (a)40 (b)30 (c)Compile-Time Error (d)None of these Ans::b 3.465 temp = temp ->next.(-y+z))). printf("%d". } (a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 Ans::d 4.

void main() { printf("%d". return(0). Traverse the given tree using Inorder. if ((printf("%s". In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) malloc (d) Queue Ans:b 8.5+val++). } (a)Data types not allowed (b)Compile-Time Error(c)3 (d)2 Ans::2 7. return(0). } (a)Compile-Time Error (b)Lvalue required Error (c)10 (d)11 Ans::c 6. What will be the output of the following program: int main() { int val=5. Preorder and Postorder traversals. Given tree: A B a)Inorder : D DHBEAFCIGJ E F C G H I J . printf("%d". else printf("Failure"). } a)Success b)TestSuccess c)Compile-Time Error(d)Failure ans::b 5.sizeof(int)).str)) == 4) printf("Success").466 { char str[]="Test". return(0).

#include<stdio. main() { static int var = 5. struct xx *s. } b.467 Preorder: Postorder: b)Inorder : Preorder: Postorder: c)Inorder : Preorder: Postorder: d)Inorder : Preorder: Postorder: ABDHECFGIJ HDEBFIJGCA DHBEAFCIGJ DHEABCFGIJ HDEBFIJGCA DHBEAFCIGJ ABDHECFGIJ HDEBFIJGAC HDBEAFCIGJ ABDHECFGIJ HDEBFIJGCA Ans:a 9. Compiler Error Ans::s 11. Run time error d. if(var) main(). printf("%d". 3 hello b.h> main() { struct xx { int x=3. 4 3 2 1 0 c. printf("%d ".) operator . printf("%s".s->x).s->name). 0 0 0 0 0 Ans:c 10. 5 4 3 2 1 d. }.var--). 4 3 2 1 b. char name[]="hello". } a. c. use dot (.

} b. float j.468 #include<stdio. 20 10 b. 7 . Compiler Error b.5. } int ret(int ret) { ret += 2. 10 10 Ans:a 14. printf("\n %d". printf("x= %d y = %d\n". swap(&x. 6 6. c = ++*p++.&y).y=20.000000 Ans::d 12. 6 d. compiler error c. 10 20 c.*b=*a-*b.c).*a=*a-*b.h> main() { const int i=4.int *b) { *a=*a+*b. } main() { int x=10. return(ret). 5 5. 5 6.000000 d. void main() { int k=ret(sizeof(float)). int swap(int *a.++k). 20 20 d.++j).000000 c.x. j = ++i.y). char c. i. 8 Ans::d 13. main() { char *p = “ayqm”. } a. printf("%d %f". } a. b. printf(“%c”.

switch(i) { case 1: printf("1"). y d. printf (“%d”. case 2: printf("2"). 0 5 d. main () { int i = 5. } printf (“%d”. 18 18 e. #define MESS junk main() { printf(“MESS”). } a. z float i=1. MESS junk . MESS Ans:c 17. main() { c. switch (i) { static int i. Error c.i). default : printf("0"). } } b. 0 1 2 c. case 5: i = i + i. a ans:b 15. Junk b. i = i * i. case 4: i = i + i. Compiler Error e.469 } b. i = 3. 1 2 0 d. 0 Ans:d 16.5. b a. } a. case 3: i = i + i. 10 10 c. 9 b. 18 5 b. 2 0 d.i).

void main() (d) . no error. But It will over writes on same file. But It will create one more file. fclose(fp1) . It will not allow. no error. main() { FILE *fp1. fputc('B'. } fn(int i) { return ++i. c. b. The new content will append in existing file. error. printf("%d"."w").470 Ans:c 18. } Find the Error. fclose(fp2) ."w") . main() { int i=10. Int fn(int). } (a) 10 (b) 11 (c) 12 Compilation error Ans:a 19.i). fp2=fopen("one". fp1=fopen("one". If Any? a. fn(i). Ans:a 20.fp1) . fputc('A'. d.fp2) . What would be the output of the following program.*fp2. no error.

} (a)Compile-Time Error (b)555 554 555 (d)557 554 555 Ans:c 21.*ptr++). printf("%d %d %d".--b. b. c. d.471 { int a=555. what type of Binary Tree is the following tree below (c)556 554 555 A B C D E F G H I J K a. binary tree strictly binary tree complete binary tree not a binary tree If suppose root to be deleted then which node will be the root node .*ptr=&a. ans:d 22.b=*ptr.++a.

c. Which function is used to detect the end of file a) EOF b) feof( ) c) ferror( ) d) NULL ans:b 25.472 A B G C E H I D K J a. If the CPU fails to keep the variables in CPU registers. b. B G Any node Both a and b are correct When fopen() fails to open a file it returns a) NULL b) –1 c) 1 d) None of the above ans:a 24. Ans:a 23. d. in that case the variables are assumed a) static b) external c) global d) auto .

x). 40 None of the above 2. } Predict the output 20 40 20. printf("\n %d". printf("\n %d".h> int x=40.h> main() { int x=40. #include<stdio.x). } int a=20.a). } printf("%d". #include<stdio. #include<stdio. main() { int x = 20. printf("\n %d".473 ans::d 1. .x). { int x = 20.h> main() { extern int a. } Predict the output 20 40 40 20 40 20 3.

printf("\n %d %f". i). }.474 Predict the output 20 0 Garbage value Error 4. printf("%d". e. } 0 0. } o\p: 1 6. float sal. #include<stdio. struct emp e={"Raja"}. y=20.000000 Garbage values Error None of the above 5. Which of the following definition is correct? int length char int . i= x < y < z. e.h>--------------------------------doubt main() { struct emp { char name[20]. int age.age. i.h> main() { int x=10. z=5. #include<stdio.sal).

h> main() { int i=4. break. } } o\p: default value 8. i++). switch (i) { default: printf("Default Value \n").h>------------doubt main() { int i=1. #include<stdio. case 1: printf("Value is 1 \n"). case 3: printf("Value is 3 \n"). if (i >10) { break. break. } . case 2: printf("Value is 2 \n"). What will be the output #include<stdio. break. while() { printf("%d".475 int long float double ans::1 7.

} Ans: X is less than Y 10.476 } } Ans::Error 9. j=15. #include<stdio. y.h>------------------------------doubt main() { int x=30. } } o\p same 11. z.h> main() { int i=10. y =40. else if (x<y) printf("X is less than Y"). . if(i%2= = j%3) { printf("Same"). else if (x>y) printf("x is greater than Y"). #include<stdio.h>------------doubt main() { int x=4. if (x==y) printf("X is equal to Y"). #include<stdio. } else { printf("Different err").

z). printf("%d %d %d". z= x--. printf("%d" . x. if (a<0.h>-----------------------doubt main() { . #include<stdio. } else { printf("C++").h> main() { float a = 0.7) { printf("C"). #include<stdio.y.7f o\p c++ 13.29.477 y=--x.7. } o\p 7 14.fval). } } Try with 0. #include<stdio.h> main() { float fval=7. } Output: 433 432 332 233 223 Ans::233 12.

} o\p mess . void main() { char a[100].h>----------------------doubt void fun(char *). } o\p b c 16. *a).h> #define MESS "Junk" main() { printf("MESS"). fun(&a[0]). *a). a[2] = 'C'. a[1] = 'B'. printf("%c". } void fun(char *a) { a++. printf("%c". #include<stdio. a[3] = 'D'. a++. #include<stdio. a[0] = 'A'.478 printf("Welcome"). main(). } How many times the program will execute? Ans:Infinte 15.

2f \n". gets(sentence). int i.h> main() { char str[] = "Sales\0man\0". printf("Enter the line of text"). #include<stdio. sizeof(str)). printf("%6.i--) { putchar(sentence[i]). } o\p 5 19. . } } 21 #include<stdio.h> main() { char sentence[80]. strlen(str)).15529. printf("%d". } o\p 11 20 #include<stdio.i>=0.h>-----------------------doubt main() { float a=3.h> main() { char str[] = "Sales\0man\0". printf("%d".479 18.a). for(i=strlen(sentence)-1.h>-------------doubt #include<string. #include<stdio.

printf("%5. Any of the following programs in c has access to three standard files: 1) standard input file.480 printf("%6.screen 4) all the above 4. standard output file. printf("%0. stderr 3) keyboard.1f \n".screen.a). } 1. 1) extern 2) static 3) stat 4) auto 6) A program can be terminated at any time by calling the function 1) fflush() 3) exit() 7) Heap 1) is a region from where memory is allocated 2) ferror() 4) clearerr() .a). standard error file 2) stdin.stdout.the appearance of the output of the output can be affected by 1) field with 3) flag 2) conversion character 4) all of the above 3. The comma operator(.) is used to 1) permit two different expressions to appear in situations where only one expression would ordinarily be used 2) Terminate loops or to exit from switch 3) alter the normal sequence of program execution by transferring control to some other part of the program 4) carry out a logical test and then take one of two possible actions. depending upon the outcome of the test 5) A variable can be declared static using the keyword.3f \n".a). In printf(). printf("%2.0f \n".a). Which of the following does not have an unary operator? 1) -7 3) j 2) ++i 4) all of the above 2.4f \n".

481 2) lies between you program and the stack 3) is a finite area 4) all of the above 8) A function can 1) perform a task 2) return a value 3) change value of actual arguments in call by reference 4) all of the above 9) Function definition void check(int i .1 2) 1.1.2.30-element character array name is one dimensional.2.30-elements string array 12) c program contains the following declaration: Static float table[2][3]={ {1.2 4) 2.1. What is the value of *(*(table+1)+1)? 2) 2.3} }.1. {2.2 4) 2.2.30-element integer array name is one dimensional.1.3 13) A c program contains the following declarations and initial Assignments: .2.30-element floating point array name is one dimensional .3}.char*j) is 1) call by value 2)call by reference 3) both (1) and (2) 4)in valid function definition 10) A union consists of a number of elements that 1) all occupy the same space in memory 2) must be structure 3) are grouped next to each other in memory 4) all have the same type 11) Which of the following array is defined in the statements Char name[30]? 5) 6) 7) 8) name is one dimensiona.

j and k are assigned the values 5. and the second is an integer 3) f accepts three arguments and returns nothing.01. What would be the value of the following expression? (3*i-2*j)%(2*d-3) 1)14 3) 1 2)18 4) 0 14) The declaration : int f(int 1). float x=0.0005. means 1) f accepts an integer argument and returns an integer quantity 2) f accepts two arguments and returns a double precision quantity.d=’d’. and the second is an integer 4) f does not accepts any arguments but returns a single character 15) The c language was developed by 1) Marting Richards 3) Ken Thompson 2) Dennis Ritchie 4) Smith Volt 16) The arguments of a function are included between 1) The parenthesis 2) double quotes 3) curly braces 4) # 17) The int type of constraints are whole numbers in the range 1) -23677 to 23678 3) -32767 to 32768 2) -32768 to 32767 4) -32864 to 32864 18) If the variables i. Char c=’c’.y=-0.3 and 2 respectively. we actually Compare 5) 6) 7) 8) the ASCII codes of the characters the characters themselves neither of the two binary code and hexadecimal code . The first arguments is a double-precision quantity. then the expression i=j+(k++ =6)+7.482 int i=8.j=5. 1) gives an error message 3) assigns a value 18 to i 2) assigns a value 16 to i 4) assigns a value 19 to i 19) In a relational expression involving characters.

does not assign any value to i assigns an float to the variable i 24) A pointer is declared by using a statement such as 1) int *p. 5) 6) 7) 8) assigns an integer to the variable i gives an error message. 2) point. 4) int &p. 3) pointer *p.&i). 25)The null character is represented by 1) \n 2)\0 3)\o 4)\t 26) The members in the union 1) have different memory locations 2) share the memory with a structure 3) have the same memory location 4) have different memory variable 27) The global variables by default belong to .483 20) The getchar function is used to 1) print the ASCII code of the character 2) to assign a character typed at the keyboard to a variable 3) to print a character on the screen 4) all of the above 21) The word case used in the switch statement represents a 5) 6) 7) 8) function in the c language data type in the c language keyword in the c language global variable in the c language 22)The logical NOT operator represented by ! is a 1) unary operator 3) ternary operator 2) binary operator 4) octal operator 23) The statement : scanf(“%d”.

484 1) the register type 3) the auto type 2) the static type 4) the dynamic type

28) The bit fields are the members of a/an 1) array 2) structure 3) union 4) inter section

29) In c, square brackets [ ] are used in 1) functions 2) arrays 3) statements 4) all of the above

30) A fields width specifier in a printf() function 1) specifies the maximum value of a number 2) controls the size of type used to print numbers 3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number 31) The two operators && and || are 1) arithmetic operators 3) logical operators 2) equality operators 4) relational operators

32) The library files that come with c are 1) text editor for program development 2) the compiler and liker 3) program examples 4) files that contain functions which carry out various commonly Used operations and calculations 33) precedence determines which operator 1) is evaluated first 3) is fastest 2) is most important 4) operates on the largest number

34) The string containing certain required formatting information is called 1) argument 3) character string 2) character array 4) control string

485

35) The advantage of a “switch” statement over an “else-if” construct is 1) a default condition can be used in the “switch” 2) the switch is easier to understand 3) several different conditions can cause one set of statements to executed in a switch 4) several different statements can be executed for each case in a switch 36) The header file “math.h” can be used for 1) providing links to assembly-language for calls 2) providing diagnostic and debugging assistance 3) providing support for the string handling functions 4) none of the above 37) The malloc() function 1) returns a pointer to the allocated memory 2) returns a pointer to the first byte of region of memory 3) changes the size of the allocated memory 4) deallocates the memory 38) which of the following expressions will return a 1 if both bits have A value of 1; otherwise will return a value of 0? 1) AND 2)OR 3)XOR4)1’stderr complement

39) If an error occurs while opening a file the file pointer is assigned a value 1) NULL 2) stdout 3) sstderr 4) not defined

40) Which of the following backslash codes used for bell? 1) \b 2) \a 3) \r 4) \s

41) One of the valid keywords in the c language is 1) printf 2) CHAR 3) auto 4) scanf

42) The comments in a c language program are placed between 1) \* and /* 2) / and .* 3) /*and*/ 4) # and #

486

43) If p and q are assigned the values 2 and 3 respectively then the statement p=q++ 1) gives an error message 2) assigns a value 4 to p 3) assigns a value 3 to p 4) assigns a value 5 to p 44) A compound statement is a group of statement included between a pair of 1) double quots 3) parentesis 2) curly braces 4) / and/

45) The number of the relational operators in the c language is 1) four 2) six 3) three 4)one

46) In the c language, ‘3’ represents 1) a digit 2)an integer 3)a character 4)a word

47) In the c language, a hexadecimal number is represented by writing 1) x 2) xo 3) 0x 4)h

48) A string in the c language is represented by enclosing a series of characters in 1) single quotes 3) parenthesis 49) One structure cannot be 5) 6) 7) 8) a member of some other structure a member of the same structure a member of a union all of the above 2) double quotes 4) / and /

50) Masking is used 1) to copy a portion of a given bit pattern to a new variable, while the remainder of the new variable is filled with 0’s(using the bitwise AND) 2) to copy a portion of a given bit pattern to a new variable,

487 while the reminder of the new variable is filled with 1’s (using the bitwise OR) 3) to copy a portion of a given bit pattern to a new variable, while the remainder of the original bit pattern is inverted within the new variable 4) all of the above 51) Almost every c program begins with the statement 1) main() 2) printf() 3) #include<stdio.h> 4) scanf()

52) A single character input from the keyboard can be obtained by using the function 1) printf( ) 2) getchar( ) 53) An expression 5) 6) 7) 8) is a collection of data objects and operators that can be evaluated to a single value is a name that substitutes for a sequence of characters causes the computer to carry out some action all of the above 3) putchar( ) 4) scanf( )

54) The expression c=i++ causes 5) 6) 7) 8) the value of I assigned to c and then I incremented by 1 I to be incremented by 1 and then the value of I assigned to @ Value of I assigned to c I to be incremented by 1

55)The single character input/output functions are 1) scanf( ) and printf( ) 3) scanf( ) and putchar( ) 2) getchar( ) and printf( ) 4) getchar( ) and putchar( )

56) The conversion character ‘I’ for data output means that the Data item is displayed as 5) 6) 7) 8) a floating point value with an exponent an unsigned decimal integer a signed decimal integer an octal integer

57) The header file “ctype.h” can be used for 1) providing links to assembly language for calls

488 2) providing diagnostic and debugging assistance 3) providing support for string handling functions 4) providing character type identification (Boolean) and translation 58) In a circular linked list 5) 6) 7) 8) components are all linked together in some sequential manner there is no beginning and no end components are arranged hierarchically forward and backward transversal within the list is permitted

59) The function ftell( ) 1) 2) 3) 4) reads a character from a file reads an integer form a file gives the current position in the file sets the position to the beginning of the file

60) A c function contain 1)function body 3)a function header 1.int a=123.12; int b=-123.12; c=a+b; printf("%2f",c); a) 0.00 b) 123.12 c) 246.24 d) None of these 2. struct emp { int a; char *name; }; main() { struct emp *e; printf("%d",sizeof(e)); } ANs: 2 2)argument declaration 4)all of the above

489

3. which is the best thing for linked list than arrays? i) Insertion ii) Deletion iii) Traversal a) (i) only b) (i),(ii) only c) ii,iii only d) iii only 4. consider the character array of size 10. When a string is more than 10 a) Error b) Overwrites c) Nothing d) garbage value

5. main() { char *str; char *fun(); str=fun(); printf("%s",str); } char * fun() { char *buffer; strcpy(buffer,"Hello world"); return buffer; } a) hello world b) Compiler error c) Runtime error d) None of the above 6. main()

490 { char *str; char *fun(); str=fun(); printf("%s",str); } char * fun() { char *buffer; buffer=(char *) malloc(sizeof(char)); strcpy(buffer,"Hello world"); return buffer; } a) hello world b) Compiler error c) Runtime error d) None of the above ans::a

7) what is the prefix expression for the given Infix expression A+B*C/D Ans::+A/*BCD

8) int a; a=65536; printf("%d",a); a) 0 b) Garbage c) 65535 d) -32768 9) main() { char p=65; printf("%c",p); } a) 65 b) p c) error d) none of the above

491

10) In a function call, _____________ is passed as arguments. a) variables b) constants c) Expressions d) All the above 11) The value of EOF is ___-1______. 12) () is used for __________ a) function body b) Arguments c) Return type d) Declaration of function 13) How does the string ends? a) /n b) /t c) /0 d) none 14) The range of Unsigned integer is a) 127 to -128 b) 0 to 65535 c) Depend up on the compiler d) -32768 to 32767 15) which one of the following is a illegal real constants a) 32.535 b) -1.5E25 to 3.5E65 c) "53682" d) -6.583 16) main() { int i,a[5]; a[1]=5; for(i=0;i<5;i++) { printf("%d",a[i]); a++;

492 } a) 0 0 0 0 0 b) Garbage value c) 0 5 0 0 0 d) Compiler error ans:d…..base address can’t be changed a++ 17) The size of int is 2 bytes,then what is the size of short int? a) 1 b) 2 c) 4 d) 8 18) In a queue,what condition applies a) First In First Out b) Last in first out c) Elements are inserted and deleted at one end d) Elements can be inserted and deleted in different ends 19) which of the following statements are true in the case of doubly linked list i) Every node is connected to other node ii) We can traverse in both the directions a) i) only b)ii) only c) Both i and ii d) neither i nor ii ans::c 20) main() { char str[]="Wipro Infotech"; char *s; s=&str[13]-13; while(*s) printf("%c",*s++); } Ans:: Wipro Infotech 21) char *a="Malayalam"; char *s; Char *str; str=a; s=str+8;

493 for(;s>=str;s--) printf("%c",*s); a) Malayalam b) malayalaM c) error d) None of the above 22) struct main { int a; int b; struct main *e1; } printf("%d %d",sizeof(e1),sizeof(*e1)); 23) #define wipro Hai void main() { printf("wipro"); } 24) Is allocating a block of memory effectively the same as defining an array? a) True b) false 25) the size of a node od doubly linked list is always greater than the single linked list a) True b) false 26) Queue is used for i) Expression Evaluation ii) Scheluding the job in First come First serve a) i) only b) ii only c) both i & ii d) neither i nor ii 27) what should be replace ????? in the program to get the output 25? ????? void main()

494 { int x=2,y=3,j; j=SQRT(x+y); printf("%d",j); } a) #define SQRT(int) (int * int) b) #define SQRT(int) (int) * (int) c) #define SQRT(int) (int + int) d) #define SQRT(int) (int) + (int) 28) void fun() { static char p[]="Hello"; return p; } main() { printf("%s",fun()); } what will be the output? Ans::Error Void function do not return a value. a) Compiler Error b) Hello c) Garbage value d) None 29) void main() { int *p; p=(int *)malloc(sizeof(int)); for(i=0;i<5;i++) printf("%d ",p[i]); } What is the output? Ans:garbage value 30) main() { int i,j; for(i=1,j=10;i<j;i++,j--); printf("%d %d",i,j); } Ans:6,5 31) Which of these will pass the address of the pointer *ptr to the function demofun()?

495 a) demofun(ptr) b) demofun(&ptr) c) demofun(*ptr) d) demofun(*&*ptr); 32) which is not a valid expression a) x!=y b) x! c) !x d) x!y 33) If max=10,rear=max,front=0,then what will be my queue? a) Queue Empty b) Queue Full c) Queue has one element d) Queue has max-1 elements 34) which is an indefinite loop? a) do while(0); b) for(;0;); c) while(1); d) while(0); 35) int *ptr; ptr=(int *)malloc(10*sizeof(int)); which is correct? i) All Values are intialised to garbage values ii) Creates memory for 10 integer data a) i only b) ii only c) both i and ii d) neither i nor ii 36) int *ptr; ptr=(int *)calloc(10*sizeof(int)); which is correct? i) All Values are intialised to zero ii) Creates memory for 10 integer data a) i only b) ii only c) both i and ii d) neither i nor ii

a) ptr is allocated 4 bytes b) ptr will be allocated sizeof struct node c) Error d) ptr will have 8 bytes 41) In a doubly linked list . b) q->a[q->rear]=item. ptr=(struct node *)calloc(sizeof(ptr)).496 37) Struct queue { int rear. } struct queue *q. printf("%c". int a[100]. 38) In which of the following we can sort the data without moving the data a) Array b) Single Linked list c) Doubly linked list d) Binary search trees 39) Char d=128. then how will you add a new element called 'item' in the queue? a) q->rear[a]=item. d) q->rear[q->a]=item. a)128 b)-128 c) error d) Garbage values 40) In the following definition struct node *ptr. int front. c) q->a[rear]=item.d).what will be the output? traverse(struct node*end) { .if the first node is first and the last node is end.

} if the input is 1.2.4.3.2.497 while(end!=NULL) traverse(end->prev).end->data). printf("%d". } what will be the output? a) 21 b)20 c) error d) Garbage value ANS::C 43) how will you refer the last node in the doubly linked list which is pointed by the pointer variable 'cursor'? a)cursor==NULL b)cursor->link=NULL c) Cursor->link=0 d) cursor->data=NULL 44) how will you refer the previous node of the pointer 'cursor' in the doubly linked list (cursor is not in the first or in the last)? a)cursor->link++ b)cursor=cursor->left c) Cursor++ d) cursor->left++ .2.5 then the output will be a) 1.3. printf("%d"*&b++).5 b) 5.4.3.1 c) compilation error d) none 42) void main() { int b=20.4.

printf("\n %d".498 1. 40 None of the above 2.x). printf("\n %d". { int x = 20. #include<stdio. .h> int x=40. } Predict the output 20 40 40 20 40 20 3. printf("\n %d". #include<stdio. main() { int x = 20. } int a=20.x).a).h> main() { int x=40.h> main() { extern int a. } Predict the output 20 40 20. } printf("%d".x). #include<stdio.

Which of the following definition is correct? int length char int int long float double 7. i. #include<stdio. }o\p 1 6. e. i= x < y < z.h> main() { int x=10.sal). #include<stdio.499 Predict the output 20 0 Garbage value Error 4. }. printf("\n %d %f". int age. } 0 0. y=20. float sal. z=5.h>--------------------------------doubt main() { struct emp { char name[20].age. struct emp e={"Raja"}. What will be the output . i). printf("%d". e.000000 Garbage values Error None of the above 5.

h>------------doubt main() { int i=1. } } } . break.500 #include<stdio. if (i >10) { break. case 2: printf("Value is 2 \n"). switch (i) { default: printf("Default Value \n").h> main() { int i=4. #include<stdio. i++). break. break. while() { printf("%d". case 1: printf("Value is 1 \n"). } }o\p default value 8. case 3: printf("Value is 3 \n").

if (x==y) printf("X is equal to Y"). elseif (x<y) printf("X is less than Y"). } else { printf("Different err"). y =40.501 9. y. elseif (x>y) printf("x is greater than Y").h> main() { int i=10. if(i%2 = j%3) { printf("Same"). } Statement missing Expression Syntax Lvalue required RValue required 10. y=--x.h>------------------------------doubt main() { int x=30. z. .h>------------doubt main() { int x=4. z= x--. #include<stdio. #include<stdio. } } o\p same 11. #include<stdio. j=15.

}o\p 7 14. printf("%d" . x.h> main() { float fval=7. #include<stdio. } } Try with 0.7f o\p c++ 13. #include<stdio.7.h>-----------------------doubt main() { printf("Welcome").502 printf("%d %d %d". #include<stdio. } Output: 433 432 332 233 223 12. } else { printf("C++").y.h> main() { float a = 0.z).fval). if (a<0.29. .7) { printf("C").

a[3] = 'D'. printf("%c". fun(&a[0]). #include<stdio. a[0] = 'A'. } How many times the program will execute? 32767 65535 Till the stack doesn’t overflow 15. . mess 18.h>----------------------doubt void fun(char *). #include<stdio. void main() { char a[100]. *a).503 main(). a[1] = 'B'. a++.h> #define MESS "Junk" main() { }o\p printf("MESS"). *a). } o\p b c 16. a[2] = 'C'. } void fun(char *a) { a++. printf("%c".

h> main() { char str[] = "Sales\0man\0". printf("%0. } . printf("%2.a).i>=0. sizeof(str)). printf("Enter the line of text"). for(i=strlen(sentence)-1. #include<stdio.h>-------------doubt #include<string.a). strlen(str)).a). printf("%6.h> main() { char sentence[80]. }o\p 5 19.h> main() { char str[] = "Sales\0man\0".2f \n". int i.504 #include<stdio. printf("%d". printf("%d".a). printf("%6.4f \n".1f \n".15529. } } 21 #include<stdio. printf("%5.3f \n".h>-----------------------doubt main() { float a=3.0f \n".i--) { putchar(sentence[i]).a). }o\p 11 20 #include<stdio. gets(sentence).

i). 8 2 2 2. printf(“ %d %d %d\n”. 9 g. { int i = 3. j).75). int i=5. printf("%d %d %d". a == 35. 13 h. i * 3). i = 5. 29 4. 15 3. g. i. h. } a.sizeof(‘p’)) a. j = xsq(i-2). void main() 1 50 1 1 50 0 0 50 0 0 50 1 . printf(" %d". 4 2 2 c. #define xsq(x) x*x main( ) { int i.sizeof(25.sizeof(123). } e. 5. } main( ) { int i= 2. –7 f. j. 6 3 0 3. printf(“%d\n”. d.a=50. 8 4 1 d.a>40). 2 2 2 b. c. fun( ) { printf("%d\n". main( ) { int a=35. fun().505 1. } } f. b. 3.

4 3 2 1 c. Default d. One b.var). void main() { int i=1. 4 3 2 1 0 b. } 6 7 8 5 6. main() { static int var=5. } } a. 5 4 3 2 1 0 7. break. printf("%d". clrscr(). 5 4 3 2 1 d. default: printf(“Default”). break. break.506 { char a[]="123abcd". switch(i) { case 1: printf("One"). Two c. } } a. main(). getch(). Compiler Error 8. void main() { switch('a') { . if(var--) { printf("%d".strlen(a)). case j: printf("Two").j=2.

int x. modifyvalue(). Compiler Error 9. x++.sum=0. Zero b. . } a. int modifyvalue() { return(x+=10). } int changevalue(int x) { return(x+=1). case 97: printf("One"). while(p<20) { p++. break. break. Error d. changevalue(x). } printf("\nsum=%d". default: printf("Error"). break.sum). 100 c. sum+=p++. clrscr(). Error 10. } } a. 120 b. x++. 110 d.507 case 'A': printf("Zero"). void main() { int p=1. One c. } void main() { int x=10.

Garbage Value 14.508 printf("First output : %d". Compiler Error d. 11 12 c. printf("\nSecond output : %d". 13 13 11. 3 2 1 0 b. 2 1 0 d. *ptr++.*p++).x). 2 1 12. 12 12 b. return i>0?main():0.ptr). } a. ptr++. void main() { char *ptr="Hello World". 12 13 d. 5 b. 3 2 1 c. printf("%d". int const *p. ello World ello World d. } a. ello World llo World 13.x).ptr).i--). 6 c. void main() . } a. a. *p=5. printf("%d". printf("%s". printf("%s". Iello World Iello World b. changevalue(x). main() { static i=3. Hello World ello World c.

. 5 5 3 b. void main() { char *s[]={"dharma". char **p. 2 c. printf("\n%s". printf("%d %d %d". 1 b. printf("%s".sizeof(str1)."ibm"}. P is a character pointer variable then.sizeof(p). 2 d. harma harma hewlet-packard 17. printf("%d %d". dharma harma ewlet-packard c. harma hewlet-packard siemens d. 4 5 3 c.sizeof(*p)). what will be the output of the following statement. char str2[]="abcd".++*p). } a. a."hewlet-packard". printf("\n%s".sizeof(str2). void main() { char *ptr="Ramco Systems". p=s. 1 2 1 2 1 16.509 { char *str1="abcd". } a. harma harma ewlet-packard b.++*p). 1 5 3 15.*p++).sizeof("ab")). 2 5 3 d."siemens".

} a. i=64/square(4). ptr++. printf(" %d %d %d". #define square(x) x*x void main() { int i=7.x)):(y) void main() { int i=15. int x:3. amco Systems Samco Systems amco Systems amco Systems mco Systems 18. }. 16 c. int pl:2.++j). 4 19.y) (x)>(y)?(printf("%d". 7 b.i). amco Systems d. printf("%s\n".i.k=0. 16 d. 17 c.j=10.k). 16 b. } a. k=man(i++. 16 17 17 16 17 11 11 11 12 2 2 2 2 20. Samco Systems c.ptr).510 (*ptr)++.j. printf("%d". } a. #define man(x.ptr). struct one { int no:1. Samco Systems b. printf("%s". . clrscr(). 64 d.

a. 0 0 1 1 3 3 b. int a.a. struct emp emp1. a. 2 c. printf("\n%d %u". struct emp emp1. 4 d. 4 4 2 4 2 22.a. 2 b.a. printf("%d %d".no=0. 0 0 2 2 3 3 c. } a. }e1.511 void main() { struct one a.sizeof(emp1.a. printf("%d %u".x.sizeof(emp1).no). struct emp .pl). a. void main() { struct emp { struct e { int *a. printf("\n%d %u".e1)).x=3. 1 1 2 2 3 3 d.a.a.no. } a. }.pl. 1 1 2 2 2 2 21.pl=1.x).

main() { printf("Enter 1 values:"). What does below code do.a). a) b c a b) c b a c) a b c d) both a and b 24.emp1. if temp is pointing to a node other than first and last node temp -> prev ->next = temp ->next. }. } a. scanf("%d%d".512 { int a. //The given input is 10 and 25 printf("a=%d a=%d". 10 10 d. Compiler Error 23. 25 25 c.&emp1.&emp1.a). a) b) c) d) no effect inserts a node deletes a node shuffling of pointers 25. Arrange the code in order to delete a node being pointer by temp. 10 25 b.a.emp1. which is the faster traversable dynamically growing list a) Binary Search Tree b) Singly Linked List c) Doubly Linked List d) Using Array . temp ->next -> prev = temp -> prev. a) b) c) free(temp) temp->prev->next = temp->next temp->next->prev = temp->prev.a.

void main() { int i=5.c). } (a)Compile-Time Error 766 (b)10 9 8 7 6 (c)9 8 7 6 6 (d)10 8 (b)a=6 b=5 (c)a=6 b=0 (d)None of (b)Compile-Time Error (c)0 3 -1 (d)0 3 .i++. a=b.++i). printf("%d %d %d %d %d". printf("a=%d b=%d".i++. void main() { int a=1.a.b. } (a)a=5 b=6 these 3.++i.b) temp=a. b=temp.513 1.b).b=6. c=(--a.i++.temp.a. if (a > b) swap(a. printf("%d %d %d". #define swap(a.b). } (a)0 3 -3 0 2. void main() { static int a=5. b++)-c.b=2.c=3.

char *argv[]) { printf(" %d".h> main() { switch (5) { case 5: printf(" 5 "). 5 10 6 Hello Genesis 13 Hello Genesis Hello Genesis 13 None of the above (b)840 (c)852 (d)864 .h> int main(int argc. F. void main() { int i. case 6: printf(" 6 "). n-i). G. H. default: printf(" 10 "). return 0.514 4. i<n--. 5 G. } (a)84 5. #include <stdio. i+=2) printf("%d". } E. printf("Hello Genesis")). for (i=1. What is the output of the program? #include <stdio. n =10. } } F. 6.

h> #define sq(a) a * a integer union pointer structure It assigns the pointer a NULL value It erases the contents of any type and cleans the pointer It places the memory address with the pointer in free store It disables the memory address with the pointer Stack Register Extern Static first second between 2 strings third . F. G. 11. Which of the following is not a storage class in C? F. #include <stdio. What is the significance of the free() function? E. What is the data type of FILE? E. F. G. G. 8. H. G. I. 5 6 7.515 H. H. H. 9. 5 10 I. Which argument of function 'strncmp()' specifies number of characters to be compared? E. 10. H. F.

Which of the following function does not support dynamic memory allocation? E. H. I. F. Which of the following is a non-linear data structure? E. } E. sq(3 + 2)). alloc realloc malloc free printf scanf strcpy strlen Stack Queue Linked List Tree 25 11 10 Compilation error .516 void main() { printf("%d". 13. G. H. 12. G. F. G. 14. F. H. 15. H. G. What is the output of the program if the input is 103? main() { int p = 234. Which of the following function does not return an integer value? F.

2. G. Where do we use a 'continue' statement? F. 17.sqr(a)). H. What is the postfix expression for A + B * C / D – E * F / G i) ABC*D/+EFG*/j) ABC*D/+EF*G/k) ABCD/*+EF*G/l) None of these. Choose from one of the alternatives (a) return(sqr(a)). H. scanf("%d". p). } E. int abc(int z) { LIFO LILO FIFO Both b & c In 'if' statement In 'switch' statement In 'goto' labels None of the above 3 103 103 103 3 103 2 . 19. G.517 printf(" %d ". int i=5. (c) return(a*a). 16. &p)). Write one statement equivalent to the following two statements: x=sqr(a). 20. printf("%d". (d) printf("%d". (b) printf("sqr(a)"). F. Queue is _________________ a) b) c) d) 18. return(x). I.

delete c. rear 23. }. } main() { int i=4. a) b) c) d) 22.abc(i=i/4)). pop e. union U { int x. } a) b) c) d) 21. What is the Infix expression for -+A/*BCD/*EFG a) A + B * C / D – E / F * G b) A + B / C * D – E * F / G 4 2 8 7 error 5 2 0 . delete b.append . The operation for adding and deleting an entry to a stack is traditionally called: a. what is the size of ob in bytes. union U ob.518 return i/2. front .insert. delete d. printf("%d". float y.push .add . char s[2].

72. What would be the root node if we enter the following data set (in the respective order) into a standard program to construct a Binary search tree? 25. 88. 26. 16. what does the code below do. } temp -> prev -> next = temp -> next. 11. free(temp). 36. 69 e) 69 f) 25 g) 26 h) 9 25. while (temp->next->next!=NULL) { temp = temp ->next. 9. 10 be the number of nodes temp = head. where head is pointing to first node & temp is a temporary pointer. 14. a) b) c) d) no effect deletes some node deletes 2nd last node deletes last node .B * C / D + E * F / G 24.519 c) A + B * C / D – E * F / G d) A . temp -> next -> prev = temp -> prev. 21. 45.

520 .

printf("%d".z. What will be the output of the following program : int main() { int val=5.--val.(-x+y)) * Compute(z.(-y+z))). printf("%d %d %d %d". What will be the output of the following program : int main() { char str[]="Test". return(0). What will be the output of the following program : int main() { int val=5. if ((printf("%s".str)) == 4) printf("Success").Compute(y.x. } (a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 4. return(0). val=printf("C") + printf("Skills"). else printf("Failure"). } a)Success b)TestSuccess c)Compile-Time Error(d)Failure 5.y. } (a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of these 2.val). printf("%d".val--).val. return(0).y=3. return(0).521 1. . #define Compute(x.++val. } (a)40 (b)30 (c)Compile-Time Error (d)None of these 3.z=4.z) (x+y-z) int main() { int x=2.

return(0). void main() { printf("%d".sizeof(int)). } (a)Data types not allowed (b)Compile-Time Error(c)3 (d)2 7. printf("%d". } (a)Compile-Time Error (b)Lvalue required Error 6. return(0). Given tree: A (c)10 (d)11 B a)Inorder : DHBEAFCIGJ Preorder: D A B D H E C F G I J E Postorder: HDEBFIJGCA b)Inorder : Preorder: Postorder: c)Inorder : Preorder: Postorder: d)Inorder : Preorder: Postorder: DHBEAFCIGJ DHEABCFGIJ HH E B F I J G C A D DHBEAFCIGJ ABDHECFGIJ HDEBFIJGAC HDBEAFCIGJ ABDHECFGIJ HDEBFIJGCA C F G I J .522 What will be the output of the following program: int main() { int val=5. Preorder and Postorder traversals. Traverse the given tree using Inorder.5+val++). In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) malloc (d) Queue 8.

h> main() { struct xx { int x=3. 5 6. #include<stdio. void main() { int k=ret(sizeof(float)). compiler error c. printf("%d %f". if(var) main().000000 12. #include<stdio. 0 0 0 0 0 . } b. j = ++i. 3 hello b.000000 c. i. 4 3 2 1 10.++j).var--). 5 4 3 2 1 d. struct xx *s. printf("%s". printf("%d". } b.s->x). 5 5. use dot (. 4 3 2 1 0 c. b. float j.523 9.) operator b.s->name). }. main() { static int var = 5. 6 6. Run time error d. Compiler Error 11. } c. char name[]="hello".h> main() { const int i=4.000000 d. printf("%d ".

c). Compiler Error e. 0 b.524 printf("\n %d". 20 20 d. Compiler Error b. 10 10 14. switch(i) { case 1: printf("1"). 0 1 2 c.y=20.*a=*a-*b. } main() { int x=10. main() { float i=1. a 15. return(ret). y d. 1 2 0 d. c = ++*p++. default : printf("0"). 7 . } c. 10 20 c. char c.int *b) { *a=*a+*b. swap(&x.&y). 8 13. printf("x= %d y = %d\n". } b. 20 10 b.++k). printf(“%c”. b. 6 d. } int ret(int ret) { ret += 2.*b=*a-*b. case 2: printf("2").5.5. } } c. main() { char *p = “ayqm”. 2 0 } b. z c.y).x. b c. int swap(int *a.

main() { int i=10. i = 3. } b. 18 5 d. printf("%d".i). 9 b. main () { int i = 5. } fn(int i) { return ++i. MESS 17. i = i * i.i). Error c. MESS junk 18. case 4: i = i + i. 10 10 c. } (a) 10 (b) 11 (c) 12 Compilation error (d) . } b. case 5: i = i + i. } printf (“%d”. fn(i). Junk b.525 16. switch (i) { static int i. 18 18 e. Int fn(int). printf (“%d”. case 3: i = i + i. What would be the output of the following program.i). #define MESS junk main() { printf(“MESS”). 0 5 d.

b=*ptr.*ptr++). no error. But It will create one more file. what type of Binary Tree is the following tree below .++a. f. It will not allow. If Any? e.fp2) . h. fp1=fopen("one". 20. printf("%d %d %d". 21. The new content will append in existing file. But It will over writes on same file. fputc('B'. error. fp2=fopen("one".--b. main() { FILE *fp1. fputc('A'. fclose(fp2) . no error.*fp2. } Find the Error.fp1) . fclose(fp1) .*ptr=&a.526 19. void main() { int a=555. g. } (a)Compile-Time Error (b)555 554 555 (d)557 554 555 (c)556 554 555 no error."w")."w") .

h. g.527 A B C D E F G H I J K e. If suppose root to be deleted then which node will be the root node A B G C E H I D K J . f. binary tree strictly binary tree complete binary tree not a binary tree 22.

z=++x||++y&&++z.y.i. } 2. If the CPU fails to keep the variables in CPU registers. in that case the variables are assumed a) static b) external c) global d) auto 1.k=0.528 e. } ans::1 10 3. 23. h. m=i++&&j++&&k++||l++. . f.m. Which function is used to detect the end of file a) EOF b) feof( ) c) ferror( ) d) NULL 25.z).l=2. g.main() { int x.j=10.13. B G Any node Both a and b are correct When fopen() fails to open a file it returns a) NULL b) –1 c) 1 d) None of the above 24. printf("%d %d". main() { int i=5.x.j).2.y. printf("%d %d %d". x=y=z=1.z. i=i&=j&&10. main() { int i=-1.j=-1.

main() { int i=10.c.+i). j). } ans::0 1.b=100.29 main() { int a=500. printf(“ %d %d %d\n”.j=7.y. +i = %d \n". printf("i = %d. i=!i>14. } . main() { int i=-1.d=40. } ans:2 3 3 1. y = --x. main() { int i=4.28.i.main( ) { int x=4.e=19. } ans::0 0 1 3 1 3. k == 35. } ans::0 5 0 3.20.k>40).x. printf(“%d %d %d\n”.i).6.k. i.k=50.z).529 printf("%d %d %d %d %d". } ans::4 1 3. z = x--. printf("%d %d".a. } 2.y.j.m).d.z.c=300. printf ("i=%d". +i.l. j = j || i++ && printf("YOU CAN").e).b. printf("%d %d %d %d %d".i. a+=b-=c*=d/=e%=5.main( ) { int k=35.

42. } 1.i--. printf("%d %d".z=2.d).a. } 5. j?(i.z).j).i++. printf("%d %d ".x). printf("%d %d %d %d".z.i.c.34.530 ans -1.b. clrscr(). printf("%d".j=20. return(0).d=4. j = i. printf("%d\n". .b=2. return 0.h> main() { int x.main() { printf("\nab").-1 1.++i.y=2.4. } int main() { int x=5.z. #include<conio. } 3.c=3.!a?b?!c:!d:a).i). main() { int i=10. clrscr(). } int main() { int a=1. printf("%d%d%d%d%d%d".a. if(x=y%2) z=2. main() { int i=5.j)?i:j:j. printf("\bsi"). a=2.--i. z/=y/z==3?y/z:x*y.y=6.

char str2[]="abcd". main() { char *p="hai friends". while(*p!='\0') ++*p++. } 1.*p1. } 2. printf("%s".i++) printf("\n%c%c%c%c". p1=p. char *p=a.p. p++. clrscr().s[ i ]. main() { char s[ ]="man".6. p++.#include<stdio. } ans:: 2 5 5 2. getch(). main() { char *str1="abcd". p[2]='z'. printf("%s %s". } ans::cdzf 2.1.sizeof(str1).h> #include<conio.p1).sizeof("abcd")).*(s+i).s[ i ].531 printf("\rha"). int i.p).sizeof(str2). printf("%d %d %d".h> void main() { char a[]="abcdef".*(i+s). } ans:: m m m a a a n n n . for(i=0.i[s]).

names[4]=t."perl"}. i = 64/square(4). t=names[3]. main() { static char names[5][20]={"pascal". char *t. printf("%d".++*p + ++*str1-32).6 1.*str. } ans::50 3.i). } 3.h> #define a 10 main() { #define a 50 printf("%d". #include <stdio. p=&s[3]. str=p. names[3]=names[4]. #include<stdio.6.7.b)."cobol". str1=s.'\0'}.8.a.'c'.'c'.'b'.2 #define cube(x) x*x*x main() { int b=3."ada". ."fortran". } ans::64 1.h> main() { char s[]={'a'.3. int i. } ans::27.532 1. printf("%d".*str1.a. a=cube(b++). char *p.'\n'. printf("%d %d".7.a). #define square(x) x*x main() { int i.

} } how many times would wipro to be printed? 1 time 4) all the local variables are stored in ----------------a) stack b) heap c) queue d) none ans::a 5) Once you call a function. which is correct? a) both insertion and deltionis made at the front end b) insertion is made at the beginning and deletion is made at the last c) insertion is made at the last and deletion is made at the beginning d) both insertion and deltionis made at the back end 3) for(i=0.all the return addresses are stored in ---------------a) stack b) heap c) queue d) none 6) Which of the following is true about binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. .j<5..j++) { if(i==j) break. 1)Allocating a 2 blocks of memory for 'n' intgers is by using a) malloc b) calloc c) both malloc and calloc d) none of the above 2) In queue using linked list.base address can't be changed names[3]=names[4].. } ans::Lvalue Required.i++) { for(j=0..i++) printf("%s".. printf("wipro").names[i]).i<=4.i<2.533 for (i=0.

back->data). then the code will be a) ptr=ptr->link. } Data Structure Questions & Answers 1)Consider the following structure struct node { int info. Suppose ptr is a pointer which is not pointing to the first or the last node.what will be the output of the following snippet front=start. b) ptr->link=ptr.*right. a) i only b)ii only c) both i and ii d) neither i nor ii 8) struct node { int data. back=end.then.534 a) i only b)ii only c) both i and ii d) neither i nor ii 7) Which of the following is true about complete binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. struct node *left. while(back!=NULL) { printf("%d". Then if we are going to delete a node after ptr. back=back->left. }. d) ptr=ptr->link->link. suppose start and end are the pointers pointing to the beginning and ending node reapectively. }. struct node *link. c) ptr->link=ptr->link->link. .

s1. then the list is a) b) c) d) It is having only 3 nodes with start. i) start->link=s1. if rear=0. ptr in the list. having start as the first node It is a circular linked list It is a doubly linked list None of the above 3) In a queue.535 2) Consider the following structure struct node { int info. front=1 then what will be the queue Queue is empty Queue is full Queue has only one element Queue is circular . iii) ptr->link=start. if rear=0. }. Suppose start is a pointer pointing to the first node of the linked list. Then if we are going to execute the following code. front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 5) a) b) c) d) In a queue. struct node *link. if rear=front then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 4) In a queue. s1 and ptr are the two pointers (they are not pointing to the first or last node). ii) s1->link=ptr.

536 6) In a queue. d.front=-1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 7) In a queue. 1 respectively. }. struct node *left. . b. Then the output is a) b) c) d) 14 11 20 15 9) The infix expression is a+b*(c-d)/(e+f)*h then my postfix expression is a) ab+cd-*ef+h*/ b) abcd-ef+*/h* c) abcd-*ef+/h*+ d) abcdef+-*/h*+ 10) In the stack. if top=0 then the stack is a) Stack is empty b) Stack is full c) Stack has only one element d) None of the above 11) Consider the structure struct node { int info. c.if rear=-1. 2. if rear=max-1. 5. 4. front=0 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above 8) The postfix expression is ab+c*d/e-. e are 2. struct node *right.The values of a.

c) nd->left=nd->left->left. } a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values 12) struct node { int data. struct node *left. 14) struct node . d) nd->right=nd->left->right. ptr=ptr->right) { if(ptr->data%2==0) printf("%d".nd->left->right=nd->right. d) nd->left=nd->left->right. struct node *left.nd->right->left=nd->left->right.nd->left->right=nd. b) nd->left=nd->right->right. How will you delete a node after nd? a) nd->right=nd->right->left.nd->right->left=nd->left->right.*right. ptr. }. 13) struct node { int data. }. If the following executes what will be the output? for(ptr=start.537 We have 10 elements in the list.nd->right->left=nd. b) nd->right=nd->right->right. Suppose nd is a node which is not in the beginning and also not in the end.nd->left->right=nd. ptr->data).nd->right->left=nd->right.*right. c) nd->right=nd->right->left. How will you delete a node before nd? a) nd->left=nd->right->left.nd->left->right=nd. Suppose nd is a node which is not in the beginning and also not in the end.

Suppose ptr is a node which is not in the beginning and also not in the end. How will you delete a node ptr? a) ptr->left->right=ptr->right. .free(ptr).*right. d) ptr->left->right=ptr->left.free(ptr). struct node *left.ptr->left->right=ptr->right.ptr->right->left=ptr->left.ptr->left->right=ptr->left. }.538 { int data. c) ptr->left->right=ptr->left->left.free(ptr).ptr->left->right=ptr.free(ptr). b) ptr->left->right=ptr->right->right.

ii. insert(66.iii.root).root).ii.i d) ii. .root). insert(8.iv.iii. iii) ptr->right=nd. insert(5. insert(70.i.539 15) struct node { int data. delete(13.root).iv b) ii. struct node *left.root).*right. ii) nd->left=ptr. iv) nd->right=ptr->right. Suppose ptr is a node which is not in the beginning and also not in the end. Then what sequence does it follows for inserting nd after ptr? a) i. insert(13. insert(45.root).iii c)iv. insert(13.iii. }. Here is the coding: i) ptr->right->left=nd. insert(25. nd is the new node.root).i.root).root). insert(32.root).root).iv 16) In the Given Infix expression which is the root node for your expression tree (A+B)(C*D)+G/H*I a) + b) c) * d) / 17) Consider a binary search tree insert(10.

printf(“%d %d %d %d”.8.36.5.66. 77.8. 70 . What will be the preorder traversal is a) 5.d=4.32.123).25.10.25.45.b.32.32.c.45. } (a)123 (b)Compile-Time Error (c)123.70. 66. 30.36.8.root).66 c) 10.00 2.5.25.000000 (d) 1 2 3 4 .13.45.13.13 19) The preorder traversal is 5.70 b) 10. d=++a||++b&&++c. What will be the output of the following program : void main() { printf("%f".32.c=3.10.36. 3.70 d) 8. } (a) 0 3 4 1 (b) 1 3 4 5 (c)1 3 4 0 3. What will be the output of the following program : void main() { int a = -1.66.13.540 insert(36.b=2.5.32.45. What will be the output of the following program : void main() (d)123.d).66.70.a.36.What will be the root node a) 5 b) 66 c) 70 d) 30 20) Which one of the following is true for the binary tree i) root is greater than the left sub tree and lesser than the right sub tree ii) root is lesser than the left sub tree and greater than the right sub tree a) only i b) only ii c) both i and ii d) Neither i nor ii 1.

sizeof(4. are. } (a)8 (b)Compile Error (c)%d (d)None of these 7) void main() { int val=5.line). } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these 6) What will be the output of the following program : void main() { printf("d%".]s".line).j. if (0 || -1) printf("Bye").sizeof ( 4. you (a)Compile Error (b)Dear Friends 4. India.how.56).8). l (c ) compile time error (d) run time error 5) What will be the output of the following program : void main() { printf().&I.&k). } (a)No Output (b)Hi! (c)Bye 9) void main() { printf("%d %d".&j. e . printf("\n%s". hi b) h . printf("%*d". } Input is : hello India hi What will be the values of i.56f)). } (d)Hi!Bye .541 { char line[80].k ? (c) dear (d) runtime error // VARIABLES NOT DECLARED a) hello .val). main() { scanf(“%c%c%c”. } INPUT :Dear.. // Max. void main() { printf("Hi!"). length=80 Chars scanf("%[^. } (a) 5 (b)5 (c)Compile-Time Error (d)None of these 8.

U1. y = x % 5. void main() { int x. }u1. x = 27 . 4 (b)4. U1. ) which of the following doesnot change value of variable i .8 (d)4. a) i++ (b) i+1 (c) i=i+1 (d) i+=1 *12.. Char ch[2]. y.a).8 (c)8. struct s { int rno=10..//cannot declare here }s1. z.k). K = j/i. . z = x / 5 . // IT SHOULD BE u1.a } (a) 5 (b) 42 ( c) 1028 (d) 24 13. Printf(“%d”.000000 (d) none of these 14.a=5. Double k. u1. i++) printf(“hi\n”).ch[0]=4 . Printf(“%lf”. union u { Int a.choice+=1)//choice =2 Currently choice will hold what value in Switch statement: (a) 2 (b) 0 (c) invalid switch statement (d) -1 ( ans: 516) 16.5 (c) 2.5 (b) 2.5.4 (c) 2. s1. static int choice. (a) 2 (b) 2.4 10. } what value y and z hold currently : (a) 2.choice-2.5.j=25.i .rno). switch(++choice. int i=10.ch[1]=2. printf(“%d”.499999 (d) invalid type conversion 15. } here the loop is performed how many times ? (a) 2 ( b) 1 ( c) 3 d) infinite 11.choice+1. main() { for( i=-2.542 (a)8.

Printf(“%d %d”. (++a<++b) ?—a:--b. . *(a[0]+3)). printf("%u %u". } . } (a) 5 6 (b) 6 7 (c) 5 7 (d) 6 6 20.b). c=(--a.b.a.b) a=b . if (a > b) swap(a.f(var.b=6. *&z*=*&x**&y.g2) g##g2 main() { int var12=100. printf("%d".b).val. void main() { int a=1. void main() { int x=4. #define f(g.b++)-c. void main() { static int a=5.a. } (a)Compile-Time error (b)5 -6 (c)5 65520 (d)None of these 19. } (a)Compile-Time error (b)Run-Time Error (c)24 (d)Unpredictable 21.c=3.”India”) printf(“%s”. } (a)a=5 b=6 (b)a=6 b=5 (c)a=5 b=5 (d)None of these 18. printf("%d %d %d". a=5.b).y=3.a.. printf("%d". char a[2][11]={“morning”.temp=a.b=6.b=2.z).12)).z=2. #define swap(a. void main() { unsigned int val=5.c). b=temp.temp. printf("a=%d b=%d". } (a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3 0 17.543 (a) compile error (b) runtime error (c) 10 (d) 0 16.val-21). (a) compile error (b) n (c) i (d) none of these *22.

d) [return type] function name (argument list). 10}. FIFO Structure LIFO Structure LILO Structure NON Linear Structure . 6. 25} }. The syntax of a function call statement is a) function name (argument list). 20.2.fgets (c) fread.//there sud be p=&i. printf(“%d”.5}. C. 15. . 12. Int *p= i. fgetc.. 6.NULL . Int *q = i. (a) 1 (b) 2 (c) address of a[0] (d) none of these 26. 25. EOF are used for the following commands respectively (a) fgetc.12 (c) 6 ..3. D. 7 (b) 7. int a[5] = { 1.to locate the position of file pointer in a file. 13 (d) none of these 30. { 5. 9. which of the following mode is useful for editing a file ? (a) w+ (b) r+ (c) a+ (d) a 28.4. b) [storage class] function name (parameter list). What is the vlalue of *(*(p+1)+1)+1 . 8.fread (b) fread. Printf(”%d %d”. c) function name (parameter list).544 a)compilation error b)runtime error c)100 d)var##12 23.fgetc (d) none of these//ans sud be c 27. which of the following function is used (a) ftell() (b) fseek ( ) (c) fwrite( ) (d) fread( ) 31. *q). B. feof . I++. 15}. int p[3][5] = { { 2.fgets. Which data structures used to perform recursion? A.*a). *p. fgets. { 3. int I=40. the term FILE is a (a) header file (b) Predefined function (c) Predefined structure (d) none of these 29. 4. 10. } (a) 40 41 (b) 41 41 (c) 40 40 (d) compile time error 24. a++. *(*(p+1)+2)//ans is 7 9 so none of these (a) 6.

1 f. 4 i. stacks use only one. Which of these pointers will change during an insertion into a NONEMPTY queue? a. Only front_ptr changes. keeping track of a front pointer and a rear pointer. . 5 36. DCBA d. Que[1] c. From where does the DeleteQue function deletes item in the array? a. c. Que[0] b. Neither changes b. 'B'. The operation for adding an entry to a stack is traditionally called: a. with ten items in the Queue stored at Que[0] through Que[9]. 34. b. Both change. insert d. The CAPACITY is 30.Here is an infix expression: 6+2*(1*5-9). and then removed one at a time. I have implemented the queue with a linked list. 'C'. If the characters 'D'. add b. Queues use two ends of the structure. Queues require dynamic memory. Que[9] d. 3 h. ABCD *36. One difference between a queue and a stack is: a. push 33.545 32. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? e. 'A' are placed in a queue (in that order). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. 2 g. DCAB c. but stacks do not. d. Suppose we have an array implementation of the Queue. Que[10] 35. Only rear_ptr changes. append c. ABDC b. in what order will they be removed? a.

Ptr->next->next->next 41. push c. Then which of the following statement will cause Ptr to point 5th node data. Ptr->next->data c. Which of the following stack operations could result in stack Overflow flow? a. Self referential structure d. is_full pop b. Ptr->next->next->data b.(C + D) * (P / Q) and traversed in Preorder. Suppose that p is a pointer variable that contains the NULL pointer. 2^n nodes d. 39. d. Stacks require dynamic memory. Then which of the following statement will cause Ptr to point 3th node data. How many Nodes? (where ‘n’ is height) a. Suppose think there is a Double linked list with 15 nodes and a pointer Ptr pointing to the Fifth node. AB*CD+PQ/*c. Ptr->next->prior->prior b. Two or more of the above answers 40. A run-time error always occurs when *p is evaluated. A Structure which can refer an another Structure of same type is called as: a. a. a. then we will get the following output. d. b. 2^(n-1) nodes c. Stacks use two ends of the structure. n nodes b. If we draw a binary Tree for the expression : A * B . Dynamic structure 43. A syntax error always occurs at compilation time. 37. Ptr->next->next->next->data d. What happens if your program tries to read or write *p? a. Nested structure c.546 c. ABCDPQ-*+*/ d. A run-time error always occurs when the program finishes. A Full Binary Search Tree contains. -*AB*+CD/PQ b. *-+*/ABCDPQ 38. c. Structure within structure b. Ptr->next->next->next . queues use only one. Suppose think there is a linked list with 10 nodes and a pointer Ptr pointing to the Second node. a. but queues do not. (2^n)-1 nodes 42. The results are unpredictable.

Non leaf node 48. ptr->marks). Ptr=first->prior . ptr = ptr->next ptr = first. Suppose Ptr needs to point last but one node in a Double linked list. 46. Leaf node d. d. What Boolean expression will be true when Ptr points to the tail node of the list? a. ptr =first. } a. replace the XXXXXXX with correct statements. b. Lists implemented with an array. Suppose Ptr points to a node in a linked list. b. Which of the statement will give me the result? a. Right child b. c.0 e. Ptr->data == 0. Ptr->next->prior->prior->prior d. ptr = ptr->next ptr = last. (ptr). Ptr->data == NULL d.547 c. In a Binary Search tree a new node is always inserted as: a. Ptr->next->prior->next->prior 44. ptr = ptr->prior 47. Doubly-linked or singly-linked lists are equally best 45. Singly-linked lists. Ptr->link == NULL c. (ptr). the given below is login for Reverse traversal of a double linked list. (ptr). Ptr == NULL b. c. Doubly-linked lists. ptr = ptr->prior ptr = last. for( XXXXXXX ) { printf(“%d”. None of the above. What kind of list is best to access the item at given position n?" a. d. (ptr). Left child c.

NULL b. e. d. 1 . static d.548 b. B. c. A only B only C only All of A. s contains the next character read from the file (unless there is no data left on the file) a. Ptr=last->next d. what is true about the above statement? A. c. Which of the following can be used across files a. or C Answer: b. 1. “%c”. Which of the following applications may use a stack? a. d. infile is the name of a file B. b. When fopen() fails to open a file it returns _______ a. after the fscanf executes. B and C None of A. A parentheses balancing program. extern b. B only 2. &nextChar). volatile c. Syntax analyzer for a compiler. -1 c. All of the above. infile is the name of a variable of type FILE* C. Ptr=last->prior c. const Answer: a 3.Consider the following statement : s= fscanf(infile. Ptr=first->next->prior 49. Evolution of postfix expression. b.

549 d. "assertion failed: %s. what is the output of the following #define assert(cond) if(!(cond)) \ (fprintf(stderr.__LINE__).c followed by an infinite loop prints some data after EOF reaches. d. The EOF is equivalent to a. contents of zzz.h> main() { FILE *ptr."r"). else printf("This statement becomes else for if in assert macro"). 0 d. line %d \n".#cond. ptr=fopen("zzz. char i. What will be the output of following code assuming file already exists with some contents #include<stdio. b. NULL 4. c. file %s. None of the above Answer: a 5. None of the above Answer: a.i). error .c". printf("%c". } a. if(i==0) assert(i < 100).c error contents of zzz. no output b. while((i=fgetch(ptr))!=EOF). -1 b. Answer: D 6. abort()) void main() { int i = 10. } a.\ __FILE__. 1 c.

where fp points to the file which contains the data in the following format wipro innovation program what is the output? a."w") . No Error. -------fgets(x. a. prints assertion failed in the file Answer: c 7.fp).*fp2. c. d. fclose(fp1) . Considering the code Char x[20]. else part is printed d.550 c. What will be the output of the following code segmet FILE *fp1. printf(“%s”. When file opened in mode “ab” . b. fputc('A'. fp2=fopen("one".fp1) . wipro wiproinnovationprogr ram wipro\ninnovation\npro Answer: A 9. Runs successfully d. None Answer: C 8.20. fclose(fp2) . but it will over writes on same file b.fp2) . fputc('B'. Error in pointer declaration c."w") .x). fp1=fopen("one".

9 with less precision than long double. d. which among the following is correct a. b. long double) the values cannot be predicted exactly. >=.1. <. >. if(me==you) printf("Hello").50.4). So float stores 0. Answer: Welcome Explanation: For floating point numbers (float. c. c. else printf("Welcome"). <=.1. b. main() { float me = 1. } 1. moves the file pointer to beginning of file moves the file pointer to the 50th byte from beginning of file moves file pointer to the 50th byte from end of file compilation error Answer: d SESSION 1 1. main() { . pointer is placed at the beginning of file end of the file error in opening none of the above Answer: b 10. Depending on the number of bytes. Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== .!= ) 2. double. d. double you = 1. Float takes 4 bytes and long double takes 10 bytes. the precession with of the value represented varies.551 a. Consider the following statement fseek(fp.

h> main() { int i=1. i=!i>14. switch(i) { default:printf("zero"). Answer : three Explanation : The default case can be placed anywhere inside the loop. case 3: printf("three"). Answer: i=0 Explanation: In the expression !i>14 .552 int i=3. #include<stdio. break. 3.i). break. switch(i) { case 1: printf("GOOD"). . } } 2. 4. 0>14 is false (zero). !i (!10) is 0 (not of true is false). break. It is executed only when all other cases doesn't match.j=2. case 2:printf("two"). main() { int i=10. } 3. case 1: printf("one"). NOT (!) operator has more precedence than ‘ >’ symbol. printf ("i=%d". ! is a unary logical operator.

case j: printf("BAD"). printf("%d". and i is incremented (note the semicolon after the for loop). 5. } 6. Answer: Compiler Error: Constant expression required in function main. } } 4. // value 10 is given as input here } 5. 6. printf("%d". break. for(.scanf("%d". Here it evaluates to 0 (false) and comes out of the loop. So number of items read is 1.i)) .i++. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error). Here 10 is given as input which should have been scanned successfully. main() { int i.printf("%d".553 break. Answer: 1 Explanation: before entering into the for loop the checking condition is "evaluated". main() { int i=0. Answer: 1 Explanation: Scanf returns number of items successfully read and not 1/0.&i)).i). Note: Enumerated types can be used in case statements. .

and any non-zero value is considered to be the boolean value TRUE. printf("%d==1 is ""%s". main() { int i=-1. Answer: 0 Explanation: ! is a logical operator. In C the value 0 is considered to be the boolean value FALSE. +i = %d \n". main() { char not.+i). 8. } 9. +i. !TRUE is FALSE (0) so it prints 0. main() { int k=1. +i = -1 Explanation: Unary + is the only dummy operator in C. Here 2 is a non-zero value so TRUE. } 8. 9. So the string is as if it is given as "%d==1 is %s".not). printf("i = %d. The conditional operator( ?: ) evaluates to "TRUE".k==1?"TRUE":"FALSE"). } 7. printf("%d". Answer: 1==1 is TRUE Explanation: When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). Answer: i = -1.k.554 7. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator).i. . not=!2.

} // If the inputs are 0.i. } 11. main() { int y.3 find the o/p 12. Answer: 4--0 .i)) printf("%d--". int i. scanf("%d". else printf("%d is not a leap year"). 12. -i. for ( t=4. Answer: i = -1. printf("i = %d.-i). } 10. 11.&i)-t.t--).555 10.printf("%d\n".1.scanf("%d". main(){ int t. Answer: 2000 is a leap year Explanation: An ordinary program to check if leap year or not. // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"). In printf first you just print the value of i.&y). After that the value of the expression -i = -(-1) is printed.2. -i = 1 Explanation: -i is executed and this execution doesn't affect the value of i. main() { int i=-1. -i = %d \n".

Explanation: i is an unsigned integer. Answer: hello Explanation: The comma operator has associativity from left to right. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.char y =10. main(){ int a= 0.&i)-t the values during execution will be.i>-2. for(i=1. } 13. Thus the value of last variable y is returned to check in if. Only the rightmost value is returned and the other values are evaluated and ignored. void main() { while(1){ if(printf("%d". It is compared with a signed value.i--) printf("c aptitude"). } 14.b. if(a. t i x 4 0 -4 3 1 -2 2 2 0 13.556 3--1 2--2 Explanation: Let us assume some x= scanf("%d".printf("%d"))) . "hello" will be printed.x. 14. Since it is a non zero value if becomes true so. 15. main(){ unsigned int i.char x =1. signed is promoted to unsigned value.int b = 20. Since the both types doesn't match.y) printf("hello").

} } 15. The condition reduces to if (x) or in other words if(0) and so z goes uninitialized. Thumb Rule: Check all control paths to write bug free code. printf("%d %d ". So it encounters the break statement and comes out of the while statement.x).z. 16.z. Answer infinite loop Explanation .y=2. main() { unsigned char i=0. for(.557 break.h> main() { int x. } 17. 17.a. printf("%d\n". This value is assigned to x. } 16.i). Answer: Garbage-value 0 Explanation: The value of y%2 is 0.i++) . Still the outer printf prints something and so returns a non-zero value. Answer: Garbage values Explanation: The inner printf executes first to print some garbage value. else continue. a=2. #include<conio. The printf returns no of characters printed and this value also cannot be predicted.i>=0. if(x=y%2) z=2.

the same gets printed.j=20. But dont write programs that depend on such behavior. Answer:128 Behavior is implementation dependent. printf("%d\n".i++) . j?(i. On the other hand if it considers char to be unsigned by default. 20. j = i. Explanation: The detail if the char is signed/unsigned by default is implementation dependent.65). . main() { char i=0.i). Since this string becomes the format string for printf and ASCII value of 65 is ‘A’. If the implementation treats the char to be signed by default the program will print –128 and terminate. main() { int i=10. } 18. So the i++ can never yield negative value and i>=0 never becomes false so that it can come out of the for loop. main() { char p[ ]="%d\n".i>=0. } 19. Answer: A Explanation: Due to the assignment p[1] = ‘c’ the string becomes. for(. “%c\n”.558 The difference between the previous question and this one is that the char is declared to be unsigned. printf(p.j)?i:j:j. Rule: You can write programs that have implementation dependent behavior. p[1] = 'c'. 18. it goes to infinite loop. 19.

} else j = j. else j = j.5. Answer: 10 10 Explanation: The Ternary operator ( ? : ) is equivalent for if-then-else statement. default : printf("0"). Answer & Explanation: Prefer the first one.j). } } 21. switch(i) { case 1: printf("1"). Which version do you prefer of the following two. . 21. case 2: printf("2"). Answer: Compiler Error: switch expression not integral Explanation: Switch statements can be applied only to integral types. 22. main() { float i=1.j) { if(i.j) j = i.str). // or the more curt one 2) printf(str).559 printf("%d %d". So the question can be written as: if(i. If the str contains any format characters like %d then it will result in a subtle bug.i. } 20. 22. 1) printf(“%s”.

} 25. printf("%s". 24. printf("%s". ch. Thus ch is always smaller than 127. Answer: Infinite Loop Implementaion dependent Explanation: The char type may be signed or unsigned by default. } 24. main() { char a[4]="HELLO". main() { char a[4]="HELL". for(ch=0.ch++) printf(“%c %d \n“. Answer: HELL Explanation: The character array has the memory just enough to hold the string “HELL” and doesnt have enough space to store the terminating null .a). Answer: Compiler error: Too many initializers Explanation: The array a is of size 4 but the string constant requires 6 bytes to get stored.560 23. void main() { char ch. ch). } 23.ch<=127. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128.a). 25.

-2. } 27. Session -2 26. if(printf("%s\n". Hence printing a null character returns 1 which makes the if statement true.561 character. Because -. printf("c=%d". else printf("Forget it\n")..c).operator can only be applied to variables as a decrement operator (eg. thus "Ok here" is printed. i--). minus * minus= plus. char a[]="\0". Answer: c=2. Explanation: Here unary minus (or negation) operator is used twice. Same maths rules applies. What is the output of the program given below .a)) printf("Ok here \n"). main() { int c=. Note: However you cannot give like --2. 28. So it prints the HELL correctly and continues to print garbage values till it accidentally comes across a NULL character. void main() { int i. } 26. ie. 27. 2 is a constant and not a variable. Answer: Ok here Explanation: Printf will return how many characters does it print.

But dont write programs that depend on such behavior. } 28.562 main() { signed char i=0. On the other hand if it considers char to be unsigned by default. it goes to infinite loop. It prints the current value of i that is -128. for (. If the implementation treats the char to be signed by default the program will print –128 and terminate. main() { char i=0.i). printf("%d\n". } 29. main() { int i = 3. for(.i>=0. 29.i++) .i++=0. Answer: Behavior is implementation dependent. THe initial value of the i is set to 0. Rule: You can write programs that have implementation dependent behavior. } . The inner loop executes to increment the value from 0 to 127 (the positive range of char) and then it rotates to the negative value of -128. Answer -128 Explanation Notice the semicolon at the end of the for loop.i>=0.i).i). printf("%d\n".i++) .) printf(“%d”. Explanation: The detail if the char is signed/unsigned by default is implementation dependent. 30. The condition in the for loop fails and so comes out of the for loop. for(.

k=0. i is 5. The values of other variables are also incremented by 1. Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination. So the value of m is 1.i. } 32.563 30. Answer: 1 10 Explanation: The expression can be written as i=(i&=(j&&10)). Session – 3 32.i. Answer: Compiler Error: Lvalue required.m).for which it gives 0).j=-1. Answer: 00131 Explanation : Logical operations always give a result of 1 or 0 . printf("%d %d". main() { int i=5.l=2. i = 5&1 is 1.j). Explanation: As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation. The inner expression (j&&10) evaluates to 1 because j==10. main() { int i=-1. So the expression ‘i++ && j++ && k++’ is executed first.j=10. m=i++&&j++&&k++||l++. The result of this expression is 0 (-1 && -1 && 0 = 0). printf("%d %d %d %d %d".l. And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. 31.m.j. i=i&=j&&10. Hence the result. } 31. .k.

34.i++.i.0 Explanation: The value of i is 0.564 33. Since this information is enough to determine the truth value of the boolean expression. The evaluation is by popping out from the stack. Answer: 45545 Explanation: The arguments in a function call are pushed into the stack from left to right. hence the result.%d".j). } 35.i++.z.i--.i).. So the statement following the if .j=0.--i. printf("%d. if(i && j++) printf("%d. Answer: 11 Explanation: the expression i+++j is treated as (i++ + j) 35. printf("%d".. printf("%d%d%d%d%d%d". Answer: 0.i+++j).j=6..j). main() { int i =0. } 33.%d.++i. } 34. and the evaluation is from right to left. main() { int i=5. main() { int i=5.

} 37. } 38. Due to post-increment on i the value of i while printing is 1.i).++giveit). printf("%u \n". void main() { unsigned giveit=-1.i). The values of i and j remain unchanged and get printed. Answer: 0 65535 37. . printf("%d".. printf("%u ". 38. while(i-->=0) printf("%u ". When the value of i becomes 0 it comes out of while loop. main() { unsigned int i=10. } 36. Answer: 1 Explanation: Note the semicolon after the while statement.565 statement is not executed. 36. main() { unsigned int i=65000.>=0 will always be true. Answer: 10 9 8 7 6 5 4 3 2 1 0 65535 65534….gotit=--giveit). So the expression i-. Explanation: Since i is an unsigned integer it can never become negative. leading to an infinite loop. int gotit. while(i++!=0) .

1. false && (anything) => false where (anything) will not be evaluated. Hence the result. main() { int i=4. j = j || i++ && printf("YOU CAN").j=7. main() { float me = 1. printf(“%d”. In the inner expression. printf("%d %d".i=++i ==6). Because it is followed by || and true || (anything) => true where (anything) will not be evaluated. . So the remaining expression is not evaluated and so the value of i remains the same. j is not equal to zero itself means that the expression’s truth value is 1. because == is of higher precedence than = operator. } 39. 40. Answer: 41 Explanation: The boolean expression needs to be evaluated only till the truth value of the expression is not known. ++i is equal to 6 yielding true(1). the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated. j). Answer: 1 Explanation: The expression can be treated as i = (++i==6). } 40. main() { int i=5. when any of the operands become false. i. SESSION 1 1.1. double you = 1.566 39. Similarly when && operator is involved in an expression.

i). } Ans: linker error. 3. } void display(char *string) { printf("%s".567 if(me==you) printf("Hello"). case 1: printf("one").string). display(string). main() { extern int i. #define int char . main() { char string[]="Hello World". case 3: printf("three"). i=20. } Ans::Hello World 5. break. } } Ans: Three 4. break. main() { int i=3. break. else printf("Welcome"). case 2:printf("two"). printf("%d". switch(i) { default:printf("zero"). } Ans: welcome 2.

} Ans: 64 8. #define clrscr() 100 main() { clrscr(). #include <stdio. main() { int i=10.i). i=!i>14. } Ans: 50 9. #define square(x) x*x main() { int i. printf ("i=%d". } Ans: 1 6.h> #define a 10 main() { #define a 50 printf("%d". printf("%d".sizeof(i)).568 main() { int i=65.a). printf("%d\n".clrscr()). i = 64/square(4). printf("sizeof(i)=%d". } Ans: 100 . } Ans: 0 7.i).

main() { clrscr().main() { printf("%p".%d").main). main() { int i=400.j=2. ans::error:type mismatch 12. } Ans: error::goto here sud be defined and called in same fuction 14. } Ans::300 400 13. } Ans : address of main 11.h> main() { int i=1.i). #include<stdio. switch(i) . printf("%d.569 10. } } fun() { here: printf("PP").. main() { int i=1.j=300. i++. while (i<=5) { printf("%d". } clrscr(). if (i>2) goto here.

printf("%d".i++.&i)). } int out=100. for(. . main() { extern int i.sizeof(i)).printf("%d". i=20. main() { extern out. main() { int i=0. printf("%d". printf("%d". printf("%d". case j: printf("BAD"). main() { int i. break.scanf("%d". } } Ans: Error::case sud have a constant value 15. out). // value 10 is given as input here } Ans: 1 16.i). } Ans: 1 ya since i++ will not increment first time so I is o in for that’s why 17 . break.570 { case 1: printf("GOOD").i)) . } Ans: Linker error 18.

not). } Ans: -1 -1 21. } void show() { printf("I'm the greatest"). printf("i = %d. } Ans::I m the greatest 20. main() { show().571 Ans: 100 19.stdoutput.i. What are the files which are automatically opened when a C file is executed? Ans: stdinput. } Ans: 0 if %c is used then a blank is printed as !2=0 24.+i). main() { char not. #define FALSE -1 #define TRUE 1 #define NULL 0 main() { . +i. not=!2. 22. +i = %d \n". 23. main() { int i=-1. } Ans: runs until stack overflow. main() { main(). printf("%d".stderror.

main() { int k=1.y). printf("%d==1 is ""%s". } Ans: i=-1 i=1 28.572 if(NULL) puts("NULL"). // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year". 26.y).i. if((c>='a') && (c<='z')) . main() { int y.x. main() { int i=-1. } Ans: TRUE ::print as it anythng in double quotes 25.-i). } Ans: 1==1 is True. scanf("%d". else printf("%d is not a leap year".convert(z).&y). else puts("FALSE"). printf("i = %d.k==1?"TRUE":"FALSE"). else if(FALSE) puts("TRUE"). -i = %d \n". } Ans: 2000 leap year 27. -i.k. getc(c). main() { char c=' '.

y) printf("hello").printf("%d\n".573 x=convert(c).scanf("%d". } convert(z) { return z-32.num2. sum(argv[1]. } Ans:hello .char x =1.2. } sum(num1. } Ans:Error?? 30.argv[2]). { return num1+num2. char **argv) { printf("enter the character").i)) printf("%d--".t--). } Ans: Error//1ST convert (char).b.x.&i)-t. if(a. main(){ int t.num2) int num1. int i. main(int argc.int b = 20. getchar(). printf("%c".x).1. } // If the inputs are 0. main(){ int a= 0.3 find the o/p Ans: 4—0 3—1 2—2 //GUD 1 31.will do in fuction prtotype+fuc dec convert(char z) sud be used+getc() is not a library function 29. for ( t=4.char y =10.

printf("%d"))) break. } } Ans: (garbage or 0) 1(compiler dependent) 34. #include<conio.i>-2.574 32. 33. } Ans: garbage 0 35. void main() { while(1) { if(printf("%d". printf("%d\n".i--) printf("c aptitude"). printf("%d %d ". } Ans: infinite.x). else continue. for(.a.h> main() { int x.i>=0. a=2.y=2.z.i). for(i=1. if(x=y%2) z=2.z. main() { unsigned int i. } Ans: infinite 36. . main() { char i=0. main() { unsigned char i=0.i++) .

str2)) printf(“Strings are not equal\n”).i>=0. char str2[] = {‘s’. main() { char p[ ]="%d\n". } Ans: no output. printf("%d\n". main() { while (strcmp(“some”. printf("%d %d".j=20. while (strcmp(str1. } Ans: 10 10 43. main() { int i=10. p[1] = 'c'.j). 42.65).i++) .575 for(. j = i.’m’.j)?i:j:j.’o’.”some\0”)) printf(“Strings are not equal\n”).i). } Ans: A 40. } Ans: no output//strcmp(gives 0 if all letters are equal) 41.’o’. } Ans: -128 39. main() { char str1[] = {‘s’.i. main() { register int a=2.’m’.’\0’}.’e’.’e’}. . j?(i. printf(p.

{ int i=20.&a). } } Ans: error 45.str).5. printf("Value of a = %d". // or the more curt one 2) printf(str). To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString.i). switch(i) { case 1: printf("1"). main() { extern i. printf("%d\n". char inputString[100] = {0}. 1) printf(“%s”. } Ans: error 44. sizeof(inputString). fp) Ans: 1. Which version do you prefer of the following two. . } } Ans: linker error(run time error) 46. case 2: printf("2").i). printf("%d\n". default : printf("0").576 printf("Address of a = %d". 47. main() { float i=1.a).

main() { char s[ ]="man". void main() { char ch. } Ans: HELLgarbage 51. Ans: error SESSION 2 1.ch++) printf(“%c %d \n“. printf("%s". for(ch=0. printf("%s".ch<=127. ch). out). ch.577 Ans: 1 48. main() { char a[4]="HELLO". main() { printf("%d". } int out=100. .a). } Ans: error//too many intializers 50. main() { char a[4]="HELL". } Ans: infinite 49.a).

printf("%c\n". p="Hello". main() { printf("%x". } Ans: 1 2 *3.c).*&*p). } Ans: mmmm aaaa nnnn 2.*(s+i). main() { char *p. main() { char *str1="abcd".*(i+s). } Ans: 2 5. .. char str2[]="abcd".i++) printf("\n%c%c%c%c". } Ans: 0xfff0 4. main() { char *p.578 int i. for(i=0.-2. printf("%d %d ".sizeof(*p).i[s]). } //here*&p==&*p Ans: H 6.s[ i ].-1<<4).s[ i ]. printf("c=%d". main() { int c=.sizeof(p)).

else printf("Forget it\n"). } Ans: Ok here 9. main() { char i=0. for(. if(printf("%s\n".i>=0.h> main() { register i=5. . char a[]="\0".//valid int can be dropped char j[]= "hello". } Ans: hello 5 8.i).sizeof("abcd")).i). printf("%d\n".579 printf("%d %d %d". #include<stdio. } Ans : -128 10. void main() { int i. What is the output of the program given below main() { signed char i=0.i++) . for(.sizeof(str1).j.sizeof(str2). } Ans: 2 5 5 7.i).i>=0. printf("%d\n".i++) .a)) printf("Ok here \n"). printf("%s %d".

} Ans : L value required error. int)). #define DIM( array.j=10. } main() { . DIM(arr. } Ans : 1 10 14. for (. i=i&=j&&10. main() { int i = 3. printf("%d %d".i. main() { int i=5.j).i).i++=0. type) sizeof(array)/sizeof(type) main() { int arr[10].) printf(“%d”. int DIM(int array[]) { return sizeof(array)/sizeof(int ).580 } Ans : -128 *11. printf(“The dimension of the array is %d”. } Ans : you can answer this if you know how values are represented in memory 12. } Ans: 10 15. 13. void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”).

'\n'. main() { static int var = 5. } Ans: The dimension of the array is 10 16.'b'. arr1 list={0.'c'.k=0. #define max 5 #define int arr1[max] main() { typedef char arr2[max].l=2. DIM(arr)).j.1. printf(“The dimension of the array is %d”.h> main() { char s[]={'a'.j=-1.k. p=&s[3].3. if(var) main(). printf("%d ".581 int arr[10]. printf("%d %d %d %d %d".'\0'}. char *p.i. .*str. main() { int i=-1.'c'.2.m. m=i++&&j++&&k++||l++.name).4}.*str1.l. arr2 name="name". #include<stdio.list[0].var--). } Ans: Error SESSION 3 1. printf("%d %s". } Ans: 0 0 1 3 1 3.m). } Ans : 5 4 3 2 1 2.

5 5.i--. names[3]=names[4]."perl"}."ada". } Ans : 4. while(*p!='\0') ++*p++. printf("%d". names[4]=t. void main() { int i=5.//asc of ‘\n’==10 so 11+98-32==77// } Ans: 77 4. p1=p. main() { char *p="hai friends". main() { int i=5.5. printf("%d%d%d%d%d".i). increment .names[i]).582 str=p.i++) printf("%s". char *t.p1). for (i=0.p. } Ans: ibj!gsjfoet 6.--i."fortran".*p1. int i.++*p + ++*str1-32). str1=s.//whever there is a pointer we consider r to l so 1st post printf("%s %s". main() { static char names[5][20]={"pascal".i++.++i. t=names[3].4.5."cobol". } Ans: Error 7.i<=4.

main() { . p=&s[3]. printf("%d".'\n'.i++ +++i). } Ans: 12 8.z. float j. } Ans : 77 10.*str. #include<stdio. j = ++i. char *p.i++ + ++i). } Ans: 11 12.j=6.'c'.'\0'}.h> main() { const int i=4.'b'. main() { int i=5. printf("%d %f". printf("%d".++j). #include<stdio. } Ans : Lvalue required error 9.i+ + +j). i.'c'.++*p + ++*str1-32). str1=s.583 printf("%d". } Ans: error 11. void main() { int i=5. printf("%d". str=p.h> main() { char s[]={'a'.*str1.

void main() { int k=ret(sizeof(float)).i). } Ans : 9.j=0. printf("%d.584 int i=_l_abc(10). } } Ans: 0 0 0 0 16.%d. printf("\n here value is %d".i++.j). main() { int i =0.++k). 13.. } Ans: 0 0 *14. if(i && j++) printf("%d. printf(p-2. printf("%d\n". p++. void main() { static int i=5.--i).. .300)..i. p++. printf("%d ". main() { char *p. } //printf(name of string )==will print string.%d". } int _l_abc(int i) { return(i++). Ans: 300 15. if(--i){ main(). p="%d\n".j).

j.i). printf("%d\n". } Ans: garbage 20.++giveit). while(i-->=0) printf("%u ".j=j++. printf(“%d%d%d”. k). . printf(“i = %d j = %d k = %d”.5. } Ans: 0 65535 19.585 } int ret(int ret) { ret += 2. void main() { int i=i++. k=k++.k=k++.++i).j.k). printf("%u \n". 17. void main() { unsigned giveit=-1.gotit=--giveit). printf("%u ". } Ans: 6 *18. int gotit. main() { unsigned int i=10. } Ans: Error 21. void main() { char a[]="12345\0". void main() { static int i=i++. int i=strlen(a). return(ret). } Ans: 7. j=j++. i.i.

printf("%d".586 } Ans: infinite 22.g=10. main() { int i=0.f<<2). printf("%f\n".j=20.k=50}. main() { float f=5. printf("%d". } Ans: l value required ++(i++) since (i++)will give an constatnt value and cant perform ++ on a constant value error 26. while(i++!=0). while(+(+i--)!=0) i-=i++.++i++).//illegal instruction printf("%lf\n".. printf("%d".fmod(f.++k). enum{i=10.//illegal instruction printf("%lf\n".f%g). . main() { int i=5. main() { int i=5. } Ans: -1//ya check while 24.i). printf("%d\n". } Ans: 1 23. main() { unsigned int i=65000.//cannot increment.i).g)). //Legal instruction } Ans: error 25.

void main() { static int i.’n’.*j. j). puts(someFun2()). char *someFun1() { char temp[ ] = “string". printf("%d %d". return temp. } char *someFun2() { char temp[ ] = {‘s’. main() { int i=4.’r’. printf(“%d”. while(i<=10) (i>2)?i++:i--. j = j || i++ && printf("YOU CAN"). } int main() { puts(someFun1()). i.j=7. } Ans: garbage SESSION 4 1. } Ans: 4 1 29.’g’}.587 printf(“%d”.’i’. return temp. } Ans: 1 27. main() { int a=10. .i=++i ==6). ‘t’. i). } Ans: 32767//ya 28.

Ans: Legal 3. j=k=&a.j. j=2. sizeof(struct unknown *)). sizeof( void *)). void main() { int *i = 0x400.k). } Ans: type of k is unknown hence ERROR 2. } Ans : Legal 6. ptr = (int *) 0x400.//ya but *ip/(*jp) is valid since /* is used for printf(“%d”. What is the subtle error in the following code segment? void fun(int n. } Ans: 2 2 2 2 5. Is this code legal? int *ptr. // set the value of memory location pointed by i.k). printf(“sizeof (int *) = %d \n”. int *ip= &i. void main() { printf(“sizeof (void *) = %d \n“. k++. void main() { int i=10. int arr[]) { . printf("\n %u %u ". // i points to the address 400 *i = 0. *jp = &j. printf(“sizeof (double *) = %d \n”. } comment Ans : error 4. int k = *ip/*jp. printf(“sizeof(struct unknown *) = %d \n”.588 void *k. sizeof(double *)). j++. sizeof(int *)).

7. *++ptr=2. *((char*)iPtr+1) ). int *iPtr = &i. main() { int i=300.// int *iPtr = &i. } Ans:300 *9.i). *((char*)iPtr+1) ).h> main() { char * str = "hello". printf("%d". printf("%d %d". while (*ptr++) least = (*ptr<least ) ?*ptr :least. char least = 127. } Ans: 0//gud 1 8. main() { int i = 257. printf("%d". printf("%d %d". } Ans: only one stmt executes with in while loop. #include <stdio. while(i++<n) p = &arr[i]. *p = 0. } . *((char*)iPtr). *((char*)iPtr). } // Ans: 2 1 *10.589 int *p=0. char *ptr = &i. main() { int i = 258. int i=0.least). char * ptr = str.

5. sizeof(*p). strlen(a)).3. int i. main() { char *p="GOOD". *(*(j+p)+i). strlen(a) = %d". *f2+=*f2+=a+=2. } sizeof(p).j.590 Ans: 1 1 11.*(*(i+p)+j).5. sizeof(a). char a[ ]="GOOD".8.9}.i<3. printf("\n sizeof(p) = %d.a.7.j<3.*f2.*f2). . main() { int a=2.f1=&a. static *p[]={a.a+2}. } Ans: 2 1 4 54 13. printf("\n sizeof(a) = %d.*(*(p+i)+j).*f1.//a=2.6.*(*(p+j)+i)). strlen(p) = %d".*f1. } } Ans : 1 1 1 1 2424 3737 4242 5555 6868 7373 8686 9999 //gud que 12.a+1. main() { static int a[3][3]={1. sizeof(*p) = %d.f2=&a// f1=f2=&a. strlen(p)).4. for(i=0. printf("\n%d %d %d".j++) printf("%d\t%d\t%d\t%d\n".2.i++) { for(j=0.

} Ans:b 16. printf(“%c”. main() { char *p = “ayqm”. } Ans: b 17. ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ). const char *a. 3. 19. Ans: data constant Pointer constant Data constant 15. c = ++*p++. Is the following statement a declaration/definition. printf("%d\n". Find what does it mean? int (*x)[10].c). char* const a. main() { char *p = “ayqm”. 2. 1. -Differentiate the above declarations. main() { .++*(p++)). char const *a. char c. } Ans: 1 18. Ans: pointer to an array of 10 integer data.591 Ans: 16 16 16 Gud1 14. What is the output for the following program main() { int arr2D[3][3]. printf(“%c”.

8} }.. {5.(int*)*v).4}.3}. p=q=r=0.r). .h> main() { int a[2][2][2] = { {10. int integer=2. q++.2.. int *i=&integer.592 int a[10].%p. #include<stdio. p++. printf("%d".*a+1-*a+3). # include <stdio.%p".*ptr).q.h> int one_d[]={1.2. } Ans : 2 21. printf("%d".3. main() { int *ptr.7. long *r. ptr+=3. printf("%d". void main() { void *v. } Ans : 1 2 4 23.6.p. ptr=one_d. v=i. main() { char *p. printf("%p. } //if ptr+=2 then 3 will printed Ans: garbage 22.. int *q. r++.. } Ans: 4 Gud1 20.

*p. void *vptr. main() { int *j. { int i=10. j=&i.*j). for(i=0.c.x). ++i) { printf(“%s\n”.c. main() { int i. i<n. } Ans: error 26.. } printf("%d". n = strlen(x). v=0. cptr=&c. } } Ans: irl rl l .*q. n. vptr=&v.v. main() { char *cptr. } Ans: 10 25. } Ans: 10 garbage 24. char *x = “girl”.593 int *p. p=&a[2][2][2]. printf("%c%v". c=10. *x = x[n].*q).%d". *q=***a. x++. printf("%d.v).

j++) printf(“%c” . for (j=0.4}. printf(“%s”. ptr-p.in/Main .co. main( ) { void *vp.//g vp = &j.a+4}. int **ptr = p. **++p. j++) printf(“%s” .(char *)vp + 3). . s+1.//fy }http://www. s+2.a+1.a+2. ptr++. main( ) { static int a[ ] = {0. *cp = “goofy”.(q+j)).3.1. int j.*(int *)vp). **ptr). *ptr-a. *(char *)vp).*--*++p + 3). char ch = ‘g’. “violet”}. main ( ) { static char *s[ ] = {“black”.2.Home?rl=t Ans: g 20 fy 29.a+3. } Ans: Error (Null pointer assignment) 30. j++) scanf(“%s” . int *p[ ] = {a. printf(“%c”. for (j=0.594 27. printf(“%d”. *ptr++. for (j=0. char **ptr[ ] = {s+3.//20 vp = cp. } Ans::ck 28. int j = 20. ***p. “white”. printf(“\n %d %d %d”.orkut. “yellow”. vp = &ch.(q+j)). j<3. p = ptr. s}. j<3. j<3. printf(“%s”.*(q+j)). main( ) { char *q.

595 printf(“\n %d %d %d”.7. p++.{{2. **ptr). *++ptr. . ++*ptr. printf("%d----%d". for(j=0.*p.***a). ptr-p. printf(“%u %u %u %d \n”.3}. j<5.50}.{2. printf(“\n %d %d %d”. int *p.4}. main( ) { int a[ ] = {10.a+1.{3.***a+1).3. p=&a[2][2][2]. ptr-p.j.*a).**a.8}. **ptr). *ptr-a.h> main() { int a[2][2][2] = { {10.a. *ptr-a.{7.*q.*q). for(j=0.30.*p. printf(“%u %u %u %d \n”.4}}.2}. main( ) { int a[2][3][2] = {{{2.4}. {5. **ptr). ptr-p. printf(“\n %d %d %d”. *ptr-a.8} }. a++. 31. *q=***a.*p).40. } } Ans: Error 32.4}}}.{3.*a. j++) { printf(“%d” .6.2.*a+1. #include<stdio. 1000 1000 1000 2 1012 1004 1002 3 33.**a+1. } p = a. j<5.20. } Ans: let base address be 1000. j++) { printf(“%d ” .

*p).++(*p)).*q=c.h> aaa() { printf("hi").j++){ printf(" %d ". int j.4. printf("%d". } main() { int (*ptr[3])().*p=c.7. } } Ans: 2 2 2 2 2 23465 35.5}. } bbb(){ printf("hello"). ptr[1]=bbb. void main() { int const * p=5. ptr[0]=aaa. for(j=0.j<5. } ccc(){ printf("bye"). ++q. ++p. } for(j=0.4.j++) { printf(" %d ".8. .3.596 } Ans: garbage garbage 34. } Ans: error SESSION 5 1.j<5. main() { int c[ ]={2.*c). # include<stdio.6.

} Ans: b c 4.a[1]='b'.a[2]='c'. fun(&j). { return( a= (a==b) ). } main() { int process(). 2. func(a. } . printf("%c".b. a[0]='a'. 3.6)). ptr[2]().597 ptr[2]=ccc. } void fun(int **k) { int a =0.*a).*a). abc(a). printf("%c". In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. printf("The value of process is %d !\n ". } abc(char a[]){ a++.b) int a. a++.process(func. /* add a stmt here*/ } Ans: *k=&a. void fun(int **).func().3. main(){ char a[100]. } Ans: bye. main(){ int * j.a[4]='d'.

int swap(int *a.*a=*a-*b.int *b) { *a=*a+*b.y). int val1.x.prod(x+2.val2.val1.y=4.y=20. 10.598 process(pf. printf("%d". Explain the statement: void ( * abc( int.b) a*b main() { int x=3. } Ans: 10 6. printf("x= %d y = %d\n". swap(&x.val2)). } main() { int x=10.val2) int (*pf) (). int foo(int *arr[]) and .&y). Is there any difference between the two declarations.y-1)). } Ans: 20 10 8. Declare an array of N pointers to functions returning pointers to functions returning pointers to characters? 11. void ( *def) () ) ) ().*b=*a-*b. } Ans: error 5. { return((*pf) (val1. #define prod(a.

printf(”%c”.a[4]=’d'. printf(”%c”. 13. a++. } int main() { puts(someFun()). return temp. a[1]]=’b'. } Ans: -10 14. a[0]=’a'. main() { char a[100].*a). printf(”%d\n”. main() { int i=_l_abc(10). } abc(char a[]) { a++.a[2]=’c'. } Ans: string constant. char *someFun() { char *temp = “string constant".–i). abc(a). } 15. } int _l_abc(int i) { return(i++). .*a).599 int foo(int *arr[2]) 12. void main() { static int i=5.

50. char i. The value of EOF is -1.SEEK_SET). while((i=fgetch(ptr))!=EOF) printf("%c". #include<stdio. b: fseek(ptr. 4. *cptr. } } Ans:Infinite Loop No Output SESSION 6 1. cptr = (int*)calloc(sizeof(int).fgetch() no such built in function. what will be the position of the file marker? a: fseek(ptr. void main() { int *mptr. .SEEK_CUR).i).0. Ans : while((fgets(receiving array.*cptr). printf(“%d”.1).c". ptr=fopen("zzz.i). } Ans: garbage 0 5.50. Ans: 0 offset 2. } Ans: linker error. 3.600 if(–i) { main().*mptr).h> main() { FILE *ptr."r").file_ptr))!=NULL). mptr = (int*)malloc(sizeof(int)). printf(“%d”. printf(”%d “. What is the problem with the following code segment? while ((fgets(receiving array.0.file_ptr)) != EOF) .

printf("%d". struct xx *s. The variable that contains address of another variable is called as 8. printf("%s". } Ans: error//declare a data type of structure then add sud be given to struct pointer *2. #include<stdio.601 6. Using pointers to call a function is called as function pointer 7. How many values can be returned by a C++ function? Ans: one 9. Pointer SESSION 7 1.s->x). }.h> main() { struct xx { . #include<stdio. char name[]="hello". The variables that can be used only within the function in which it is declared is called as Local variable. Which of the following is mandatory for all C++ program? a) main() b) scanf() c) system() d) all the above Ans : main() 10.s->name).h> main() { struct xx { int x=3.

ghi.%d".ghi. struct yy { char s.ghi.. abc.next=&abc. def.BLUE. struct aaa *next. enum colors {BLACK. int x=100. ghi.%d.prev=&def. x=abc.prev=&ghi.prev=&jkl.BLACK.def.. jkl.def. struct xx *p.BLUE. } Ans: 0 1 2 6.602 int x. }.jkl.i=1.next=&def. main() { struct aaa abc.next=&jkl. struct aaa{ struct aaa *prev.i=3.prev=&abc. }. int i. } Ans: Error 3. struct yy *q.jkl.jkl.next->next->prev->next->i.abc.GREEN). return(1). abc.i=2. .GREEN} main() { printf("%d. def.i=0.next=&ghi. }.

error. exception.error). What is the output for the program given below typedef enum errorType{warning.y).(*pp).603 printf("%d".}error.g1).x. } Ans: Error (multiple declaration of error). int y. } Ans : error 10. g1=1. } Ans : 2 *7.*pp. printf("origin is(%d%d)\n". }. main() { struct student { char name[30].g1. exception. .pp->y). struct point { int x. printf("%d". error. main() { pp=&origin.pp->x. struct point origin.x). typedef struct error{int warning.(*pp).error =1. printf("origin is (%d%d)\n". main() { error g1.}error. main() { error g1. } Ans: 0 0 00 8. g1. 9. printf("%d".

sizeof(stud). }. struct student { char name[30].month.rollno. &student. scanf("%s%d%d%d".month. main() { struct date. scanf("%s%d%d%d".dob. } Ans: error 12.day. &student. rollno[6].dob. } } &student. struct date { int day. &student.rollno. struct date { int day.604 struct date dob. There were 10 records stored in “somefile.month. struct date dob.dob. }.dob. puts(stud. } Ans: error 11. 1 . while(!feof(fp)) { fread(&stud. .dat” but the following program printed 11 names.dob. }stud.dob.year).year. What went wrong? void main() { struct student { char name[30]. fp).month. stud. stud.”r”).year).day. }stud.year. &student. FILE *fp = fopen(“somefile. &student.name). }stud.dat”.

aType *b. struct a *b. Ans: yes 17. aType someVariable. 16.605 Ans: last record will get printed twice when feof is used. . } Ans : no 14. } Ans: no// 15. Is the following code legal? struct a { int x. Is the following code legal? void main() { typedef struct a aType. Is the following code legal? typedef struct a { int x. 13. }. struct a b. struct a { int x. }aType Ans: syntax error. aType *b. Is the following code legal? struct a { int x. Is the following code legal? typedef struct a aType.

MON.55.2. ans::-1. main() { float f=5.bit. printf("\n %d %d %d".bit4). printf(”%lf\n”.j=20.k=50}. } Ans: no 18.VAL2.sizeof(var)). printf(”%lf\n”. 1) struct value { int bit1:1.TUE.fmod(f. 19.bit3.FRI.2 2) ans::2 3) enum days{MON=-1.g=10.bit.FRI. enum{i=10. printf(”%d\n”. int bit4:4.VAL4.VAL3.bit1.SAT). .0.g)). }. int bit3:4.f%g).606 struct a { int x.58 enum value{VAL1=0.SAT}.2. printf("%d %d %d %d %d %d". printf("%d". Printf can be implemented by using __________ list. } Ans:error.2}.THU.57.f<<2).56.WED.THU.VAL5}var.TUE. printf(”%f\n”. aType *b.WED=55. ans::-1.++k).bit. }bit={1.

v.b. printf("%d". } ans::2. }. stud3=fail.stud1. .607 4) void main() { union var { int a.sizeof(p). }. printf("%d %d".*q. struct byte var={1}. struct node *p. stud1=pass.sizeof(q)).fail. v. struct node *link. printf("\n %d %d %d". p=(struct node *)malloc(sizeof(struct node)). enum status stud1. q=(struct node *)malloc(sizeof(struct node)).stud2.one).b=100. union var v.a). v.stud3). ans::-1 7) enum status{pass. printf("%d".atkt}. }.2 6) struct byte { int one:1. } ans::100 5) void main() { struct node { int data.var.stud3.stud2.a=80. stud2=atkt.

i^j).u. } ans::103 Design 11) { void main() union test { int i.u."Thermal"}.{104.i). u.(*(c+2)). union x u. float f.i|j&j|i.ch[0]=3. printf("%d %d %d ". void main() { struct course c[]={ {102.ch[1]=2."Manufacturing"}.ch[0]. printf("%d %d %d ". }. printf("%d".courseno). char ch[2]. 10) struct course { int courseno.608 ans::0 1 2 8) int i=4. char coursename[25].ch[1]. .c[1]."Design"} }.{103. }. printf("%s". 9) { union x int i.u.j=8. u.i|j&&j|i.coursename).

a. int no. t->i=10. void main() { struct book b1={"Let us C".phone).city. t=(union test *)malloc(sizeof(union test)). }. char author[25]."kerala". }.a. }. printf("\n city=%s pin=%d". printf("\n name=%s phone=%s".e. struct emp { char name[25]. union test *t. } ans:: name=jeru phone=2344 city=kerala pin=55 13) { struct book char name[25].name. int pin.55}. printf("%c\n".t->i). struct emp e={"jeru".e.101}. } 12) { void main() struct address { char phone[15].e.609 char c. char city[25]."2344".e. t->c='a'.t->f).a.pin). struct address a. . }. printf("%d\n". t->f=10."YPK".10f. void display(struct book *). printf("%f\n".t->c).

"i love India").610 display(&b1).b->author.m2).b->name. s.b->no). m. } void display(struct book *b) { printf("\n %s %s %d". char m2[50].&m.m. int b:2. unsigned int c:3.s.c=5. struct sample s.b=1.a=-2.101 14) { void main() struct sample { int num."We are Indians"). char m1[50]. printf("\n %u %u %u". strcpy(m.m1.num. printf("\nThe value of a is %d". s. }. strcpy(m. printf("\nThe value of b is %d". s. }m. s.c).num=1.b=0.b).s. printf("\nThe value of c is %d".m2. .m.s. s.a).a=2. } ans::garbage value will be printed 16) { void main() struct sample { int a:3. } ans:: Let us C. s.m1.c=3.YPK.

s.no). } void passrecord(struct sample x) { x.c).s. printf("\n Name : %s".611 printf("\nThe value of a is %d".x.no=x. printf("\n Name : %s".s.a).name). printf("\nThe value of c is %d".b). void passrecord(struct sample).no+10.name). scanf("%s".no).sizeof(s)).s. int no. printf("\n Enter the Roll Number:"). printf("\n values after the function:\n"). printf("\n No : %s". void main() { struct sample s. passrecord(s). printf("\n Total size of the structure sample is %d".s.x.s.s. }. printf("\n No : %d". printf("\nThe value of b is %d". scanf("%d". } 18) Point out if there is any error in the program void main() { . printf("\n Inside the function:\n"). printf("\n Enter the name:").no).name). } 17) { struct sample char name[10].

Arrange the code below. a) free(temp) b) temp->prev->next=temp->next c) temp->next->prev=temp->prev. struct list { int data."Hacker"). struct list* left. float bs. struct list* right. strcpy(e.name.name. printf("\n %s %d". int age.age). . what are the steps required to insert a new node n at a point pointed by ptr? note: ptr is not the last node. }. } ans::error 1.e. age=25. a) b c a b) c b a c) a b c d) both a and b 4. to delete a node being pointer by temp. }.612 struct employee { char name[25]. struct employee e. can we have more than one data members in a doubly linked list structure a) b) yes no 3.e.

2.L. where head is startning node in D. n->left = ptr->left n->left->right = n ptr->left = n n->right = ptr b) 4 3 2 1 c) 4 2 1 3 d) 3 1 2 4 a)1 2 3 4 . What does function do. What does below code do.L of nine nodes. i++) { If(i==1) temp=head. else if (i%2==1) temp= temp->next. 4. free(temp). 3. if temp is pointing to a node other than first and last node temp -> prev ->next = temp ->next. } a) middle node b) last but one node c) cannot make out d) second node 6. head!=NULL.613 1. for( i=1. temp ->next -> prev = temp -> prev. if temp is pointing to a node in DLL and temp1 is a newnode? temp1 -> prev = temp temp1 -> next =temp ->next temp -> next->prev = temp1 temp -> next = temp1 a) inserts node before temp..head=head ->next. where does the pointer temp pointing after the code execution. b) inserts after temp c) deletes node pointed by temp. a) b) no effect inserts a node . 5. d) none of the above 7.

while (temp->next->next!=NULL) { Temp = temp ->next. free ( temp ). temp -> next -> prev = temp -> prev. if there are 100 nodes temp=head. a) b) c) d) deletes 3rd last node no effect 3rd node is deleted Middle node is deleted . what does the code below do. head -> prev = null. where head is starting node & temp is temporary pointer temp=head. free(temp). a) b) c) d) no effect NULL data is stored Starting node is deleted First and second node are shuffled 9. free(temp). } temp -> prev -> next = temp -> next. where head is pointing to first node & temp is a temporary pointer. head= head -> next. while ( temp -> next -> next -> next != NULL) { Temp = temp -> next. a) no effect b) deletes some node c) deletes 2nd last node d) deletes last node 10. what does the code do. temp -> next -> prev = temp -> prev. 10 be the number of nodes temp = head. What does the code below do.614 c) d) deletes a node shuffling of pointers 8. } temp -> prev -> next = temp -> next.

main() { printf("%c\n". char *p = y. p = p + 1. } a)ASCII value of '1' is required to find out the answer b)2 c)50 d)Syntax Error ans::b 2. printf("%d\n". main() { int y[2][2] = { {1. } a)i b)Program will have runtime error c)Unpredictable d)No visible output ans::d 3. printf("%c\n".*p).2}. int *p = &y[1].4} }. {3. } a)4 b)3 c)The program doesn't compile d)Output is unpredicatable ans::a . '1' + 1). p = p + 9.615 1.*p). main() { char y[10] = "abcdefghi".

616 4. main() { int x = 10. x). x = x + y. main() { unsigned int i = 5. x = x + y. int y = 20. x = x + y. if (x >= 30) { int y = 30. } } a)5 b)6 c)Infinite d)Program will not compile ans::c . int y = 10. } else { int y = 40. } a)40 b)50 c)60 d)70 ans::b 5. } printf("%d\n". while (--i >= 0) { printf("Hello World\n").

struct emp e. push(top. insert(root. insert(root.5). void main() { printf(“%d”. } a)24 b) No Output c) Compiler Error d) None Of the above ans::c 7.1). push(top. push(top.2). push(top. a)1 2 3 4 5 b) 1 2 5 4 3 c) 1 3 4 5 2 d) 2 1 3 4 5 8.20).10). preorder(root).617 6.5). } assume insert function inserts a node at its correct position in the tree. void main() { int x. insert(root.40). . }.sizeof(struct emp)). insert(root. char name[10]. what is the outpur of the following prog. void main() { insert(root.3). struct emp { int age. root is the root of the tree and preorder function prints the nodes as in preorder traversal.4).

(a) 10 (b) 5 (c) 1 (d) 25 9. 'C'. } consider push function pushes onto the stack the given value.append c.DCAB d. if the preorder traversal of a BST tree is 100 50 25 75 200 150 300 then the root of the tree is : ( a) 300 (b) 75 (c) 100 (d) 25 10. 4 D. printf(“%d”. x=pop(top). 6 C.add b. 9 . and then removed one at a time.insert d. There is a tree in the box at the top of this section.push 11.25).ABDC 14 / \ 2 /\ /\ 1 3 10 30 / / 7 40 \ 50 11 c.DCBA 12. push(top. in what order will they be removed? a. If the characters 'D'. The operation for adding an entry to a stack is traditionally called: a. and pop operation performs pop and returns the poped value. 'B'. 'A' are placed in a queue (in that order).ABCD b.1).618 push(top. How many leaves does it have? A. x). 5 B.

How many of the nodes have at least one sibling? E. Something between -5 and -15 . What is the value stored in the parent node of the node containing 30? J.There is a tree in the box at the top of this section. 6 18. 6 G. 2 T. 9 R. 0 P. 5 F. 9 17. There is a tree in the box at the top of this section. 8 W.There is a tree in the box at the top of this section. 40 N.There is a tree in the box at the top of this section. What is the depth of the tree? S. 7 H. How many children does the root have? X. 8 16. 14 M. None of the above 15. 11 L.*: a.619 13. 4 Z. 2 Q. 10 K. What is the value of the postfix expression 6 3 2 4 + . 8 I.There is a tree in the box at the top of this section. 3 U. 2 Y. How many descendants does the root have? O. 4 V. 9 14. Something between -15 and -100 b.

20. Something between 5 and -5 d. . Something between 15 and 100 19.(ii) and (iii) only (c) (i) and (iii) only (d) (i). (iv) Two elements are deleted from the queue. cursor = link. Something between 5 and 15 e. (ii) Two elements are deleted from the queue. What statement changes cursor so that it points to the next node? a. (v) 2 and 3 are added to the queue. cursor = cursor->link.620 c. .5. c. Suppose cursor points to a node in a linked list (using the node definition with member functions called data and link). 4 .(for notational convenience “ – “ used to denote an empty cell) The following operations have to be performed. What are the final front and rear values when the above operations are performed into a circular queue? (a) front = 7 rear=2 (b) front = 2 rear=0 (c) front = 5 rear=8 (d) front = 5 rear=0 21. (i) 6 is added to the queue. d. b.. Consider the following statements: (i) The queue can be implemented by a linked list.front = 1 rear= 3 Queue = -. -. (iv) The Queue can be implemented only by an array-based method. Consider the following queue which can be allocated eight integers and five operations. cursor++. (iii) There are references kept at both the front and the back of the list. (iii) 10 and 12 are added to the queue.(iii) and (iv) only (e) (ii) and (iv) only . Which of the above statement(s) is/are valid for the queues? (a) (i) only (b) (i).. cursor += link. (ii) The queue can be implemented only by stack.2 .

abc. } (a)Compile-Time Error (b)10 Ans::6 24. p=b.next=&jkl. Printf(“%d”. ghi.e.next=&def.*p.def.abc. printf("%d".jkl.b[]={1. main() { struct aaa abc.e).c=3.*p). int i.prev=&jkl.prev=&abc. 2 3 B.5}.ghi.i=2.ghi.next->next->prev->next->i. ghi. Printf(“%d”.jkl. x=abc. main(){ int i. jkl.jkl.i=3. struct aaa{ struct aaa *prev.d=4. e=(a. int x=100.b=2. def.c)+(c. struct aaa *next.i=1.i=0. 2 4 C. void main() { int a=1.3.a)+(b.*p).next=&abc.4. 2 5 Ans::2 3 23. 3 4 D.def. } (c)6 (d)2 . } A. printf("%d". }. abc. ++*p.def.d)-(d.next=&ghi.2.b).621 22. P+=2.prev=&ghi.x).prev=&def.

69 (a) 25 1 6 1 1 1 4 2 1 2 6 3 6 4 5 6 9 7 2 8 8 9 25 (b) 1 1 1 6 2 1 1 4 2 6 7 2 8 8 3 6 4 5 6 9 9 25 (c) 1 6 1 1 2 1 1 4 2 6 3 6 6 9 7 2 8 8 9 45 . 88. 11. 45. 26. 14. 36.622 25. 21. 16. What would be the output if we enter the following data set (in the respective order) into a standard program to construct a Binary search tree? 25. 9. 72.

b) (a<b?a:b) . #define min(a.623 (d) 1 6 1 1 21 2 5 7 2 1 4 3 6 2 6 4 5 6 9 8 8 9 2) which of the following data structure is used in hierarchical data modeling a) stacks b) queues c) trees d) structure ans: trees 3) a binary tree with 20 nodes have _____ null branches a) 20 b) 22 c) 21 d) 40 Ans: 21 4) in tree construction which of the following is suitable efficient data structure a) array b) doubly linked list c) stack d) queue e) none ans: doubly linked list 5) find output of the following code.

which finite set of elements that is either empty or is portioned into 3 disjoint subset. printf(“%d\n”. break.4+4).624 main() { int a.a). what type of Binary Tree is the following tree below compile time error hi helloo No output 7 8 Compile time error Garbage. Ans::a . single linked list b. switch(f) { default: puts(“hi”). stack d. double linked list c. case 2. a=min(3+4.0 : puts(“helloo”). } } a) b) c) d) Ans::a 2. a. binary tree Answer: D 3. } a) b) c) d) 6) main() { float f=2.

Which is the preorder of a Binary tree represented below A B C D E F G H J I K a. strictly binary tree complete binary tree almost complete binary tree not a binary tree Answer: D 4.625 A B C D E F G H I J K a. ABDHIECFJKG b. b. IHDEBKJFGCA . c. d.

c. b. B G Any node Both a and b are correct Answer B 6. AB*C*D*E*F*G/H+IJ^- . b. ^-+//*BC*DEGA+HI/J*KL ^+-//*BC*DEGA+HI*J/KL ^-+/*/BC*DEGA+HI*J/KL ^-+/*/BC*DEGA+HI*J/KL Answer: A 7. d. conver this expression in prefix form (A+B * C/D * E /G – H + I) ^ ( J /K * L) a.626 c. ABCDEFKJGHI Answer: A 5. postfix form of the following expression is A*B*C*D*E*F/G+H-I^J a. IHDBEAKJFCG d. If suppose root to be deleted then which node will be the root node A B G C E H I D K J a. d. -/*****ABCDEFGH+^IJ b. c.

While(tempvalue!=key) { temp1=temp.T almost complete B. Considering the following code in which ‘root’ is the root node in binary tree and ‘temp’ and ‘temp1’ are pointers and ‘key’ has only 1 leaf node left temp=root.T stricktly complete B. 2n-1 Answer: A 9.T a. strictly B.T completely B. c. tn = 2L+1 d. of node in complete B. d. which is formula to find the total no. tn=2d+1 – 1 where depth(d) !=level b. AB*CB*D*E*F/GH*IJ^ 8. BA*D*C*F*GH/+IJ^d. tn ==2d+1 – 1 where depth != level(L) c.627 c. what type of B.T is the following tree A B C D E H F G I a. b. If(tempvalue<key) .T Answer: A 10.

} else if(tempvalue>key) temp=templeft. c. d. b. } if(temp1value < key) temp1right=templeft. what is the output after execution of this code? a. else if(temp1value>key) temp1left=templeft. Deletes the key value node & make leaf node connected to its parent Deletes the leaf node of key node Deletes the key node None of the above Answer: A . free(temp).628 { temp=tempright.

629 .

Sign up to vote on this title
UsefulNot useful