FRP C & DS dumps

897
1) If you dont know the array size which one do you prefer? a) array b) linked list 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 ?????? 4) To print a single character in output, which function is used? a) getchar() b) gets() c) putchar() d) puts() ans::c 5) The effective way of sorting is done by _______________ a) single linked list 1

Transcript of FRP C & DS dumps

Page 1: FRP C & DS dumps

1) If you dont know the array size which one do you prefer?a) arrayb) linked list

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 ??????

4) To print a single character in output, which function is used?a) getchar()b) gets()c) putchar()d) puts()ans::c

5) The effective way of sorting is done by _______________a) single linked listb) arraysC)Doubly linked listd) Binary search treesans:: c or d??

6) void main(){struct emp{ int a;

1

Page 2: FRP C & DS dumps

struct emp b;};struct emp m;printf("%d",sizeof(m));}ans::error

7) #define t 10void main(){ printf("%d",t);}

a) 10b) Error:Unfined symbol 't'c) Error:Improper placement of preprocessord) none of the above

ans::a8) data structures used for stack

a) arrayb) linked listc) bothd) noneans::c

9) Explicit datatype conversion is calleda) Type castingb) conversionc) separationd) noneans::a

10) What is the size of char *a,int *b,float *q,if the size of the Double pointer is 2 bytes

a) 1 1 1b) 2 2 2c) 4 4 4 d) 1 2 4ans::b

11) The data structure used for searching isa) arrays

2

Page 3: FRP C & DS dumps

b) single linked listc) double linked listD) Binary search treesans::d

12) For what purpose queues are used?i) expression evaluationii) device queue for processes

a) i onlyb) ii onlyc) both i and iid) neither i nor iians::b

13) The data structure used for sorting without moving the data isa) arraysb) single linked listc) double linked listD) Binary search treesans::d

14) struct stack{

int a[10];int top;

};struct stack *s;

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;

3

Page 4: FRP C & DS dumps

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 simplyprintf("Equal");elseprintf("Unequal");

ans::error17) main()

{ int i,j;

for(i=0;i<2;i++) {

for(j=0;j<5;j++){if(i==j)

continue;printf("wipro");}

}}

18) which one is used to get a multiword string?a) getsb) printfc) puts

4

Page 5: FRP C & DS dumps

d) getcharans::a.

19) main(){

char *a="\12345\n";printf("%d",sizeof(a));

}ans::2(turbo c) and in VS and : 4

20) int fun(){

int k=10;return(&k);

}main(){

int *p;p=fun();printf("%d",*p);

}ans::10

21) i) char *str="welcome"; ii) char str[50]="welcome";for these 2 definitions will they give you the same output for the given statement?

printf("%c",str[3]);

Ans:Yes

22) void fun(){

return(a>100?100:200);}void main(){

printf("%d",fun(5));}ans::error

5

Page 6: FRP C & DS dumps

23) void disp(int a,int b){

return(a>b?a+b:a*b);}void main(){

printf("%d",,disp(5,6));}ans::error

24) void main() {

int i=0; while(i==0) { }

printf("%d",i); }ans:: no output//infinte loop

25) void main() {

int i=1; while(++i==1) {

} printf("%d",i);

}

ans::2

3) char s[]={'a','b','c','\0'};printf("%s",s);output::abc

4) int arr[3][3]={2,3,4, 5,6,7, 8,9,10};

6

Page 7: FRP C & DS dumps

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

6) which can be replaced by a switch block?a) do..whileb) forc) whiled) else ifans::d

7) which of these is not a operator in c?a) ~b) ^c) %d) ::ans: d::

8) which of these is not a valid character constanta) "A"b) '*'c) '+'d) 'h'ans::a

9) struct student{ int i; char c[10]; struct student *s;};struct student stud,*stu;stu=&stud;printf("%d ",sizeof(stud));ans::14

7

Page 8: FRP C & DS dumps

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

11) 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

12) 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

13) What is the order in which the preorder is evaluated?i) root nodeii) left nodeiii) right node

a) i,ii,iii b) ii,iii,ic) iii,ii,id) ii,i,iii

ans::a14) which operations are more effective in linked list than arrays?

i) insertionii) deletioniii) traversal

a) i,ii only

8

Page 9: FRP C & DS dumps

b) iii onlyc) all the aboved) i,iii only

ans::a15) what is the output of the following program?

void main(){ int i=12; int *q; q=&i; *q=*q-8;printf("%d",i);}ans::4

16) What is the use of precedence in C programs for operators?a) Precendence are used to replace the variables used in operationsb) precendence are used to allocate memory spacec) precendence are used to evaluate the expression firstd) None of the aboveans::c

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) trueb) false

ans::b

9

Page 10: FRP C & DS dumps

19) int i=1;switch(i*2){ case 1:

printf("case1");break;

case 2:printf("case 2");

default:printf("default");

break;}a) case1 case2 defaultb) case2c) case2 defaultd) compiler errorans::c

20) 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

21) struct a{ char *i; char *j;};struct b{ struct a x;

10

Page 11: FRP C & DS dumps

int i;}*y;printf("%d %d",sizeof(y),sizeof(*y));

ans::2 622) #define t printf

void main(){int i=10;t("%d",i);} ans::10

23) int a[3][4]={1,2,3,4, 5};printf("%d",a[0][4]);ans::5

24) which one is used to check the given string is palindrome or nota) Single Linked listb) doubly linked listc) ArraysD) none of the aboveans::c

25) #define HELLO haivoid main(){ printf("HELLO");}ans::HELLO

26) The formal arguments has a default value zeroa) trueb) falseans::b

27) void fun(){ ????? x++; printf("%d",x);}

11

Page 12: FRP C & DS dumps

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

28) if rear=-1,front=-1 then what will be my queue?a) Queue is emptyb) Queue is fullc) Queue has one elementD) Queue has max-1 element

ans::a29) void main()

{ int i; for(i=1;i<=5;i++)

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

}ans::6

30) If p=(int *) malloc(sizeof(int)*10),then which one is true?i) It allocates 20 bytes of memoryii) The value in the memory is allocated to zero

a) i onlyb)ii onlyc) both i and iid) neither i nor iians::a

31) If p=(int *) calloc(sizeof(int)*10),then which one is true?

12

Page 13: FRP C & DS dumps

i) It allocates 20 bytes of memoryii) The value in the memory is allocated to zero

a) i onlyb)ii onlyc) both i and iid) neither i nor iians::c

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++){

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?

13

Page 14: FRP C & DS dumps

a) It is the first nodeb) It is the last nodec) It is in the middled) none of these

ans::b

37) If 'a' is the integer which is not statically initialized then what is the value of 'a'?

a) zerob) garbagec) none of these

ans::b38) 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 ".". 39) Which of the following is considered as tokens in C?

a) Variablesb) Keywordsc) Constantsd) All the above

ans::d

40) C is a ____________________ languagea) Platform independent programmingb) Platform dependent programmingc) Object oriented programmingd) None of the aboveans::b

41) main()

14

Page 15: FRP C & DS dumps

{ int i=3; switch(i) {

default: printf("default");case 1: printf("case 1");case 2: printf("case 2");

break; }ans::default case1 case2

42) #define FIRST 1#define SECOND FIRST+FIRSTmain(){ printf("%d",SECOND * SECOND);}ans::3

43) int b[5];main(){ static int a[5]; int i;

for(i=0;i<5;i++)printf("%d %d",a[i],b[i]);

}output: o o o o o o o o o o

44) which is having the more precendenceA: * , b:+, c:==, d: -ans::a

45) main(){ char *x="girl"; int n,i; n=strlen(x); *x=x[n];//g will be replaced by \0 for(i=0;i<n;i++){ printf("%s \n",x);// x++;

15

Page 16: FRP C & DS dumps

}}

ans:: irlrll

46) int sample(int x){ int *y; y=&x; x=*y+2; return(x);}void main(){ int x=5; printf("%d",sample(x));}

ans::7

47) void main(){ int *j,*k; int a=5,b=8; j=&a; k=&b; j=j*2; k=j/2; printf("%d %d",*j,*k);}ans::error//mul n div cannot be done on pointers

48) To make a pointer 'cursor'as a tail node,which line is correcta) cursor->right==NULLb) cursor->left==NULLc) cursor==NULLd) cursor->left==0

ans::a

16

Page 17: FRP C & DS dumps

49) Single linked list has a lnk to the next addressa) trueb) false

ans::a

50) int 5[x]={1,2,3,4,5};printf("%d",2[x]);ans::error//declaration terminated incorrectly

51) int arr[]={1,2,3,4,5};printf("%d %d",arr,&arr);garbage garbage//same both array statrting address

52) int a[3][4]={1,2,3,4, 5,6,7,8 ,9,0};printf("%d %d",a,a[2][1]);ans::garbage(%u sud be used) 0

53) The argc,argv are initialised ina) header fileb) within mainc) outside maind) none

ans::a

54) Queue isi) First in first outii) used in expression evaluation.

a) i onlyb) ii onlyc) both i and iid) neither i nor iians::a

55) which is correct?a) Auto variables are local variablesb) Extern variables are global variablesc) static variables are global variablesd) registers are local variablesans::b

17

Page 18: FRP C & DS dumps

56) main(){ int i=5; int *p; p=&5; printf("%d %d",i,*p);}

ans:: error//must take an adress of a variable

57) int foo(int a,float b){ float c; c=(float)a+b;printf("%c",c);}main(){ ????? foo(8,12.5);}which line is replaced for ?????? to get the ouput of 20.5ans::nothing //not reqd %f sud be used tats it

58) main(){ float v; v=10/4.0; printf("%f",v);}

ans::2.5000000

59) In a doubly linked list, 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

18

Page 19: FRP C & DS dumps

60) void main(){ int i=12,j,*p;

p=&i; j=++*p+8; printf("%d",j);}ans::21

1) int a=123.12; int b=-123.12; int c=a+b; printf("%2f",c);

a) 0.00 b) 123.12 c) 246.24 d) None of theseans:: none of these abnormal floating point

2. struct emp { int a; char *name; }; main() { struct emp *e; printf("%d",sizeof(e)); }ans::23. 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

19

Page 20: FRP C & DS dumps

ans::b

4. consider the character array of size 10.When a string is more than 10 a) Error b) Overwrites c) Nothing d) garbage value

ans::error/too many intializersans::a5. main() { char *str; char *fun(); str=fun(); printf("%s",str); } char * fun() { char *buffer; strcpy(buffer,"Hello world"); return buffer; } ans::runtime error //as buffer is lost when it goes out of a function better to use static char *buffer

or malloc to allocate memory for buffer. a) hello world b) Compiler error c) Runtime error d) None of the aboveans::c6. main() { char *str; char *fun(); str=fun(); printf("%s",str); }

20

Page 21: FRP C & DS dumps

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::a7) what is the prefix expression for the given Infix expression A+B*C/D

ans::+a/*bcd8) int a; a=65535; printf("%d",a); a) 0 b) Garbage c) 65535 d) -32768 output::garbageans::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));9) main() { char p=65; printf("%c",p); }

a) 65 b) p c) error d) none of the aboveans::none of the above//aoutput capital "A"

10) In a function call, _____________ is passed as arguments. a) variables

21

Page 22: FRP C & DS dumps

b) constants c) Expressions d) All the above

all the above11) The value of EOF is 26__-1_______.

ascII=2612) () is used for __________ a) function body b) Arguments c) Return type d) Declaration of function

ans::b

13) How does the string ends?

a) /nb) /tc) /0d) noneans::none...\\it terminated by'\0'not/0 ok

14) The range of Unsigned integer is

a) 127 to -128b) 0 to 65535c) Depend up on the compilerd) -32768 to 32767ans::c

15) which one of the following is a illegal real constants

a) 32.535b) -1.5E25 to 3.5E65c) "53682"d) -6.583ans::"53682"

16) main() { int i,a[5]; a[1]=5; for(i=0;i<5;i++)

22

Page 23: FRP C & DS dumps

{ printf("%d",a[i]);

a++; // Error}

a) 0 0 0 0 0b) Garbage valuec) 0 5 0 0 0d) Compiler errorans::d

17) The size of int is 2 bytes,then what is the size of short int?a) 1b) 2c) 4d) 8ans::b

18) In a queue,what condition applies

a) First In First Outb) Last in first outc) Elements are inserted and deleted at one endd) Elements can be inserted and deleted in different ends

ans::a19) 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) onlyb)ii) onlyc) Both i and iid) neither i nor ii

ans::c20) main() { char str[]="Wipro Infotech";

char *s; s=&str[13]-13; while(*s)

23

Page 24: FRP C & DS dumps

printf("%c",*s++); }ans:: wipro infotech

21) char *a="Malayalam"; char *s; Char *str; str=a; s=str+8; for(;s>=str;s--) printf("%c",*s);

a) Malayalam b) malayalaM c) error d) None of the aboveans::b22) struct main { int a; int b; struct main *e1; }; printf("%d %d",sizeof(e1),sizeof(*e1));

ans::2 623) #define wipro Hai void main() { printf("wipro");

}ans::wipro

24) Is allocating a block of memory effectively the same as defining an array? a) True b) false

ans::false

24

Page 25: FRP C & DS dumps

25) the size of a node of a doubly linked list is always greater than the single linked list a) True b) false

ans::true26) 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 & iid) neither i nor ii

ans::b27) what should be replace ????? in the program to get the output 25?

?????void main(){

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)ans::b

28) void fun(){ static char p[]="Hello"; return p;}

main(){ printf("%s",fun());}

what will be the output?

25

Page 26: FRP C & DS dumps

a) Compiler Error b) Hello c) Garbage value d) Noneans::a

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::garbageif calloc is used o/p is 00000

30) main(){ int i,j; for(i=1,j=10;i<j;i++,j--); printf("%d %d",i,j);}ans::1 10,2 9,3 8,4 7,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); ans::b

32) which is not a valid expressiona) x!=y b) x! c) !x d) x!y

ans::x! and x!y33) If max=104,rear=max,front=0,then what will be my queue?

a) Queue Emptyb) Queue Fullc) Queue has one element

d) Queue has max-1 elements

26

Page 27: FRP C & DS dumps

ans::c or b??34) which is an indefinite loop?

a) do while(0);b) for(;0;);c) while(1);d) while(0);ans::c

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 onlyb) ii onlyc) both i and iid) neither i nor ii

ans::c36) 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 onlyb) ii onlyc) both i and iid) neither i nor ii

ans::b37) Struct queue

{ int rear;

int front; int a[100];

} struct queue *q; then how will you add a new element called 'item' in the queue?

27

Page 28: FRP C & DS dumps

a) q->rear[a]=item; b) q->a[q->rear]=item;c) q->a[rear]=item;d) q->rear[q->a]=item;ans::b

38) In which of the following we can sort the data without moving the data

a) Arrayb) Single Linked listc) Doubly linked listd) Binary search treesans::d

39) Char d=128; printf("%c",d);

a)128b)-128c)errord)Garbage valuesans::d

40) In the following definition

struct node *ptr;ptr=(struct node *)calloc(sizeof(ptr));

a) ptr is allocated 4 bytesb) ptr will be allocated sizeof struct nodec) Errord) ptr will have 8 bytesans::a

41) In a doubly linked list ,if the first node is first and the last node is end,what will be the output?

traverse(struct node*end){

while(end!=NULL)

28

Page 29: FRP C & DS dumps

traverse(end->prev); printf("%d",end->data);

}

if the input is 1,2,3,4,5 then the output will be

a) 1,2,3,4,5b) 5,4,3,2,1c) compilation errord) noneans::b

42) void main(){

int b=20;printf("%d"*&b++);

}what will be the output?

a) 21 b)20 c) error d) Garbage valueans::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==NULLb)cursor->link=NULLc)Cursor->link=0d)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->leftc) Cursor++d) cursor->left++ans::b

29

Page 30: FRP C & DS dumps

1)Consider the following structure struct node { int info; struct node *link; }; Suppose ptr is a pointer which is not pointing to the first orthe last node.Then if we are going to delete a node after ptr,then the code will be

a) ptr=ptr->link;b) ptr->link=ptr;c) ptr->link=ptr->link->link;d) ptr=ptr->link->link;ans::c

2) Consider the following structure struct node { int info; struct node *link; };

Suppose start is a pointer pointing to the first node of the linked list.s1 and ptr are the two pointers(they are not pointing to the first or last node).Then if we are going to execute the following code,

i) start->link=s1;ii) s1->link=ptr;iii) ptr->link=start;

then the list is

a) It is having only 3 nodes with start,s1,ptr in the list,having start as the first nodeb) It is a circular linked listc) It is a doubly linked listd) None of the aboveans::b

30

Page 31: FRP C & DS dumps

3) In a queue, if rear=front then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) none of the aboveans::c

4) In a queue,if rear=0,front=0 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) none of the aboveans::c

5) 4) In a queue,if rear=0,front=1 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) Queue is circular ans::d

6) In a queue,if rear=-1,front=-1 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) none of the aboveans::a 7) In a queue,if rear=max-1,front=0 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) none of the aboveans::b

8) The postfix expression is ab+c*d/e-.The values of a,b,c,d,e are 2,4,5,2,1 respectively. Then the output is

a) 14 b) 11

31

Page 32: FRP C & DS dumps

c) 20 d) 15ans::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::c10) 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 ans::c

11) Conside the structure struct node

{ int info;

Struct node *left; struct node *right;

}; We have 10 elements in the list.If the following executes what will be the output?

for(ptr=start;ptr;ptr=ptr->right){ if(ptr->data%2==0) printf("%d",ptr->data);}

a) Only even numbers are printedb) Only odd numbers are printedc) Compiler errord) Only garbage valuesans::c /well if ptr is defined then even no are printed

12) Struct node

32

Page 33: FRP C & DS dumps

{ int data; struct node *left,*right;};

Suppose nd is a node which is not in the beginning and also not in the end.How will you delete a node after nd?

a) nd->right=nd->right->left;nd->right->left=nd->left->right;b) nd->right=nd->right->right;nd->right->left=nd;c) nd->right=nd->right->left;nd->right->left=nd->right;d) nd->right=nd->left->right;nd->left->right=nd;ans::b

13) Struct node{ int data; struct node *left,*right;};

Suppose nd 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;nd->right->left=nd->left->right;b) nd->left=nd->right->right;nd->left->right=nd->right;c) nd->left=nd->left->left;nd->left->right=nd;d) nd->left=nd->left->right;nd->left->right=nd;ans::c

14) Struct node{ int data; struct node *left,*right;};

Suppose ptr is a node which is not in the beginning and also not in the end.How will you delete a node ptr?

33

Page 34: FRP C & DS dumps

a) ptr->left->right=ptr->right;ptr->right->left=ptr->left;free(ptr);b) ptr->left->right=ptr->right->right;ptr->left->right=ptr->right;free(ptr);c) ptr->left->right=ptr->left->left;ptr->left->right=ptr;free(ptr);d) ptr->left->right=ptr->left;ptr->left->right=ptr->left;free(ptr);ans::a

15) Struct node{ int data; struct node *left,*right;};

Suppose ptr is a node which is not in the beginning and also not in the end. nd is the new node.Here is the coding: i) nd->right->left=nd; ii) nd->left=ptr; iii) nd->left->right=nd; iv) nd->right=ptr->right;

Then what sequence does it follows for inserting nd after ptr?

a) i,ii,iii,ivb) ii,iv,i,iiic)iv,iii,ii,id) ii,iii,i,ivans::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) /

34

Page 35: FRP C & DS dumps

ans::a

17) Consider a binary search tree insert(10,root); insert(25,root); insert(5,root); insert(8,root); insert(13,root); insert(45,root); insert(70,root); insert(32,root); delete(13,root); insert(66,root); insert(13,root); insert(36,root);

What will be the preorder traversal is

a) 5,8,10,13,25,32,36,45,66,70b) 10,5,8,25,13,45,32,36,70,66c) 10,8,5,13,32,45,36,66,32,70d) 8,5,32,36,10,66,45,70,25,13 ans::b

18) The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is

a) 3,5,7,14,17,22,55 b) 14,55,5,7,22,17,3c) 3,5,14,7,22,17,55d) 55,22,17,14,7,5,3ans::a

19) The preorder traversal is 5,3,66,30,77,70 .What will be the root nodea) 5b) 66

35

Page 36: FRP C & DS dumps

c)70d)30ans::520) 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 ib) only iic) both i and iid) neither i nor ii

ans::a

1. What is the output of the following:unsigned i=32768;void main(){

printf("%d",i);}

a. 32768 b. -32768 c. Error d. None of the aboveAns::b

2. int i;void main(){

static int i=3;printf("%d",i);

}

a. 3b. Multiple declaration (since I is static)c. 0d. None of the above

Ans::3

36

Page 37: FRP C & DS dumps

3. What is the output of the following:main(){

void change(char *);char *t="test";change(t);printf("%s",t);

}void change(char *t){

char *ab="new test";*t=*ab;

}a. new test b. test c. nest d. None of the above

4. What would be printed:#include<stdio.h>int i=0;void main(){while(i){

switch(i){

case 3<2: printf("Hi"); break;case 3>2: printf("Hello"); break;default: printf("welcome");

}++i;

}}

a. Hi b. Welcome c. No output d. Error

Ans::c

37

Page 38: FRP C & DS dumps

# include<stdio.h>int get();void main(){int x=20;x=get();printf("%d ",x);}

int get(){return(60);}

a. 60 b. Garbage c. Error d. 20

5. 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);}

a. 10 20 b. 20 10 c. Error d. Garbage valueAns::a

7.main()

{char *p="hai friends",*p1;p1=p;while(*p!='\0')

38

Page 39: FRP C & DS dumps

++*++p;printf("%s %s",p,p1);

}

a. ibj!gsjfoet b. hbj!gsjfoet c. hbj!gsjfoet hbj!gsjfoet d. None

ans::d

8. main(){ char a[100]={“abcdef”}; a++; printf(“%s”,&a[1]); Ans : c}

a) bcdef b) abcdef c)compilation error d) none of the above

9. When fopen() fails to open a file it returns _______a. NULL b. -1 c. 1 d. None of the above

Ans : a

39

Page 40: FRP C & DS dumps

10. int i=5;fun( ){

printf("%d\n", i * 3);}main( ){

int i= 2;{int i = 3;printf(" %d", i);fun();}

}a. 3, 15 b. 3, 6 c. 3 d. 0 Ans : a

11. main(){static int i=3;printf("%d",i--);return i>0?main():0;}

a. 3 2 1 0 b. 3 2 1 c. 2 1 0 d. 2 1 Ans : b

12. P is a character pointer variable then, what will be the output of the following statement.printf("%d %d",sizeof(p),sizeof(*p));

a. 1 2 b. 2 1 c. 2 2 d. 1 1

13. void main(){char *s[]={"dharma","hewlet-packard","siemens","ibm"};char **p;p=s;printf("%s",++*p);printf("\n%s",*p++);printf("\n%s",++*p);}

40

Page 41: FRP C & DS dumps

a. dharma harma ewlet-packardb. harma hewlet-packard siemensc. harma harma hewlet-packardd. harma harma ewlet-packard

41

Page 42: FRP C & DS dumps

14. void main(){char *ptr="Ramco Systems"; (*ptr)++;printf("%s\n",ptr);ptr++; Ans : bprintf("%s",ptr);}

a. Samco Systems Samco Systems b. Samco Systems amco Systemsc. amco Systems amco Systems d. amco Systems mco Systems

15. #include <stdio.h>     main()     {         switch (5)        {             case 5: printf(" 5 ");             default: printf(" 10 ");             case 6: printf(" 6 ");         }     }

A. 5 B. 5 10 6 C. 5 10 D. 5 6 Ans : b

16. Which of the following is not a storage class in C?

A. Stack B. Register C. Extern D. Static Ans : a

17. Which of the following function does not return an integer value?

A. printf B. scanf C. strcpy D. strlen Ans : c

18. int i=5; int abc(int z) { return i/2; }

42

Page 43: FRP C & DS dumps

main() { int i=4; printf("%d",abc(i=i/4)); }

a) error b) 5 c) 2 d) 0 Ans : 2

19. What will be the output of the following program : int main()

{ int val=5; val=printf("C") + printf("Skills");

printf("%d",val); return(0); }

(a) 7 (b) C7 (c) Compile-Time Error (d) CSkills7 Ans : d

43

Page 44: FRP C & DS dumps

20. #include<stdio.h>main(){

struct xx{ int x=3; char name[]="hello"; };struct xx *s;

printf("%d",s->x);printf("%s",s->name);

}

a. 3 hello b. Compiler Error c. Run time error d. use dot (.) operator

21. int swap(int *a,int *b){ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

}

a. 20 10 b. 10 20 c. 20 20 d. 10 10 Ans : a

22. main(){

char *p = “ayqm”;char c;c = ++*p++;printf(“%c”,c);

}a) a b) b c) y d) z Ans : z

44

Page 45: FRP C & DS dumps

23. main(){

float i=1.5;switch(i){

case 1: printf("1");case 1.5: printf("2");default : printf("0");

}}

a. 0 b. 0 1 2 c. 1 2 0 d. Compiler Error e. 2 0

24. 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 Ans : d

25. The EOF is equivalent to a. -1 b. 1 c. 0 d. None of the above Ans :

a

26. In a queue, if rear=max-1, front=0 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) None of the above Ans : b

27. The postfix expression is ab-cd+*ef/-.The values of a, b, c, d, e,f are 4, 2, 5, 2, 6, 3 respectively. Then the output is

a) -6 b) 12 c) 20 d) None Ans : 12

28. In the stack, if top=0 then the stack isa) Stack is empty b) Stack is full c) Stack has only one element d) None

29. struct node {

45

Page 46: FRP C & DS dumps

int data; struct node *left,*right;};

nd is a node which is not in the beginning and also not in the end. How will you remove a node after nd from the list?

a) nd->right=nd->right->left;nd->right->left=nd->left->right;b) nd->right=nd->right->right;nd->right->left=nd;c) nd->right=nd->right->left;nd->right->left=nd->right;d) nd->right=nd->left->right;nd->left->right=nd;

30. 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. Consider the following structure struct node { int info; struct node *link; };

Suppose ptr is a pointer which is not pointing to the first also not to the last node. Then if you remove a node after ptr from the list, then the code will be

a) ptr=ptr->link;b) ptr->link=ptr;c) ptr->link=ptr->link->link;d) ptr=ptr->link->link;

46

Page 47: FRP C & DS dumps

32. What does below code do, if temp is pointing to a node other than first and last node

temp -> prev ->next = temp ->next;temp ->next -> prev = temp -> prev;free(temp);

a) no effect b) inserts a nodec) deletes a noded) shuffling of pointers

33. What is the Infix expression for - + A / * B C D / * E F G

a) A + B * C / D – E / F * G

b) A + B / C * D – E * F / G

c) A + B * C / D – E * F / G Ans : c

d) A - B * C / D + E * F / G

34. What is the postfix expression for A + B * C / D – E * F / Ga) ABC*D/+EFG*/-b) ABC*D/+EF*G/- Ans : bc) ABCD/*+EF*G/-d) None of these.

35. A binary tree with 15 nodes have _____ null branchesa) 15 b) 14 c) 16 d) 17

1. union u { Int a; Char ch[2]; }u1;U1.a=5;U1.ch[0]=4 ; u1.ch[1]=2; Printf(“%d”,a);}(a) 5 (b) 42 ( c) 1028 (d) 24

47

Page 48: FRP C & DS dumps

36. 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 is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? a. 1 b. 2 c. 3 d. 4

e. 5

39.Suppose that p is a pointer variable that contains the NULL pointer. What happens if your program tries to read or write *p?

a. A syntax error always occurs at compilation time. b. A run-time error always occurs when the program finishes. c. The results are unpredictable.

d. A run-time error always occurs when *p is evaluated

45. What kind of list is best to access the item at given position n?" a. Doubly-linked lists. b. Lists implemented with an array. Ans : b c. Singly-linked lists.

d. Doubly-linked or singly-linked lists are equally best

50. Which of the following applications may use a stack? a. A parentheses balancing program. b. Evolution of postfix expression. c. Syntax analyzer for a compiler.

d. All of the above.

#include<stdio.h> void main() { union a {

48

Page 49: FRP C & DS dumps

int i; char ch[2]; }; union a u; u.ch[0]= 3; u.ch[1]= 2; printf("%d %d %d",u.ch[0],u.ch[1],u.i); } a) 3 2 515 b)515 2 3 c) 3 2 5 d) none of these

Ans : a

main(){struct student {char name[30];struct date dob;}stud;struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);}

a) It scans perfectly with error b) scanf format is incorrect c) No Error d) compilation Error Ans : d

In printf(),the appearance of the output of the output can be affected by

1) field with 2) conversion character3) flag 4) all of the above

Any of the following programs in C has access to three standard files:

1) Standard input file, standard output file, standard error file

49

Page 50: FRP C & DS dumps

2) stdin,stdout, stderr3) keyboard,screen,screen4) all the above

Heap

1) is a region from where memory is allocated2) lies between you program and the stack3) is a finite area4) all of the above

Function definition void check(int i ,char*j) is1) call by value 2)call by reference3) both (1) and (2) 4)in valid function definition

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,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 variable4) all of the above

A fields width specifier in a printf() function

1) specifies the maximum value of a number2) controls the size of type used to print numbers3) controls the merging of the program listing4) specifies how many characters positions will be used for a number

50

Page 51: FRP C & DS dumps

The global variables by default belong to

1) the register type 2) the static type3) the auto type 4) the dynamic type

What will be the output of the following program :void main(){

unsigned x=0xf880,y=5,z; z=x<<y; printf("%#x %#x",z,x>>y-1);}

(a)1000 f87 (b)8800 0xf88 (c)1000 f88(d)0x1000 0xf88Ans. (d)

1) int num[26],temp;num[0]=100;num[25]=200;temp=num[25];num[25]=num[0];num[0]=temp;printf("\n%d %d",num[0],num[25]);

o/p: 200 100

2. int array[26],i;for(i=0;i<=25;i++){

array[i]='A'+i;printf("\n%d, %c", array[i],array[i]);

}o/p:65=A to 97-Z

3. int sub[50],i;for(i=0;i<=48;i++)

51

Page 52: FRP C & DS dumps

{sub[i]=i;printf("\n%d", sub[i]);

}

o/p:0-48

4. int a[5]={3,4,5,6,7};printf("%d",a);

o/p: address of a

5. int i,a[5]={3,4,5,6,7};for(i=0;i<5;i++)printf("\n%d",a+i);

o/p: a[i]=a+I *(a+i) denotes value adress’s of all int’s is printed

6. int i,a[5]={3,4,5,6,7};printf("\n%d",a[5]);

o/p: Runtime Error (Array Index Out Of Bound)

7. int i,a[5]={3,4,5,6,7};for(i=0;i<5;i++)printf("\n%d",a[++i]);

o/p: 4,6,adress value

8. int i,a[3];a[3]=8;printf("\n%d",a[3]);

o/p:8

9. int i,a[2][2]={1,2,3,4};for (i=0;i<2;i++)printf("%d",a[i][i]);

52

Page 53: FRP C & DS dumps

o/p: 1,4

10. int i,a[2][2]={1,2,3,4};for (i=0;i<2;i++)printf("%d",a[i]);

o/p: 8230 8234 ( adress’s of int’s)

11. int i,a[2][2]={1,2,3,4};for (i=0;i<2;i++)printf("%d , %d\n",a[i]+1);

o/p:8682,8999 8686,8999

12. int a[2][2]={1,2,3,4};printf("%d",a);

o/p: base address of a (1st element) 8686

13. char a[5][10]={"akshay","Parag","Chirag","Hemal","Hetal"};

printf("%s",a);

o/p: akshay

14. char a[5][10]={"akshay","Parag","Chirag","Hemal","Hetal"};

printf("%s",a+2);

o/p:chirag

15. char a[5][10]={"akshay",

53

Page 54: FRP C & DS dumps

"Parag","Chirag","Hemal","Hetal"};

printf("%s",a[+2]);

o/p:chirag

16. char a[5][10]={"akshay","Parag","Chirag","Hemal","Hetal"};

printf("%s",a[2]);

o/p:chirag

17. char a[5][10]={"akshay","Parag","Chirag","Hemal","Hetal"};

printf("%c",a[2][4]);

o/p: ‘a’

18. char a[5][10]={"akshay","Parag","Chirag","Hemal","Hetal"};

printf("%c",a[2][7]);

o/p: (some symbol)

19. char c[2]="A";printf("\n%c",c[0]);printf("\n%s",c);

54

Page 55: FRP C & DS dumps

o/p:A A

20. char s[]="Get organized ! learn C";printf("\n%s",&s[2]);printf("\n%s",s);printf("\n%s",&s);

o/p: t organized ! learn C Get organized ! learn C";

Get organized ! learn C";

21. char s[]="No two viruses work similarly";int i=0;while (s[i]!=0){

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

}

22. char str1[]={'H','e','l','l','o'}; //Add ‘\0’ to avoid garbage value

char str2[]="Hello";printf("\n%s", str1);printf("\n%s", str2);

o/p: Hello garbage values Hello

23. printf(5+"Good Morning"); o/p: Morning

24. printf("%c","abcdefgh"[4]); o/p:e

25. printf("\n%d%d%d",sizeof('3'),sizeof("3");sizeof(3)); o/p:1 2 2

1. #include<stdio.h>

55

Page 56: FRP C & DS dumps

void display();void main(){

printf("\n Only smarties use C?");display();

}

void display(){

printf("\n Brilliants too use C!");main();

}

o/p: error cannot call main() from the program

2. #include<stdio.h>void main(){

printf("\n Only smarties use C?");main();

}

o/p: error cannot call main() from the program

3. #include<stdio.h>

int check(int);void main(){

int i=45,c;c=check(i);printf("\n%d",c);

}

int check(int ch){

if(ch>=45)return (100);

elsereturn (10);

56

Page 57: FRP C & DS dumps

}

o/p:100

4. #include<stdio.h>int check(int);void main(){

int i=45,c;c=check(i *1000);printf("\n%d",c);

}

int check(int ch){

if(ch>=40000)return (ch/10);

elsereturn (10);

}

o/p:10

5. int x=10;void display();

void main(){

int x=20;printf("\n%d",x);display();

}

void display(){

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

57

Page 58: FRP C & DS dumps

o/p: 20,inside display 10

6. #include<stdio.h>

int i;void increment();void decrement();

void main(){

printf("\ni=%d",i);increment();increment();decrement();decrement();

}

void increment(){

i=i+1;printf("\non incrementing i=%d",i);

}

void decrement(){

i=i-1;printf("\non decrementing i=%d",i);

}o/p:1 2 1 0

7. void fun(int,int)void main(){

int i=5,j=2;fun(i,j);printf("\n%d%d",i,j);

58

Page 59: FRP C & DS dumps

}

void fun(int i,int j){

i=i*i;j=j*j;

}

o/p:5,2 (call by value ex:)

8. void fun(int *,int *);void main(){

int i=5,j=2;fun(&i,&j);printf("\n%d%d",i,j);

}

void fun(int *i,int *j){

*i=*i * *i;*j=*j * *j;

}

o/p: 25 4(call by reference)

9. void fun(int *x,int y){

int i=4,j=2;fun(&i,j);printf("\n%d%d",i,j);

}

void fun(int *i,int j){

*i=*i * *i;j=j*j;

}

59

Page 60: FRP C & DS dumps

10. void fun(void *);int i;void main(){ void *vptr; vptr =&i; fun (vptr);}void fun(void *p){

int **q;q=(int **)&p;printf("%d",**q);

}

o/p:0

30. float x=1.1;while(x==1.1){

printf("\n%f",x);x=x-0.1;

}

o/p: no output

31. int x=3,y=0,z;while (x>=0){

x--;y++;if(x==y)

continue;else

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

o/p: 2 1 1 2 0 3

60

Page 61: FRP C & DS dumps

-1 4

32. int x=4,y=0,z;while(x>=0){

if(x==y)break;

elseprintf("\n%d%d",x,y);

x--;y++;

}

o/p:4 0 3 1

33. int i=0;for(i=1;i<=5;printf("\n%d",i));

i++;

o/p: infinite 1’s

34. int i;for(;i;)printf("\n Here is some mail for you");

35. int i=1, j=1;for(;;){

if(i>5)break;

elsej+=i;

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

}

o/p:2 536. char suite=3;

61

Page 62: FRP C & DS dumps

switch(suite){case 1:

printf("\n Diamond");case 2:

printf("\n Spade");default:

printf("\n Heart");}

o/p:Heart

37. int c=3;switch(c){case '3':

printf("You never win the silver prize");break;

case 3:printf("You always lose the gold prize");break;

default:printf("Ofcourse provided you win a prize");

}

o/p: You always lose the gold prize

38. int i=3;switch(i){

case 0:printf("\nCustomers are dicey");

case 1+0:printf("\nMarkets are pricey");

case 4/2:printf("\nInvestors are moody");

case 8%5:printf("\nAtleast employees are good");

62

Page 63: FRP C & DS dumps

}

o/p: Atleast employees are good

39. int k; float j=2.0;

switch(k=j+1){case 3:

printf("\n Trapped");break;

default:printf("\n Caught");

}

o/p:Trapped

40.int ch='a'+'b';switch(ch){

case 'a':case 'b':

printf("\nYou entered b");case 'A':

printf("\na as in ashar");case 'b' + 'a':

printf("\n You entered a and b");}

o/p: You entered a and b

41. int i=1;switch(i-2){

case -1:printf("\nFeeding Fish");

case 0:

63

Page 64: FRP C & DS dumps

printf("\n Weeding grass");case 1:

printf("\n Mending roof");default :

printf("\n Just to survive");}

42. int x=25;printf("%d%d%d",x==25,x=50,x<78); o/p:0 50 1

43. int x=25;printf("%d%d%d",x==50,x=50,x<78); Ans : 0 50 1

44. int x=50;printf("%d%d%d",x<78,x=100,x==50); o/p:0 100 1

1. int b[]={10,20,30,40,50};int i;for(i=0;i<=4;i++)printf("\n%d",*(b+i));

o/p: 10,20,30,40,50

2. int b[]={0,20,0,40,5};int i,*k;k=b;for(i=0;i<=4;i++){

printf("\n%d",*k);k++;

}

o/p: 0,20,0,40,5

64

Page 65: FRP C & DS dumps

3. char s[]="No two viruses work similarly";int i=0;while (s[i]!=0){

printf("\n%c",*(s+i));printf("\n%c",*(i+s));i++;

}

4. char s[]="Churchgate:no church no gate";char t[25];char *ss,*tt;ss=s;while(*ss!='\0')

*ss++=*tt++;printf("\n%s",t);

o/p:error tt is used without being initialised

5. int arr[]={10,20,36,72,45,36};int *j,*k;

j=&arr[4];k=(arr +4);

if(j==k)printf("The two pointers point to the same location");

elseprintf("The two pointers do not point to the same location");

o/p: The two pointers point to the same location

6. #include<stdio.h>

void main(){

int s[2][2]={

65

Page 66: FRP C & DS dumps

{2,2},{3,3}

};

int i,j;

for(i=0;i<2;i++)for(j=0;j<2;j++)printf("%d\n",*(*(s+i)+j));

}

o/p:2 2 3 3

7. void main(){

float a=13.5;float *b,*c;b=&a;c=b;printf("\n%u %u %u",&a,b,c);printf("\n%f %f %f %f %f",a,*(&a),*&a,*b,*c);

}

8. int *p,a[3]={1,2,3};p=a;printf("%d",*p++);printf("%d",*a);printf("%d",*p);

o/p:1 1 2

9. int *p,a;a=20;p=&a;scanf("%d",p);printf("A= %d and *P = %d",a,*p);

66

Page 67: FRP C & DS dumps

o/p:20 20

10. int **q,*p,a,b=40;a=20;p=&a;q=&p;*q=&b;printf("A= %d and *P = %d and **Q = %d",a,*p,**q);

11. float *p;int a;a=30;p=&a;printf("A= %d and *P=%f",a,*p);

12. float *p;int a;a=30;p=&a;printf("Address of A= %u and Value of P=%u",&a,p);

13. float a;int *p;a=30.90;p=&a;printf("Address of A= %u and Value of P=%u",&a,p);

14. int a[]={10,20,30,40,50};int *p;p=a;printf("The value of *P is %d\n",*p);p++;printf("Now the value of *P is %d\n",*p);

15. int a[]={10,20,30,40,50};int *p;

67

Page 68: FRP C & DS dumps

p=a;printf("The value of a[0] is %d\n",*p);p++;*p=300;printf("Now the value of a[1] is %d\n",a[1]);

16. int a[]={10,20,30,40,50};int *p;p=a;p=p*2;printf("%d",*p);

17. void main(){

char *str;str="%d\n";printf(str,300);

}

18. void main(){

char *str;str="%d\n";str++;printf(str-1,300);

}

19. void main(){

char *str;str="%4s";printf(str,"K");

}

20. void main()

68

Page 69: FRP C & DS dumps

{int i,*j;i=3;j=&i;printf("%d",i**j*i+*j);

}

21. 1. #define disp printf

void main(){

disp("Hello World");}

2. #define newline "\n"

void main(){

printf("Hello newline World");}

3. #define pi 3.14

void main(){

float d=pi;printf("%f",d);

}

4. #define pi 3.14

void main(){

float pi=2.11;printf("%f",pi);

}

69

Page 70: FRP C & DS dumps

5. #define pi 3.14

void main(){

printf("%f",pi);scanf("%f",&pi);printf("%f",pi);

}

6. #define maxi(a,b) a>b?a:b

void main(){

float x,y;scanf("%f%f",&x,&y);

printf("%f",maxi(x,y));}

(1) which of the following lines gives/prints the output 20

void main(){

lint1: int i=20;line2: int *k,**j;line3: j=&i;line4: k=&j;line5: printf("\n%d",i);line6: printf("\n%d",**k);line7: printf("\n%d",***&k);

}

(1) only 5 (2)only 7(3) only 6 (4)all 5,6,7

ans:(4)

70

Page 71: FRP C & DS dumps

(2)

void main(){int x,y=6;x=y+NULL;printf("%d",x);}

o/p: 6

(3)

void main(){static int arr[12];printf("%d",sizeof(arr));}

o/p: 24

(4)

void main(){float a[]={1.2,3.4,5.7,12.3};int i;for(i=0;i<=5;++i)printf("%f ",a[i]);}

o/p: 1.200000 3.400000 5.700000 12.300000 0.000000 0.000000

71

Page 72: FRP C & DS dumps

(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",7["wipro infortech");}

(8)

#include<stdio.h>void main(){char *p="hello";char q[]={'h','e','l','l','o'};printf("%d %d",sizeof(*p),sizeof(*q));}

o/p: 1 1

(9)

#include<stdio.h>

72

Page 73: FRP C & DS dumps

void main(){int i=0;while(){ switch(i) {

case 3<2:printf("Hi");break;case 3>2:printf("Hello");break;default:printf("welcome");

} ++i;}}

o/p:error

(10)void main(){int i=0;while(i<3){switch(i){case 1:printf("case1");

case 2:printf("case2");break;

73

Page 74: FRP C & DS dumps

default:printf("Default");}++i;}}

o/p:default case1 case2 case2

(11)#include<stdio.h>void main(){char str1[]="Hello";char str2[]="Hello"if(str1==str2)printf("\nEqual");elseprintf("\nNot equal");

}

0/p: Error

(12)which one of the comment line statement is correct (1) /* hello world */(2) //hello world//(3) */ hello world */(4) /&hello world &/

Ans: (1)

74

Page 75: FRP C & DS dumps

(13)

The value of EOF is _____(1) NULL (2)0(3)-1 (4)1

Ans: (3)

(14)

#include<stdio.h>void main(){int i;for(i=2;i=0;i--){printf("%d",&i);}}

No output

(15)

struct addr{char city[5];char street[5];};struct emp{char name[20];int empno;struct addr *a;};

75

Page 76: FRP C & DS dumps

struct emp *pemp;

How will you access city from the *pemp;ans: pemp->a->city

(16)

If you want to allocate 2 blocks of memory for a set of 5 integers,which will you use?

(a) malloc (b)calloc(c)neither (a)&(b) (d)either (a)&(b)

Ans:(d)

(17)

#include<stdio.h>

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

0/p: 50

(18)

#include<stdio.h>#define HELLO hivoid main()

76

Page 77: FRP C & DS dumps

{printf("HELLO");}

o/p: HELLO

(19)Convert to prefix

(a+b)*(c/d)

ans: *+ab/cd

(20)

#include<stdio.h>

struct person{char *name;char *age;char *c;};struct emp{int a;struct person *addr;};

void main(){struct emp *e1;printf("%d",sizeof(e1));

}

77

Page 78: FRP C & DS dumps

o/p: 4

(21)

#include<stdio.h>void main(){int i;i=10/4;printf("%d",i);

}

o/p: 2

(22)

#include<stdio.h>void main(){float i;i=10/4;printf("%f",i);

}

o/p: 2.000000

(23)

To arrange nodes in ascending order ________ is used

1)inorder 2)preorder 3)postorder 4)all the above

78

Page 79: FRP C & DS dumps

ans: inorder

(24)

int i=6,*j;line1: j=&i;line2: j=&35;line&: j=&(i+25);

Which of the above lines are correct?

Ans: line1

(25)

#include<stdio.h>void main(){int i=10;printf("%d",i==10);}

o/p: 1

(26)#include<stdio.h>int get();void main(){int x=20;

79

Page 80: FRP C & DS dumps

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

int get(){return(60);}

o/p: 60

(27)

#include<stdio.h>void main(){int a[3][4]={1,2,3,4,5,6,7,8,9};printf("%d ",a[2][1]);}

o/p: 0

(28)

#include<stdio.h>void main(){static int a[100];int i;for(i=0;i<4;i++)printf("%d",a[i]);}

80

Page 81: FRP C & DS dumps

o/p: 0 0 0 0

(29)

which is better memory allocation when size is not known

1)static 2)dynamic 3)both 4)neither

ans: dynamic

(30)

struct city{char name[10];char address[0];};

struct details{struct city c;};struct details *d;

How will u access address(member)

1)d->c.address 2)d.c.address 3)d.c->adddress

Ans:d->c.address

(31)

#include<stdio.h>void main()

81

Page 82: FRP C & DS dumps

{

int array[]={10,20,30,40,50},*p;p=&array[0] + 4; //p=array+4for(;p>=array;p--)printf("%d ",*p);

}

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 treewhich is correct

1) a alone 2)b alone 3)neither (a) nor (b)

(33)

Linked list is better than array because of1) insertion 2)deletion 3)traversal

a) (1) & (2) b) (2) & (3)

(34)

In the doubly linked list ,to add a new element in the tail node

(35)

#include<stdio.h>

82

Page 83: FRP C & DS dumps

#define wipro mainvoid wipro(){

printf("main");

}

o/p: main

(36)

#include<stdio.h>#define output(int) printf("%d ",int)void main(){int a=2,b=3;output(a);output(b);}

o/p: 2 3

(37)

#include<stdio.h>#define wipro printfvoid main(){

wipro("welcome");

}

o/p: welcome

83

Page 84: FRP C & DS dumps

(38)

Which one of the following statement is false for binary search tree1) root is less than left and right subtree2)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.h>aaa(){printf("hi");}bbb(){printf("hello");}ccc(){printf("bye");}void main(){int (*ptr[3])();ptr[0]=aaa;ptr[1]=bbb;ptr[2]=ccc;ptr[1]();}

o/p: hello

84

Page 85: FRP C & DS dumps

(40)a=15,b=3,c=5,d=3

a*b+c-devaluate the expression

Ans:47

(41)

#include<stdio.h>

void main(){int i,j;for(i=0;i<2;i++){for(j=0;j<5;j++){if(i==j)break;printf("wipro");}}}

How many times wipro will be printed

o/p: 1 time

42)

#include<stdio.h>void main(){

85

Page 86: FRP C & DS dumps

int a=10,b=10;a+=1;printf((a>b)?"hi":"hello");}

o/p: hi

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.h>void main(){static int a[5];int i;for(i=0;i<5;++i)printf("%d ",a[i]);}

o/p: 0 0 0 0 0

46)For allocating 2 blocks of 5 elements of integer type,what we will use?

1)malloc( ) or calloc( ) 2)only malloc

86

Page 87: FRP C & DS dumps

3)calloc( ) 4)neither malloc( ) nor calloc( )

Ans: (1)

47)

#include<stdio.h>struct emp{int i;char name[15];};

void main(){struct emp e1={1,"hi"},*e2;e2=&e1;if(e1==e2)printf("\nstructures are equal");elseprintf("\nstructures are not equal");}

Ans:

error

48)The arguments in a function call are known as

a) Actual parameters b)Formal parameters

49)#include<stdio.h>

87

Page 88: FRP C & DS dumps

void main(){char *fun();char *s;s=fun();printf("%s",s);}

char *fun(){return("Hello");}

o/p:Hello

50)The range of unsigned integers is _________

51)

prefix to infixpostfix to infix

52)Which is initialized as zero

1)global variable 2)static variable3)register variable 4)extern variable

a)(1) and (2) b) (1) and (3)

c) (1),(2)and (3) d) (1),(2),(3) and (4)

Ans: a

88

Page 89: FRP C & DS dumps

53)which statement used to read from file

1)fgets 2)fread 3)fscanf 4)sscanf

54)#include<stdio.h>fun1(){int a=5;static int b=5;a++;b++;printf("%d ",a);printf("%d\n",b);}void main(){fun1();fun1();}

o/p:

6 66 7

55)In what aspect linked list is efficient than array

1)Insertion 2)deletion 3)Traversal

a)1 and 2 b)3 only c)2 and 3 only

Ans:(a)

89

Page 90: FRP C & DS dumps

56)

#include<stdio.h>

void main(){int i;for(i=16/3;i<5;i++)printf("%d",i);}

o/p:

no output

57)

#include<stdio.h>void main(){int a;a=9/4.5;printf("%d",a);}

Ans: 2

58)

#include<stdio.h>#define TRUE 1#define FALSE 0void main(){if(TRUE)printf("True");else

90

Page 91: FRP C & DS dumps

printf("False");}

o/p:True

59)

#include<stdio.h>void main(){char str1[]="Hello";char str2[]="Hello";if(str1==str2)printf("True");elseprintf("False");}

o/p:false

60)

Which of the following is correcta) To read a character by character in files getc is used.b) To read a character by character in files fgetc is used.c) To read a line by line in a file gets is used.d) To read a line by line in a file fgets is used.

Ans:(a),(b) and (d)

61)#include<stdio.h>itn one_d[]={1,2,3};void main(){

91

Page 92: FRP C & DS dumps

int *ptr;ptr=one_d;ptr+=3;printf("%d",*ptr);}/*#include<stdio.h>

void main(){

int array[] = {10,20,30,40,50};int *p;

p = &array+4;

for (;p>=array; p--){

printf ("%d \n", *p);}

}*///______________________________________________________________________________

/*#include<stdio.h>

struct city{

char name[10];char *address;

};

struct details{

struct city c;};

void main(){

struct details *d1;

92

Page 93: FRP C & DS dumps

scanf("%s",d1->c.address);}*/

//______________________________________________________________________________

/* 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, to add a new element in the tail node1. nd->next = NULL:2. nd-> prev->next = tail;3 nd - > prev = tail;

which order is correct1 2 33 2 13 1 2 */

//______________________________________________________________________________

/*#include<stdio.h>

93

Page 94: FRP C & DS dumps

void main(){int c[] ={2.8,3.4,4,4.6,7.5};

int j, *p=c, *q = c;

for (j=0; j<5; j++){

printf("%d", *c);++q;

}

for (j=0; j<=5; j++){

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

}}*///______________________________________________________________________________

/* Which of the following is correct

1. signed char range is -128 to 1272. unsigned char range is 0 to 2553. int by default is short int4. short int by default is signed short int */

//______________________________________________________________________________

/*#include<stdio.h>#include<string.h>

void main(){

int i,n;

94

Page 95: FRP C & DS dumps

char *x = "OOAD";n = strlen(x);

*x = x[n];

for(i=0; i <n; ++i){

printf ("%s \n", x);x++;

}

}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){

int i, j;for(i=0; i <2; i++){

for(j=0; j<5; j++){if(i==j)

break;printf ("wipro");

}}

}*/

//______________________________________________________________________________

/*#include<stdio.h>

95

Page 96: FRP C & DS dumps

void main(){

int i=2;switch(i){

case 2:printf ("Case2");

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

}}*/

//______________________________________________________________________________

/* When pointer is assign to null pointer what will be the outputa. compile Errorb. runtime error while acessing the pointerc. some output*/

//______________________________________________________________________________

/*#include<stdio.h>

void main(){

int *p, j;????

*p = 35;printf ("%d", j);

}*/

96

Page 97: FRP C & DS dumps

//______________________________________________________________________________

/*#include<stdio.h>

aaa(){

printf("hi");}

bbb(){

printf ("Hello");}

ccc(){

printf("bye");}

void main(){

int (*ptr[3])();ptr[0] = aaa;ptr[1] = bbb;ptr[2] = ccc;

ptr[2]();}*///______________________________________________________________________________

/*#include<stdio.h>

#define wipro main

wipro()

97

Page 98: FRP C & DS dumps

{printf ("main");

}

void main(){

wipro();}*/

//______________________________________________________________________________

/*#include<stdio.h>

#define output(int) printf ("%d", int);

void main(){

int a=2,b=3;output(a);output(b);

}*/

//______________________________________________________________________________

/*#include<stdio.h>

#define wipro printf

main(){

wipro("Hai");}*/

//______________________________________________________________________________

98

Page 99: FRP C & DS dumps

/* Which one of the following statements is true for binary searc tree1. root is less than left & right sub tree2. root is less than left sub tree but greater than right sub tree*/

//______________________________________________________________________________

/* The Range fo unsigned integer is _____________________________*/

//______________________________________________________________________________

/*#include<stdio.h>

void main(){

auto int i=0;static int j=0;extern int k =0;register int l=0;

i++;j++;k++;l++;

printf ("%d %d %d", i, j,l);}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main(){

99

Page 100: FRP C & DS dumps

const char a="b";}*///______________________________________________________________________________

/*#include<stdio.h>void main(){

int i=10;

while(++i>10){

printf ("something");}

}*/

//______________________________________________________________________________

/*#include<stdio.h>define mul(a) (a) * (a); /*They will ask u what will be the define statement toget the output as hundred and the define statement have four opitons. This iscorrect option to get the output*/

/*void main(){

int result;result = mul(10);

printf ("%d", result);}*/

//______________________________________________________________________________

10

Page 101: FRP C & DS dumps

/*#include<stdio.h>

struct a{

int no;int *no1;int *no2;

} *a1;

void main(){

printf ("%d %d %d %d", sizeof(a1->no),sizeof(a1->no1), sizeof(*a1), sizeof(a1));}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){

static int a[5];

int i;

for(i=0; i<5; i++){

printf ("%d", a[i]);}

}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main(){

10

Page 102: FRP C & DS dumps

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

}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){int x,y=6;x=y+NULL;printf("%d",x);} *///______________________________________________________________________________

/*#include<stdio.h>

void main(){static int arr[12];printf("%d",sizeof(arr));} *///______________________________________________________________________________

/*#include<stdio.h>void main(){float a[]={1.2,3.4,5.7,12.3};int i;for(i=0;i<=5;++i)printf("%f ",a[i]);}*/

10

Page 103: FRP C & DS dumps

//______________________________________________________________________________

//A user-defined function returns a pointer (yes/No)

//______________________________________________________________________________

/*#include<stdio.h>void main(){char *p="hello";char q[]={'h','e','l','l','o'};printf("%d %d",sizeof(*p),sizeof(*q));}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){int i=0;while(){switch(i){case 3<2:printf("Hi");break;case 3>2:printf("Hello");break;default:printf("welcome");}++i;

10

Page 104: FRP C & DS dumps

}}*///______________________________________________________________________________

/*#include<stdio.h>void main(){int i=0;while(i<3){switch(i){case 1:printf("case1");

case 2:printf("case2");break;default:printf("Default");}++i;}}*///______________________________________________________________________________

/*#include<stdio.h>void main(){char str1[]="Hello";char str2[]="Hello";if(str1==str2)printf("\nEqual");elseprintf("\nNot equal");

10

Page 105: FRP C & DS dumps

}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){int i;for(i=2;i=0;i--){printf("%d",&i);}}*///______________________________________________________________________________

/*#include<stdio.h>

void main(){

int i=5;

printf ("%d", ~i);}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main(){int i=10;printf("%d ",i=50);}*/

10

Page 106: FRP C & DS dumps

//______________________________________________________________________________

/*#include<stdio.h>#define HELLO "hi"void main(){printf("HELLO");}*///______________________________________________________________________________

/*#include<stdio.h>

struct person{char *name;char *age;char *c;};struct emp{int a;struct person *addr;};

void main(){struct emp *e1;printf("%d",sizeof(e1));

}*/

//______________________________________________________________________________

10

Page 107: FRP C & DS dumps

/*#include<stdio.h>void main(){int i;i=10/4;printf("%d",i);

}*/

//______________________________________________________________________________/*#include<stdio.h>void main(){int a[3][4]={1,2,3,4,5,6,7,8,9};printf("%d ",a[2][1]);}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){

int array[]={10,20,30,40,50},*p;p=&array[0] + 4; //p=array+4for(;p>=array;p--)printf("%d ",*p);

}*/

//______________________________________________________________________________

/*#include<stdio.h>#define wipro main

10

Page 108: FRP C & DS dumps

void wipro(){

printf("main");

}*/

//______________________________________________________________________________

/*#include<stdio.h>void main(){int a=10,b=10;a+=1;printf((a>b)?"hi":"hello");}*/

//______________________________________________________________________________

/*#include<stdio.h>struct emp{int i;char name[15];};

void main(){struct emp e1={1,"hi"},*e2;e2=&e1;if(e1==e2)printf("\nstructures are equal");elseprintf("\nstructures are not equal");}*/

10

Page 109: FRP C & DS dumps

//______________________________________________________________________________

6. The size of long double isa. 8 bytes b. 10 Bytes c. Compiler Dependentd. There is no datatype called long double.Ans::b

7. What is the output of the following:unsigned i=32768;void main(){

printf("%d",i);}

b. 32768c. -32768d. Errore. None of the aboveAns::b

8. How many times Wipro Technologies printed in the following code: for(i=0;i<5;i++)

for (j=0;j<5;j--) {

if (i==j) break;printf(“Wipro Technologies”);

}

a. 4 timesb. Errorc. Infinite loopd. Not predictableAns::c

9. What is the output of the followingint i;void main(){

static int i=3;

10

Page 110: FRP C & DS dumps

printf("%d",i);}

e. 3f. Multiple declaration (since I is static)g. 0h. None of the aboveAns::a(3)10. What is the output of the following:

main(){

void change(char *);char *t="test";change(t);printf("%s",t);

}void change(char *t){

char *ab="new test";*t=*ab;

}b. new testc. testd. neste. None of the aboveAns::c

6. main() { char *fun(); printf("%s",fun()); } char * fun() { char buffer[]=”Hello World”; return buffer; }

a) hello world

11

Page 111: FRP C & DS dumps

b) Compiler error c) Garbage Value d) None of the aboveans::c//if static char buffer is used it would have worked

11. main(){ int a=10,*p=&a,*q=p; *q++;//valid

printf(“%d %d %d”,a,*p,*q);}

a. 11 11 11b. 10 10 11c. Garbage value;d. ErrorGarbage value//actaually 10 10 garbageAns::c

12. #define c(a) a*a#define c(b) b+bvoid main(){ printf(“%d”,c(10));}

e. 100f. 20g. 400h. Error

Ans::f13. void rec(int);

void main(){ rec(3);}void rec(int n){

if (n<=0) return; rec(n-1); printf(“%d”,n); rec(--n);

11

Page 112: FRP C & DS dumps

}a. 1 2 1 3 1 2 1b. 0 1 2 0c. Infinite loopd. Error

Ans::a14. int z, x=5,y=-10,a=4,b=2;

z=x++ - --y * b / a;What number will z in the sample code above contain? a. 5 b. 6 c. 10 d. 11 ans::c

10. char* myFunc (char *ptr){ ptr += 3; return (ptr);}

int main(){ char *x, *y; x = "HELLO"; y = myFunc (x); printf ("y = %s \n", y); return 0;} What will print when the sample code above is executed? a. y = HELLO b. y = ELLO c. y = LLO d. y = LO Ans::d11. What would be the output? void main(){

11

Page 113: FRP C & DS dumps

printf("%s",7["wipro infotech");}

a. fb. Garbage valuec. fotechd. Error

Ans::b Garbage value //used as”wipro infotech”+712. Predict the outputchar p[]="hello";char q[]={'h','e','l','l','o'};printf("%d %d",sizeof(p),sizeof(q));

a. 5 5b. 6 6c. 6 5d. 5 6

Ans::c13. What would be printed: #include<stdio.h>

int i=0;void main(){while(i){

switch(i){Case 3<2:

printf("Hi");break;

case 3>2:printf("Hello");break;

default:printf("welcome");

}++i;}

}

11

Page 114: FRP C & DS dumps

b. Hic. Welcomed. No outpute. ErrorAns::c

14. struct addr{char city[5];char street[5];};struct emp{char name[20];int empno;struct addr *a;};

struct emp *pemp;

How will you access city from the *pemp;a. pemp->a->cityb. pemp->*a.cityc. pemp->a.*cityd. All the above.

Ans::a //rest invalid15. #include<stdio.h>int get();void main(){int x=20;x=get();printf("%d ",x);}

int get(){return(60);}

b. 60

11

Page 115: FRP C & DS dumps

c. Garbaged. Errore. None of the above

Ans::a16. What would be the out put of the followingvoid main(){int a=10,b=20,c=30;a++ || b-20 && ++c;printf("%d %d %d",a,b,c);}

a. 11 20 31b. 11 0 30c. 11 20 30d. Error

Ans::c17. What will be the output of the following program :

void main(){ printf("Hi!"); if (-1) printf("Bye");}

(a)No Output (b)Hi! (c)Bye(d)Hi!Bye

Ans::d18. void main()

{ printf("Hi!"); if !(0) printf("Bye");}

(a)Compile-Time error (b)Hi! (c)Bye(d)Hi!Bye

Ans::a19. void main()

{ printf("Hi!"); if (-1+1+1+1-1-1-1+(-1)-(-1)) printf("Bye");

11

Page 116: FRP C & DS dumps

}(a)No Output (b)Hi! (c)Bye

(d)Hi!ByeAns::d20. void main()

{ int a=1,b=2,c=3,d=4,e; if (e=(a & b | c ^ d)) printf("%d",e);}

(a)0 (b)7 (c)3 (d)No OutputNas::21. auto int a=5;

void main(){ printf("%d",a);}

(a)Compile-Time error (b)Run-Time error (c)5(d)Unpredictable

Ans::a//auto cannot be declared outside any fuction22. main()

{ int a=1; if (a) printf("Test"); else; printf("Again");}

(a)Again (b)Test (c)Compile-Time Error(d)TestAgain

Ans::b23. void main()

{ float i; for (i=0.1; i<0.4; i+=0.1) printf("%.1f",i);}

11

Page 117: FRP C & DS dumps

(a)0.10.20.3 (b)Compile-Time Error (c)Run-Time Error (d)No OutputAns::a

24.Point out the error if any #include<stdio.h>

main(){

struct xx{

int x;struct yy{

char s;struct xx *p;

};//name sud be given….struct yy *q;

};}

a. Compile time errorb. Run time errorc. No error.d. Compiler dependent

ans::a

5. Heap

1) is a region from where memory is allocated2) lies between you program and the stack3) is a finite area4) all of the above

Ans::426. Predict the outputint a = 4, b = 7,c; c = a = = b; printf("%i",c);

a) 0b) errorc) 1d) garbage value

11

Page 118: FRP C & DS dumps

ans::error//= = would not work == will do27. What will be the output of the following statements?int a[2][2] = { 3,2,5,4 };printf("%d",*(*(*(a))));

a) errorb) 3c) garbage valued) 2Ans::a28.Which of the functions is most apt for reading a multi-word ?

a) puts()b) gets()c) scanf()d) vsscanf()Ans::b29. What will be the output of the following program ?

#include<stdio.h>#include<math.h>void main(){int n; char *str = "324.89"; n = atoi(str); printf("%d",n);}

a) 300b) 324c) 32489d) 89Ans::32430. #include<stdio.h>void main(){ printf("%d"); }

a) errorb) no output

11

Page 119: FRP C & DS dumps

c) %dd) 0Ans::d31. #include<stdio.h>void main(){int a = 36, b = 9;printf("%d",a>>a/b-2);}

a) 9b) 7c) 5d) none of theseAns::a32. #include<stdio.h>

void main(){ int a,b; void small(int,int); printf("Enter 2 numbers\n"); scanf("%d %d",&a,&b);}void small(int x,int y){ if (x<y) printf("A is less than B"'); else printf("B is less than A");}

If a=10, b=10 What is the output

a. B is less than Ab. A is less than Bc. Errord. No output

Ans::d33. swap(int *a,int *b){int *t;

11

Page 120: FRP C & DS dumps

t=a;a=b;b=t;}

void main(){int a=10,b=20;swap(&a,&b);printf(“%d %d”,a,b);}

b. 10 20c. 20 10d. Errore. Garbage value

Ans::a34. main()

{char *p="hai friends",*p1;p1=p;while(*p!='\0') ++*++p;printf("%s %s",p,p1);

}

a. ibj!gsjfoetb. hbj!gsjfoet c. hbj!gsjfoet hbj!gsjfoet d. None of the above

Ans::d//abnormal program termination35. 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));}

If the input given are Wipro Technologies Chennai

12

Page 121: FRP C & DS dumps

What will be the output

a. WTChennai TChennai Chennaib. Chennai Chennai Chennaic. Wipro Technologies Chennaid. None of the above

Ans::d36. 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. OOADOADAD

b. OADADD

c. No outputd. None of the above

Ans::b37. #define FALSE -1

#define TRUE 1#define NULL 0main() { if(NULL)

puts("NULL"); else if(FALSE)

puts("TRUE"); else

12

Page 122: FRP C & DS dumps

puts("FALSE"); }

a. TRUEb. FALSEc. TRUE FALSEd. Error

Ans::a38. main()

{ int i=5,j=6,z; printf("%d",i---j); }

a. -1b. Errorc. 0d. None of the above

Ans::a39. 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 0004b. 0000:0001 0000:0002 0000:0004c. 1 2 4d. ErrorAns::a//inc by their type value in p,q r set to zero

40. # include<stdio.h>aaa() {

12

Page 123: FRP C & DS dumps

printf("hi"); }bbb(){ printf("hello"); }ccc(){ printf("bye"); }main(){ int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; (*ptr)();}

a. hib. helloc. byed. ErrorAns::hi

1) Which of the following is a compound assignment statement?a)a=bb) a=b=cc) a+=bd) a=b;b=c;

ans::c2) 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!=EOFb) ch!=NULLc) ch==NULLd) ch=='\0'

ans::a3) which of the following accepts only the specified number of characters from a file

a) fgetsb) fread

12

Page 124: FRP C & DS dumps

c) fputcd) fputs

ans::a4) which of the following is the best for getting a string with space from the standard input

a) getsb) getcc) fgetsd) puts

ans::fgets//gets5)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"a) char *message[ ]="hello"

ans::c6) which data structure is best for searching an element in the given list

a) arraysb) single linked listc) doubly linked listd) binary search trees

ans::d7) 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,18b)18,4c) 4,18d) 4,4

ans::a8) what would the statement strcmp("Astring","Astring"); return?

a) 0

12

Page 125: FRP C & DS dumps

b) <1c)>1d) -1

ans::a9) which statement is used to compare the two strings ?

a) strcmpb)strcomparec) stringcompared) str_cmp

ans::a10) int fun(int x) { int y=55;

return((x-y)?y:x); } main() { int a=20; fun(a); printf("%d",y); }

ans::error11) 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() {

12

Page 126: FRP C & DS dumps

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,20b) 20,5,10c) 20,10,5d) none of the above

ans::a14) 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

15) Allocating a 2 blocks of memory for 'n' intgers is by usinga) mallocb) callocc) both malloc and callocd) none of the above

ans::b16) In queue using linked list, which is correct?

a) both insertion and deltionis made at the front endb) insertion is made at the beginning and deletion is made at the lastc) insertion is made at the last and deletion is made at the beginningd) both insertion and deltionis made at the back end

ans::c17) main()

12

Page 127: FRP C & DS dumps

{ int i=10; printf("%d",i==10); }ans::118) main() { char c='p';

printf("%c",c); }ans::p19) 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?a) unsigned char shortb) unsigned short charc) short unsigned chard)noneof the above

ans::b21) void fun(char *str) {

12

Page 128: FRP C & DS dumps

char *str1="hai"; str=str1; } main() { char *str="Hello"; fun(str); printf("%s",str); }ans::hello22) 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 only27) for(i=0;i<2;i++) { for(j=0;j<5;j++)

{

12

Page 129: FRP C & DS dumps

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]); }error30) 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 onlyb) i onlyc)all the threed) none of the above

12

Page 130: FRP C & DS dumps

ans::c31)which of these is replaced by a switch block?

a) while loopb) do whilec) for loopd)else if

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 string34) main() {

char s[ ]="\12345s\n";printf("%d\n",sizeof(str));

13

Page 131: FRP C & DS dumps

}ans::635) 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;

b)char signed a;c) char a signed;d) none of the above

ans::c

37) all the local variables are stored in -----------------a) stackb) heapc) queued) none

ans::a38) Once you call a function,all the return addresses are stored in ----------------

a) stackb) heapc) queued) none

ans::a39) Which of the following is true about binary tree

i) all nodes except leaf node has exactly two childii) root node is greater than the left sub tree and lesser than the right

sub tree.a) i onlyb)ii onlyc) both i and iid) neither i nor ii

ans::b40) Which of the following is true about complete binary tree

13

Page 132: FRP C & DS dumps

i) all nodes except leaf node has exactly two childii) root node is greater than the left sub tree and lesser than the right

sub tree.a) i onlyb)ii onlyc) both i and iid) neither i nor ii

ans::c41) 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 snippetfront=start;back=end;while(back!=NULL){ printf("%d",back->data);

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 snippetfront=start;back=end;while((front!=back)&&(back->left!=front)){ temp=front->data; front->data=back->data; back->data=temp;}

13

Page 133: FRP C & DS dumps

43) the declaration of the pinter to an array ofint having the name iptr is -------------------

a) int *iptrb) int &iptrc) int *&iptrd)iptr *int

ans::a44) int one_d={0,1,2}; main() {

int *ptr;ptr=one_d;ptr+=3;printf("%d",*ptr);

}ans::error45) struct a { char *b; char *c; char *d; };struct e{ char *f; struct a *g;}abc;printf("%d",sizeof(abc));

ans::4

46) struct a { char *b; char *c; char *d; };

13

Page 134: FRP C & DS dumps

struct e{ char *f; struct a g;}abc;printf("%d",sizeof(abc));ans::8

47)#define wipro main wipro() {

printf("main"); }ans::main48) void prod(int x,int y,int z){ int p; p=x*y*z; printf("%d",p);}void main(){ int a=3,b=4,c=5;prod(a,b,c);}49) int meq();void main(){printf("Hai");meq();printf("Hello");}meq(){printf("Bye");}ans::HaiByeHello49) void main(){char *p="welcome";

13

Page 135: FRP C & DS dumps

char q[ ]={'w','e','l','c','o','m','e'};printf("%d %d",sizeof(*p),sizeof(*q));}ans::1150) The size of the doubly linked list is always greater than the single linked list

a) trueb) false

51) char *ptr="abcdefgh";char *sptr;sptr=ptr+5;printf("%s",sptr);

ans::fgh52) If the integer occupies 2 bytes then short int will take how many bytes?

53) In C, syntax error is generated by ---------------------a) compilerb) InterpreterC) linkerd) none

54) char *ptr="Madam";char *sptr=ptr+4;while(sptr>=ptr){ printf("%c",*sptr);sptr--;}ans::madaM

55) void main(){int i;i=10/20;printf("%d",i);}ans::0

13

Page 136: FRP C & DS dumps

56) The arguments in a function call is known as ---------------------a) formal argumentsb) actual arguments

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

58) int i=10;main(){int i=20;{int i=30;printf("%d",i);}printf("%d",i);}ans::3020

59) void fun();main(){fun();}void fun(){ printf("good");}ans::good

60) void main(){ int i=10;j=20,k=30,l=40,m;int *a[4];

13

Page 137: FRP C & DS dumps

a[0]=&i;a[1]=&j;a[2]=&k;a[3]=&l;for(m=0;m<4;m++)printf("%d",*a[m]);}ans::10203040

61) if the insertion is made only at the beginning then which data structure is used

a) arrayb) stackc) queued) 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","Hewlett packard","New city","ibm"}; char **ptr=a; printf("%s",++*p); printf("%s",*p++); printf("%s",*p);}ans::harmaharmaHewlett packard

64)

13

Page 138: FRP C & DS dumps

C Questions

Note : All the programs are tested under Turbo C/C++ compilers. It is assumed that,

Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.

The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

Predict the output or error(s) for the following:

1. void main(){

int const * p=5;printf("%d",++(*p));

}Answer:

Compiler error: Cannot modify a constant value. Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

2. main(){

char s[ ]="man";int i;for(i=0;s[ i ];i++)printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}Answer:

mmmm aaaa nnnn

Explanation:s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the

same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address.

13

Page 139: FRP C & DS dumps

So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

3. main(){

float me = 1.1;double you = 1.1;if(me==you)

printf("I love U");else

printf("I hate U");}

Answer: I hate U

Explanation:For floating point numbers (float, double, long double) the

values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.

Rule of Thumb: Never compare or at-least be cautious when using floating point

numbers with relational operators (== , >, <, <=, >=,!= ) .

4. main(){static int var = 5;printf("%d ",var--);if(var)

main();}Answer:

5 4 3 2 1 Explanation:

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

5. main()

13

Page 140: FRP C & DS dumps

{ int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) {

printf(" %d ",*c); ++q; } for(j=0;j<5;j++){

printf(" %d ",*p);++p; }

}

Answer: 2 2 2 2 2 2 3 4 6 5 Explanation:

Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.

6. main(){

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

}

Answer: Linker Error : Undefined symbol '_i'

Explanation: extern storage class in the following declaration, extern int i;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. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .

7. main(){

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

14

Page 141: FRP C & DS dumps

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

Answer: 0 0 1 3 1

Explanation :Logical operations always give a result of 1 or 0 . And also the

logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

8. main(){

char *p;printf("%d %d ",sizeof(*p),sizeof(p));

}

Answer: 1 2

Explanation:The sizeof() operator gives the number of bytes taken by its

operand. P is a character pointer, which needs one byte for storing its value (a character). 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.

9. main(){

int i=3;switch(i) { default:printf("zero"); case 1: printf("one");

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

break; case 3: printf("three");

break; }

14

Page 142: FRP C & DS dumps

}Answer :

threeExplanation :

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

10.main(){

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

Answer: fff0

Explanation :-1 is internally represented as all 1's. When left shifted four

times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

11.main(){

char string[]="Hello World";display(string);

}void display(char *string){

printf("%s",string);}

Answer:Compiler Error : Type mismatch in redeclaration of function

display Explanation :

In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

12.main(){

int c=- -2;

14

Page 143: FRP C & DS dumps

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

Answer: c=2; Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.

Note: However you cannot give like --2. Because -- operator can only

be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

13.#define int charmain(){

int i=65;printf("sizeof(i)=%d",sizeof(i));

}Answer:

sizeof(i)=1Explanation:

Since the #define replaces the string int by the macro char

14.main(){

int i=10;i=!i>14;Printf ("i=%d",i);

}Answer:

i=0

Explanation:In the expression !i>14 , NOT (!) operator has more precedence

than ‘ >’ symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

15.#include<stdio.h>main()

14

Page 144: FRP C & DS dumps

{char s[]={'a','b','c','\n','c','\0'};char *p,*str,*str1;p=&s[3];str=p;str1=s;printf("%d",++*p + ++*str1-32);

}Answer:

77Explanation:p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p

is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.

Now performing (11 + 98 – 32), we get 77("M"); So we get the output 77 :: "M" (Ascii is 77).

16.#include<stdio.h>main(){

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };int *p,*q;p=&a[2][2][2];*q=***a;printf("%d----%d",*p,*q);

}Answer:

SomeGarbageValue---1Explanation:

p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.

17.#include<stdio.h>main(){

14

Page 145: FRP C & DS dumps

struct xx{ int x=3; char name[]="hello"; };struct xx *s;printf("%d",s->x);printf("%s",s->name);

}Answer:

Compiler ErrorExplanation:

You should not initialize variables in declaration

18.#include<stdio.h>main(){

struct xx{

int x;struct yy{

char s;struct xx *p;

};struct yy *q;

};}

Answer:Compiler Error

Explanation:The structure yy is nested within structure xx. Hence, the

elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

19.main(){

printf("\nab");

14

Page 146: FRP C & DS dumps

printf("\bsi");printf("\rha");

}Answer:

haiExplanation:

\n - newline\b - backspace\r - linefeed

20.main(){

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

}Answer:

45545Explanation:

The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

21.#define square(x) x*xmain(){

int i;i = 64/square(4);printf("%d",i);

}Answer:

64Explanation:

the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64 22.main()

{char *p="hai friends",*p1;p1=p;

14

Page 147: FRP C & DS dumps

while(*p!='\0') ++*p++;printf("%s %s",p,p1);

}Answer:

ibj!gsjfoetExplanation:

++*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 ; is encountered the location will be incremented that is p++ will be

executedHence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by executing ++*p and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so on. Similarly blank space is converted to ‘!’. Thus, we obtain value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything.

23.#include <stdio.h>#define a 10main(){

#define a 50printf("%d",a);

}Answer:

50Explanation:

The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

24.#define clrscr() 100main(){

clrscr();printf("%d\n",clrscr());

}Answer:

100Explanation:

14

Page 148: FRP C & DS dumps

Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input program to compiler looks like this :

main(){ 100; printf("%d\n",100);}

Note:100; is an executable statement but with no action. So it doesn't

give any problem

25.main(){

printf("%p",main);}

Answer:Some address will be printed.

Explanation: Function names are just addresses (just like array names are

addresses).main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.

27) main(){clrscr();}clrscr();

Answer:No output/error

Explanation:The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).

28) enum colors {BLACK,BLUE,GREEN} main()

14

Page 149: FRP C & DS dumps

{ printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1);}Answer:

0..1..2Explanation:

enum assigns numbers starting from 0, if not explicitly defined.

29) void main(){ char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }Answer:

4..2 Explanation: the second pointer is of char type and not a far pointer

30) main(){ int i=400,j=300; printf("%d..%d");}Answer:

400..300Explanation:

printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take only the first two values. If more number of assignments given in the program,then printf will take garbage values.

31) main(){ char *p; p="Hello";

14

Page 150: FRP C & DS dumps

printf("%c\n",*&*p);}Answer:

H Explanation:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.

32) main(){ int i=1; while (i<=5) { printf("%d",i); if (i>2)

goto here; i++; }}fun(){ here: printf("PP");}Answer:

Compiler error: Undefined label 'here' in function mainExplanation:

Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function fun() Hence it is not visible in function main.

33) main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3];

15

Page 151: FRP C & DS dumps

names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]);}Answer:

Compiler error: Lvalue required in function mainExplanation:

Array names are pointer constants. So it cannot be modified.

34) void main(){

int i=5;printf("%d",i++ + ++i);

}Answer:

Output Cannot be predicted exactly.Explanation:

Side effects are involved in the evaluation of i

35) void main(){

int i=5;printf("%d",i+++++i);

}Answer:

Compiler Error Explanation:

The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators.

36) #include<stdio.h>

main(){int i=1,j=2;switch(i) { case 1: printf("GOOD");

break; case j: printf("BAD");

15

Page 152: FRP C & DS dumps

break; }}Answer:

Compiler Error: Constant expression required in function main.Explanation:

The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).

Note:Enumerated types can be used in case statements.

37) main(){int i;printf("%d",scanf("%d",&i)); // value 10 is given as input here}Answer:

1Explanation:

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.

38) #define f(g,g2) g##g2main(){int var12=100;printf("%d",f(var,12));}Answer:

100

39) main(){int i=0; for(;i++;printf("%d",i)) ;

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

15

Page 153: FRP C & DS dumps

1Explanation:

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).

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);}Answer:

MExplanation:

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);

15

Page 154: FRP C & DS dumps

}Answer:

Compiler ErrorExplanation:

Initialization should not be done for structure members inside the structure declaration

42) #include<stdio.h>main(){struct xx { int x; struct yy { char s; struct xx *p; };

struct yy *q; }; }

Answer:Compiler Error

Explanation: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.

15

Page 155: FRP C & DS dumps

44) 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.

45) main(){ extern out; printf("%d", out);} int out=100;Answer:

100Explanation:

This is the correct way of writing the previous program.

46) main(){ show();}void show(){ 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:

15

Page 156: FRP C & DS dumps

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, 2114, 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++;

} p = a; for(j=0; j<5; j++)

15

Page 157: FRP C & DS dumps

{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:

111222333344

Explanation:Let us consider the array and the two pointers with some address

a0 1 2 3 4

100 102 104 106 108 p

100 102 104 106 108

15

Page 158: FRP C & DS dumps

1000 1002 1004 1006 1008 ptr

10002000

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

15

Page 159: FRP C & DS dumps

M O U S E \0When 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 \0The third input starts filling from the location 102M T V I R T U A L \0This is the final value stored .The first printf prints the values at the position q, q+1 and q+2

= M T VThe second printf prints three strings starting from locations q,

q+1, q+2 i.e MTVIRTUAL, TVIRTUAL and VIRTUAL.

51) main( )

{ 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:

g20fyExplanation:

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 4th 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;

15

Page 160: FRP C & DS dumps

**++p; printf(“%s”,*--*++p + 3);}Answer:

ckExplanation:

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’.

53) main(){ int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) {

printf(“%s\n”,x);x++;

} }Answer:

(blank space)irlrll

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 (‘\

16

Page 161: FRP C & DS dumps

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.

54) 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 NDEBUGand this will disable all the assertions from the source code.

Assertionis a good debugging tool to make use of.

55) main()

{int i=-1;+i;printf("i = %d, +i = %d \n",i,+i);}Answer:

i = -1, +i = -1Explanation:

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?

16

Page 162: FRP C & DS dumps

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

positionof 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.

59) 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.

60) main(){main();}Answer:

Runtime error : Stack overflow.Explanation:

16

Page 163: FRP C & DS dumps

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 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.

62) main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));}Answer:

2 5 5Explanation:

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.

63) main(){char not;not=!2;

16

Page 164: FRP C & DS dumps

printf("%d",not);}Answer:

0Explanation:

! 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.

64) #define FALSE -1#define TRUE 1#define NULL 0main() { if(NULL)

puts("NULL"); else if(FALSE)

puts("TRUE"); else

puts("FALSE"); }Answer:

TRUEExplanation:

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()

16

Page 165: FRP C & DS dumps

{int k=1;printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");}Answer:

1==1 is TRUEExplanation:

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".

66) main(){int y;scanf("%d",&y); // input given is 2000if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year");else printf("%d is not a leap year");}Answer:

2000 is a leap yearExplanation:

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:

16

Page 166: FRP C & DS dumps

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);}Answer:

30,20,10Explanation:

'{' introduces new block and thus new scope. In the innermost block i is declared as,

const volatile unsignedwhich is a valid declaration. i is assumed of type int. So printf prints 30. In the next block, i has value 20 and so printf prints 20. In the outermost block, i is declared as extern, so no storage space is allocated for it. After compilation is over the linker resolves it to global variable i (since it is the only variable visible there). So it prints i's value as 10.

69) main(){ int *j; { int i=10; j=&i;

16

Page 167: FRP C & DS dumps

} printf("%d",*j);}Answer:

10Explanation:

The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.

70) main(){int i=-1;-i;printf("i = %d, -i = %d \n",i,-i);}Answer:

i = -1, -i = 1Explanation:

-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i. After that the value of the expression -i = -(-1) is printed.

71) #include<stdio.h>main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }Answer:

Compiler error Explanation:

i is a constant. you cannot change the value of constant

72) #include<stdio.h>main()

16

Page 168: FRP C & DS dumps

{ int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q);}Answer:

garbagevalue..1Explanation:

p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.

73) #include<stdio.h>main() { register i=5; char j[]= "hello"; printf("%s %d",j,i);}Answer:

hello 5Explanation:

if you declare i as register compiler will treat it as ordinary integer and it will take integer value. i value may be stored either in register or in memory.

74) main(){ int i=5,j=6,z; printf("%d",i+++j); }Answer:

11Explanation:

the expression i+++j is treated as (i++ + j)

16

Page 169: FRP C & DS dumps

76) struct aaa{struct aaa *prev;int i;struct aaa *next;};

main(){ struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x);}Answer:

2Explanation:

above all statements form a double circular linked list;abc.next->next->prev->next->i this one points to "ghi" node the value of at particular node is 2.

77) struct point { int x; int y; };struct point origin,*pp;main(){pp=&origin;printf("origin is(%d%d)\n",(*pp).x,(*pp).y);printf("origin is (%d%d)\n",pp->x,pp->y);}

Answer:origin is(0,0)

16

Page 170: FRP C & DS dumps

origin is(0,0) Explanation:

pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.

Note: Since structure point is globally declared x & y are initialized

as zeroes

78) main(){ int i=_l_abc(10);

printf("%d\n",--i);}int _l_abc(int i){ return(i++);}Answer:

9Explanation:

return(i++) it will first return i and then increments. i.e. 10 will be returned.

79) main(){ char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r);}Answer:

0001...0002...0004Explanation:

++ operator when applied to pointers increments address according to their corresponding data-types.

17

Page 171: FRP C & DS dumps

80) main(){ char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x);}convert(z){ return z-32;}Answer:

Compiler errorExplanation:

declaration of convert and format of getc() are wrong.

81) main(int argc, char **argv){ printf("enter the character"); getchar(); sum(argv[1],argv[2]);}sum(num1,num2)int num1,num2;{ return num1+num2;}Answer:

Compiler error.Explanation:

argv[1] & argv[2] are strings. They are passed to the function sum without converting it to integer values.

82) # include <stdio.h>int one_d[]={1,2,3};main(){ int *ptr; ptr=one_d;

17

Page 172: FRP C & DS dumps

ptr+=3; printf("%d",*ptr);}Answer:

garbage valueExplanation:

ptr pointer is pointing to out of the array range of one_d.

83) # include<stdio.h>aaa() { printf("hi"); }bbb(){ printf("hello"); }ccc(){ printf("bye"); }main(){ int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2]();}Answer:

bye Explanation:

ptr is array of pointers to functions of return type int.ptr[0] is assigned to address of the function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. ptr[2]() is in effect of writing ccc(), since ptr[2] points to ccc.

85) #include<stdio.h>main(){FILE *ptr;char i;ptr=fopen("zzz.c","r");

17

Page 173: FRP C & DS dumps

while((i=fgetch(ptr))!=EOF)printf("%c",i);

}Answer:

contents of zzz.c followed by an infinite loop Explanation:

The condition is checked against EOF, it should be checked against NULL.

86) main(){ int i =0;j=0; if(i && j++) printf("%d..%d",i++,j);printf("%d..%d,i,j);}Answer:

0..0 Explanation:

The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. The values of i and j remain unchanged and get printed.

87) main()

{ int i; i = abc(); printf("%d",i);}abc(){ _AX = 1000;}Answer:

1000Explanation:

Normally the return value from the function is through the information from the accumulator. Here _AH is the pseudo

17

Page 174: FRP C & DS dumps

global variable denoting the accumulator. Hence, the value of the accumulator is set 1000 so the function returns value 1000.

88) int i; main(){

int t;for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--);

}// If the inputs are 0,1,2,3 find the o/pAnswer: 4--0

3--12--2

Explanation:Let us assume some x= scanf("%d",&i)-t the values during

execution will be,

t i x 4 0 -4 3 1 -2 2 2 0

89) main(){

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }Answer:

hello Explanation:

The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.

90) main(){ unsigned int i; for(i=1;i>-2;i--)

17

Page 175: FRP C & DS dumps

printf("c aptitude");}Explanation:

i is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.

91) In the following pgm add a stmt in the function fun such that the address of

'a' gets stored in 'j'.main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }Answer:

*k = &aExplanation:

The argument of the function is a pointer to a pointer. 92) What are the following notations of defining functions known as?

i. int abc(int a,float b) { /* some code */

}ii. int abc(a,b) int a; float b;

{ /* some code*/ }

Answer:i. ANSI C notationii. Kernighan & Ritche notation

93) main()

17

Page 176: FRP C & DS dumps

{char *p;p="%d\n";

p++; p++; printf(p-2,300);

}Answer:

300Explanation:

The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

94) main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a);}abc(char a[]){ a++;

printf("%c",*a); a++; printf("%c",*a);}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.

95) func(a,b)

int a,b;{

return( a= (a==b) );}main(){int process(),func();printf("The value of process is %d !\n ",process(func,3,6));}process(pf,val1,val2)int (*pf) ();

17

Page 177: FRP C & DS dumps

int val1,val2;{return((*pf) (val1,val2)); }Answer:

The value if process is 0 !Explanation:

The function 'process' has 3 parameters - 1, a pointer to another function 2 and 3, integers. When this function is invoked from main, the following substitutions for formal parameters take place: func for pf, 3 for val1 and 6 for val2. This function returns the result of the operation performed by the function 'func'. The function func has two integer parameters. The formal parameters are substituted as 3 for a and 6 for b. since 3 is not equal to 6, a==b returns 0. therefore the function returns 0 which in turn is returned by the function 'process'.

96) void main(){

static int i=5;if(--i){

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

}}Answer:

0 0 0 0Explanation:

The variable "I" is declared as static, hence memory for I will be allocated for only once, as it encounters the statement. The function main() will be called recursively unless I becomes equal to 0, and since main() is recursively called, so the value of static I ie., 0 will be printed every time the control is returned.

97) void main(){

int k=ret(sizeof(float));printf("\n here value is %d",++k);

}int ret(int ret)

17

Page 178: FRP C & DS dumps

{ret += 2.5;return(ret);

}Answer:

Here value is 7Explanation:

The int ret(int ret), ie., the function name and the argument name can be the same.

Firstly, the function ret() is called in which the sizeof(float) ie., 4 is passed, after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main() it is printed after and preincrement.

98) void main(){

char a[]="12345\0";int i=strlen(a);printf("here in 3 %d\n",++i);

}Answer:

here in 3 6Explanation:

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.

99) void main(){

unsigned giveit=-1;int gotit;printf("%u ",++giveit);printf("%u \n",gotit=--giveit);

}Answer:

0 65535Explanation:

17

Page 179: FRP C & DS dumps

100) void main(){

int i;char a[]="\0";if(printf("%s\n",a))

printf("Ok here \n");else

printf("Forget it\n");}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, thus "Ok here" is printed.

101) void main()

{void *v;int integer=2;int *i=&integer;v=i;printf("%d",(int*)*v);

}Answer:

Compiler Error. We cannot apply indirection on type void*.Explanation:

Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void pointers are normally used for, 1. Passing generic pointers to functions and returning such

pointers.2. As a intermediate pointer type.3. Used when the exact pointer type will be known at a later

point of time.

102) void main(){

int i=i++,j=j++,k=k++;printf(“%d%d%d”,i,j,k);

}

17

Page 180: FRP C & DS dumps

Answer: Garbage values.

Explanation:An identifier is available to use in program code from the point

of its declaration. So expressions such as i = i++ are valid statements. The i, j and k are automatic variables and so they contain some garbage value. Garbage in is garbage out (GIGO).

103) void main(){

static int i=i++, j=j++, k=k++;printf(“i = %d j = %d k = %d”, i, j, k);

}Answer:

i = 1 j = 1 k = 1Explanation:

Since static variables are initialized to zero by default.

104) void main(){

while(1){if(printf("%d",printf("%d")))

break;else

continue;}

}Answer:

Garbage valuesExplanation:

The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.

104) main(){

18

Page 181: FRP C & DS dumps

unsigned int i=10;while(i-->=0)

printf("%u ",i);

}Answer:

10 9 8 7 6 5 4 3 2 1 0 65535 65534…..Explanation:

Since i is an unsigned integer it can never become negative. So the expression i-- >=0 will always be true, leading to an infinite loop.

105) #include<conio.h>main(){

int x,y=2,z,a;if(x=y%2) z=2;a=2;printf("%d %d ",z,x);

} Answer:

Garbage-value 0Explanation:

The value of y%2 is 0. This value is assigned to x. 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.

106) main(){

int a[10];printf("%d",*a+1-*a+3);

}Answer:

4 Explanation:

*a and -*a cancels out. The result is as simple as 1 + 3 = 4 !

107) #define prod(a,b) a*b

18

Page 182: FRP C & DS dumps

main() {

int x=3,y=4;printf("%d",prod(x+2,y-1));

}Answer:

10Explanation:

The macro expands and evaluates to as:x+2*y-1 => x+(2*y)-1 => 10

108) main(){

unsigned int i=65000;while(i++!=0);printf("%d",i);

}Answer:

1Explanation:

Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1.

109) main()

{int i=0;while(+(+i--)!=0)

i-=i++;printf("%d",i);

}Answer:

-1Explanation:

Unary + is the only dummy operator in C. So it has no effect on the expression and now the while loop is, while(i--!=0) which is false and so breaks out of while loop. The value –1 is printed due to the post-decrement operator.

113) main()

18

Page 183: FRP C & DS dumps

{float f=5,g=10;enum{i=10,j=20,k=50};printf("%d\n",++k);printf("%f\n",f<<2);printf("%lf\n",f%g);printf("%lf\n",fmod(f,g));

}Answer:

Line no 5: Error: Lvalue requiredLine no 6: Cannot apply leftshift to floatLine no 7: Cannot apply mod to float

Explanation:Enumeration constants cannot be modified, so you cannot apply

++.Bit-wise operators and % operators cannot be applied on float

values.fmod() is to find the modulus values for floats as % operator is

for ints.

110) main(){

int i=10;void pascal f(int,int,int);f(i++,i++,i++);printf(" %d",i);

}void pascal f(integer :i,integer:j,integer :k){

write(i,j,k); }Answer:

Compiler error: unknown type integerCompiler error: undeclared function write

Explanation:Pascal keyword doesn’t mean that pascal code can be used. It

means that the function follows Pascal argument passing mechanism in calling the functions.

111) void pascal f(int i,int j,int k)

18

Page 184: FRP C & DS dumps

{ printf(“%d %d %d”,i, j, k);

}void cdecl f(int i,int j,int k){

printf(“%d %d %d”,i, j, k); }main(){

int i=10;f(i++,i++,i++);printf(" %d\n",i);i=10;f(i++,i++,i++);printf(" %d",i);

}Answer:

10 11 12 1312 11 10 13

Explanation:Pascal argument passing mechanism forces the arguments to be

called from left to right. cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.

112). What is the output of the program given below

main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }Answer

-128Explanation

Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. 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.

18

Page 185: FRP C & DS dumps

The condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.

113) main()

{ unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }Answerinfinite loopExplanationThe 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.

114) main() {

char i=0; for(;i>=0;i++) ; printf("%d\n",i);

}Answer:

Behavior is implementation dependent.Explanation:

The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.Rule:

You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.

115) Is the following statement a declaration/definition. Find what does it mean?

int (*x)[10];

18

Page 186: FRP C & DS dumps

AnswerDefinition.x is a pointer to array of(size 10) integers.

Apply clock-wise rule to find the meaning of this definition.

116). What is the output for the program given below

typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }Answer

Compiler error: Multiple declaration for errorExplanation

The name error is used in the two meanings. One means that it is a enumerator constant with value 1. The another use is that it is a type name (due to typedef) for enum errorType. Given a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used:

error g1;g1=error;

// which error it refers in each case?When the compiler can distinguish between usages then

it will not issue error (in pure technical terms, names can only be overloaded in different namespaces).

Note: the extra comma in the declaration,enum errorType{warning, error, exception,}

is not an error. An extra comma is valid and is provided just for programmer’s convenience.

117) typedef struct error{int warning, error,

exception;}error; main()

18

Page 187: FRP C & DS dumps

{ error g1; g1.error =1; printf("%d",g1.error); }

Answer1

ExplanationThe three usages of name errors can be distinguishable by the

compiler at any instance, so valid (they are in different namespaces).Typedef struct error{int warning, error, exception;}error;

This error can be used only by preceding the error by struct kayword as in:

struct error someError;typedef struct error{int warning, error, exception;}error;

This can be used only after . (dot) or -> (arrow) operator preceded by the variable name as in :

g1.error =1; printf("%d",g1.error);

typedef struct error{int warning, error, exception;}error;This can be used to define variables without using the preceding struct keyword as in:

error g1;Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid.

NoteThis code is given here to just explain the concept behind. In

real programming don’t use such overloading of names. It reduces the readability of the code. Possible doesn’t mean that we should use it! 118) #ifdef something

int some=0;#endif

main(){

int thing = 0;printf("%d %d\n", some ,thing);

18

Page 188: FRP C & DS dumps

}

Answer:Compiler error : undefined symbol some

Explanation:This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration int some = 0;effectively removed from the source code.

119) #if something == 0int some=0;#endif

main(){

int thing = 0;printf("%d %d\n", some ,thing);

}

Answer0 0

ExplanationThis code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.

120). What is the output for the following program

main() {

int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D ==

arr2D[0])) ); }

Answer1

Explanation

18

Page 189: FRP C & DS dumps

This is due to the close relation between the arrays and pointers. N dimensional arrays are made up of (N-1) dimensional arrays. arr2D is made up of a 3 single arrays that contains 3

integers each .

The name arr2D refers to the beginning of all the 3 arrays. *arr2D refers to the start of the first 1D array (of 3 integers) that is the same address as arr2D. So the expression (arr2D == *arr2D) is true (1). Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero doesn’t change the value/meaning. Again arr2D[0] is the another way of telling *(arr2D + 0). So the expression (*(arr2D + 0) == arr2D[0]) is true (1). Since both parts of the expression evaluates to true the result is true(1) and the same is printed.

121) void main() {

if(~0 == (unsigned int)-1)printf(“You can answer this if you know how values are represented in memory”);

} Answer

You can answer this if you know how values are represented in memoryExplanation

~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. –1 is represented in unsigned value as all 1’s and so both are equal.

122) int swap(int *a,int *b)

18

arr2Darr2D[1]

arr2D[2]

arr2D[3]

Page 190: FRP C & DS dumps

{ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

}Answer

x = 20 y = 10Explanation

This is one way of swapping two values. Simple checking will help understand this.

123) main(){char *p = “ayqm”;printf(“%c”,++*(p++));}Answer:

b

124) main(){

int i=5; printf("%d",++i++);

} Answer:

Compiler error: Lvalue required in function mainExplanation:

++i yields an rvalue. For postfix ++ to operate an lvalue is required.

125) main(){

char *p = “ayqm”;char c;c = ++*p++;printf(“%c”,c);

19

Page 191: FRP C & DS dumps

}Answer:

bExplanation:

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.

126)int aaa() {printf(“Hi”);}int bbb(){printf(“hello”);}iny ccc(){printf(“bye”);}

main(){int ( * ptr[3]) ();ptr[0] = aaa;ptr[1] = bbb;ptr[2] =ccc;ptr[2]();

}Answer:

byeExplanation:

int (* ptr[3])() says that ptr is an array of pointers to functions that takes no arguments and returns the type int. 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. Similarly, the other two array elements also get initialized with the addresses of the functions bbb and ccc. Since ptr[2] contains the address of the function ccc, the call to the function ptr[2]() is same as calling ccc(). So it results in printing "bye".

127)main(){int i=5;printf(“%d”,i=++i ==6);}

19

Page 192: FRP C & DS dumps

Answer:1

Explanation:The expression can be treated as i = (++i==6), because == is of higher precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.

128) main(){

char p[ ]="%d\n";p[1] = 'c';printf(p,65);

}Answer:

AExplanation:

Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.

129) void ( * abc( int, void ( *def) () ) ) ();

Answer:: abc is a ptr to a function which takes 2 parameters .(a). an integer variable.(b). a ptrto a funtion which returns void. the return type of the function is void.

Explanation:Apply the clock-wise rule to find the result.

130) main(){while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”);}Answer:

No outputExplanation:

19

Page 193: FRP C & DS dumps

Ending the string constant with \0 explicitly makes no difference. So “some” and “some\0” are equivalent. So, strcmp returns 0 (false) hence breaking out of the while loop.

131) main(){

char str1[] = {‘s’,’o’,’m’,’e’};char str2[] = {‘s’,’o’,’m’,’e’,’\0’};while (strcmp(str1,str2)) printf(“Strings are not equal\n”);

}Answer:

“Strings are not equal”“Strings are not equal”….

Explanation:If a string constant is initialized explicitly with characters, ‘\0’ is not appended automatically to the string. Since str1 doesn’t have null termination, it treats whatever the values that are in the following positions as part of the string until it randomly reaches a ‘\0’. So str1 and str2 are not the same, hence the result.

132) main()

{int i = 3;for (;i++=0;) printf(“%d”,i);

}

Answer:Compiler Error: Lvalue required.

Explanation:As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation.

133) void main()

{int *mptr, *cptr;mptr = (int*)malloc(sizeof(int));

19

Page 194: FRP C & DS dumps

printf(“%d”,*mptr);int *cptr = (int*)calloc(sizeof(int),1);printf(“%d”,*cptr);

}Answer:

garbage-value 0Explanation:

The memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros.

134) void main(){

static int i;while(i<=10)(i>2)?i++:i--;printf(“%d”, i);

}Answer:

32767Explanation:

Since i is static it is initialized to 0. Inside the while loop the conditional operator evaluates to false, executing i--. This continues till the integer value rotates to positive value (32767). The while condition becomes false and hence, comes out of the while loop, printing the i value.

135) main(){

int i=10,j=20;j = i, j?(i,j)?i:j:j;printf("%d %d",i,j);

}

Answer:10 10

Explanation:The Ternary operator ( ? : ) is equivalent for if-then-else

statement. So the question can be written as:if(i,j)

{

19

Page 195: FRP C & DS dumps

if(i,j) j = i;else j = j;}

elsej = j;

136) 1. const char *a;2. char* const a; 3. char const *a;-Differentiate the above declarations.

Answer:1. 'const' applies to char * rather than 'a' ( pointer to a constant char )

*a='F' : illegala="Hi" : legal

2. 'const' applies to 'a' rather than to the value of a (constant pointer to char )

*a='F' : legala="Hi" : illegal

3. Same as 1.

137) main(){

int i=5,j=10;i=i&=j&&10;printf("%d %d",i,j);

}

Answer:1 10

Explanation:The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.

19

Page 196: FRP C & DS dumps

138) main(){

int i=4,j=7;j = j || i++ && printf("YOU CAN");printf("%d %d", i, j);

}

Answer:4 1

Explanation:The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to zero itself means that the expression’s truth value is 1. 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.Similarly when && operator is involved in an expression, when any of the operands become false, the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated. false && (anything) => false where (anything) will not be

evaluated.

139) main(){

register int a=2;printf("Address of a = %d",&a);printf("Value of a = %d",a);

}Answer:

Compier Error: '&' on register variableRule to Remember:

& (address of ) operator cannot be applied on register variables.

140) main(){

float i=1.5;switch(i)

19

Page 197: FRP C & DS dumps

{case 1: printf("1");case 2: printf("2");default : printf("0");

}}Answer:

Compiler Error: switch expression not integralExplanation:

Switch statements can be applied only to integral types.

141) main(){

extern i;printf("%d\n",i);{

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

}}Answer:

Linker Error : Unresolved external symbol iExplanation:

The identifier i is available in the inner block and so using extern has no use in resolving it.

142) main(){

int a=2,*f1,*f2;f1=f2=&a;*f2+=*f2+=a+=2.5;printf("\n%d %d %d",a,*f1,*f2);

}Answer:

16 16 16Explanation:

f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.

143) main()

19

Page 198: FRP C & DS dumps

{char *p="GOOD";char a[ ]="GOOD";printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p));printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));

}Answer:

sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4sizeof(a) = 5, strlen(a) = 4

Explanation:sizeof(p) => sizeof(char*) => 2sizeof(*p) => sizeof(char) => 1Similarly,sizeof(a) => size of the character array => 5When 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. 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.

144) #define DIM( array, type) sizeof(array)/sizeof(type)main(){

int arr[10];printf(“The dimension of the array is %d”, DIM(arr, int));

}Answer:

10 Explanation:

The size of integer array of 10 elements is 10 * sizeof(int). The macro expands to sizeof(arr)/sizeof(int) => 10 * sizeof(int) / sizeof(int) => 10.

145) int DIM(int array[]) {return sizeof(array)/sizeof(int );}main(){

19

Page 199: FRP C & DS dumps

int arr[10];printf(“The dimension of the array is %d”, DIM(arr));

}Answer:

1 Explanation:

Arrays cannot be passed to functions as arguments and only the pointers can be passed. So the argument is equivalent to int * array (this is one of the very few places where [] and * usage are equivalent). The return statement becomes, sizeof(int *)/ sizeof(int) that happens to be equal in this case.

146) main(){

static int a[3][3]={1,2,3,4,5,6,7,8,9};int i,j;static *p[]={a,a+1,a+2};for(i=0;i<3;i++){

for(j=0;j<3;j++)printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));

}}Answer:

1 1 1 12 4 2 43 7 3 74 2 4 25 5 5 56 8 6 87 3 7 38 6 8 69 9 9 9

Explanation:*(*(p+i)+j) is equivalent to p[i][j].

147) main(){

void swap();

19

Page 200: FRP C & DS dumps

int x=10,y=8; swap(&x,&y);printf("x=%d y=%d",x,y);

}void swap(int *a, int *b){ *a ^= *b, *b ^= *a, *a ^= *b; }Answer:

x=10 y=8Explanation:

Using ^ like this is a way to swap two variables without using a temporary variable and that too in a single statement.Inside main(), void swap(); means that swap is a function that may take any number of arguments (not no arguments) and returns nothing. So this doesn’t issue a compiler error by the call swap(&x,&y); that has two arguments. This convention is historically due to pre-ANSI style (referred to as Kernighan and Ritchie style) style of function declaration. In that style, the swap function will be defined as follows,

void swap()int *a, int *b{ *a ^= *b, *b ^= *a, *a ^= *b; }

where the arguments follow the (). So naturally the declaration for swap will look like, void swap() which means the swap can take any number of arguments.

148) main(){

int i = 257;int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}Answer:

1 1 Explanation:

20

Page 201: FRP C & DS dumps

The integer value 257 is stored in the memory as, 00000001 00000001, so the individual bytes are taken by casting it to char * and get printed.

149) main(){

int i = 258;int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}Answer:

2 1 Explanation:

The integer value 257 can be represented in binary as, 00000001 00000001. Remember that the INTEL machines are ‘small-endian’ machines. 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. The integer value 258 is stored in memory as: 00000001 00000010.

150) main(){

int i=300;char *ptr = &i;*++ptr=2;printf("%d",i);

}Answer:

556Explanation:

The integer value 300 in binary notation is: 00000001 00101100. It is stored in memory (small-endian) as: 00101100 00000001. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. So the integer corresponding to it is 00000010 00101100 => 556.

151) #include <stdio.h>main(){

char * str = "hello";

20

Page 202: FRP C & DS dumps

char * ptr = str;char least = 127;while (*ptr++)

least = (*ptr<least ) ?*ptr :least;printf("%d",least);

}Answer:

0Explanation:

After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘\0’. So the value of ‘str’ is less than that of ‘least’. So the value of ‘least’ finally is 0.

152) Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?Answer:

(char*(*)( )) (*ptr[N])( );

153) main(){

struct student {

char name[30];struct date dob;

}stud;struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}Answer:

Compiler Error: Undefined structure dateExplanation:

Inside the struct definition of ‘student’ the member of type struct date is given. 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.

20

Page 203: FRP C & DS dumps

154) main(){

struct date;struct student

{char name[30];struct date dob;

}stud;struct date

{ int day,month,year; };scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}Answer:

Compiler Error: Undefined structure dateExplanation:

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.

155) There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong?void main(){

struct student{char name[30], rollno[6];}stud;FILE *fp = fopen(“somefile.dat”,”r”);while(!feof(fp)) {

fread(&stud, sizeof(stud), 1 , fp);puts(stud.name);

}}Explanation:

fread reads 10 records and prints the names successfully. It will return EOF only when fread tries to read another

20

Page 204: FRP C & DS dumps

record and fails reading EOF (and returning EOF). So it prints the last record again. After this only the condition feof(fp) becomes false, hence comes out of the while loop.

156) Is there any difference between the two declarations, 1. int foo(int *arr[]) and2. int foo(int *arr[2])Answer:

No Explanation:

Functions can only pass pointers and not arrays. The numbers that are allowed inside the [] is just for more readability. So there is no difference between the two declarations.

157) What is the subtle error in the following code segment?void fun(int n, int arr[]){

int *p=0;int i=0;while(i++<n)

p = &arr[i];*p = 0;

}Answer & Explanation:

If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program).

158) What is wrong with the following code? int *foo(){

int *s = malloc(sizeof(int)100);assert(s != NULL);return s;

}Answer & Explanation:

20

Page 205: FRP C & DS dumps

assert macro should be used for debugging and finding out bugs. The check s != NULL is for error/exception handling and for that assert shouldn’t be used. A plain if and the corresponding remedy statement has to be given.

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. In assert, 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.

Rule to Remember:Don’t use expressions that have side-effects in assert

statements.

160) void main(){int *i = 0x400; // i points to the address 400*i = 0; // set the value of memory location pointed by i;}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. This type of pointer in which the non-availability of the implementation of the referenced location is known as 'incomplete type'.

161) #define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort())

void main(){int i = 10;if(i==0) assert(i < 100); else

20

Page 206: FRP C & DS dumps

printf("This statement becomes else for if in assert macro");}Answer:

No outputExplanation:The else part in which the printf is there becomes the else for if in the assert macro. Hence nothing is printed. The solution is to use conditional operator instead of if statement,#define assert(cond) ((cond)?(0): (fprintf (stderr, "assertion failed: \ %s, file %s, line %d \n",#cond, __FILE__,__LINE__), 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,#define assert(cond) { \if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \

n",#cond,\ __FILE__,__LINE__), abort()) \}

162) Is the following code legal?struct a {

int x; struct a b;

}Answer:

NoExplanation:

Is it not legal for a structure to contain a member that is of the same

type as in this case. Because this will cause the structure declaration to be recursive without end.

163) Is the following code legal?struct a {

int x;

20

Page 207: FRP C & DS dumps

struct a *b; }Answer:

Yes.Explanation:

*b is a pointer to type struct a and so is legal. The compiler knows, the size of the pointer to a structure even before the size of the structureis determined(as you know the pointer to any type is of same size). This type of structures is known as ‘self-referencing’ structure.

164) Is the following code legal?typedef struct a {

int x; aType *b;

}aTypeAnswer:

NoExplanation:

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;struct a{

int x;aType *b;

};Answer:

YesExplanation:

The typename aType is known at the point of declaring the structure, because it is already typedefined.

166) Is the following code legal?void main(){

20

Page 208: FRP C & DS dumps

typedef struct a aType;aType someVariable;struct a

{ int x; aType *b;

};}Answer:

NoExplanation:

When the declaration,typedef struct a aType;is encountered body of struct a is not known. This is known as ‘incomplete types’.

167) void main()

{printf(“sizeof (void *) = %d \n“, sizeof( void *));printf(“sizeof (int *) = %d \n”, sizeof(int *));printf(“sizeof (double *) = %d \n”, sizeof(double *));printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *));}Answer :

sizeof (void *) = 2sizeof (int *) = 2sizeof (double *) = 2sizeof(struct unknown *) = 2

Explanation:The pointer to any type is of same size.

168) char inputString[100] = {0};To get string input from the keyboard which one of the following is

better?1) gets(inputString)2) fgets(inputString, sizeof(inputString), fp)

Answer & Explanation:The second one is better because gets(inputString) doesn't know the size of the string passed and so, if a very big input (here, more than 100 chars) the charactes will be written past the input

20

Page 209: FRP C & DS dumps

string. When fgets is used with stdin performs the same operation as gets but is safe.

169) Which version do you prefer of the following two,1) printf(“%s”,str); // or the more curt one2) printf(str);

Answer & Explanation:Prefer the first one. If the str contains any format characters like %d then it will result in a subtle bug.

170) void main(){

int i=10, j=2;int *ip= &i, *jp = &j;int k = *ip/*jp;printf(“%d”,k);

}Answer:

Compiler Error: “Unexpected end of file in comment started in line 5”.Explanation:

The programmer intended to divide two integers, but by the “maximum munch” rule, the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. To force what is intended by the programmer,

int k = *ip/ *jp;// give space explicity separating / and * //orint k = *ip/(*jp);// put braces to force the intention

will solve the problem.

171) void main(){char ch;for(ch=0;ch<=127;ch++)printf(“%c %d \n“, ch, ch);}Answer:

20

Page 210: FRP C & DS dumps

Implementaion dependentExplanation:

The char type may be signed or unsigned by default. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. Thus ch is always smaller than 127.

172) Is this code legal?int *ptr; ptr = (int *) 0x400;Answer:

YesExplanation:

The pointer ptr will point at the integer in the memory location 0x400.

173) main(){

char a[4]="HELLO";printf("%s",a);

}Answer:

Compiler error: Too many initializersExplanation:

The array a is of size 4 but the string constant requires 6 bytes to get stored.

174) main(){

char a[4]="HELL";printf("%s",a);

}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.

21

Page 211: FRP C & DS dumps

175) main(){

int a=10,*j;void *k; j=k=&a;

j++; k++;

printf("\n %u %u ",j,k);} Answer:

Compiler error: Cannot increment a void pointerExplanation:

Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type. No pointer arithmetic can be done on it and you cannot apply indirection operator (*) on void pointers.

176) main(){

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

int i;

177) Printf can be implemented by using __________ list.Answer:

Variable length argument lists178) char *someFun()

{char *temp = “string constant";return temp;}int main(){

21

Page 212: FRP C & DS dumps

puts(someFun());}

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, so this doesn’t lead to dangling pointers.

179) char *someFun1(){char temp[ ] = “string";return temp;}char *someFun2(){char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};return temp;}int main(){puts(someFun1());puts(someFun2());}

Answer:Garbage values.

Explanation:Both the functions suffer from the problem of dangling pointers. In

someFun1() temp is a character array and so the space for it is allocated in heap and is initialized with character string “string”. This is created dynamically as the function is called, 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. The function someFun2() also suffers from the same problem but the problem can be easily identified in this case.

C AptitudeAptitude

21

Page 213: FRP C & DS dumps

Note : All the programs are tested under Turbo C/C++ compilers. It is assumed that,

Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.

The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

Predict the output or error(s) for the following:

26.void main(){

int const * p=5;printf("%d",++(*p));

}Answer:

Compiler error: Cannot modify a constant value. Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

27.main(){

char s[ ]="man";int i;for(i=0;s[ i ];i++)printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}Answer:

mmmm aaaa nnnn

Explanation:s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the

same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

21

Page 214: FRP C & DS dumps

28.main(){

float me = 1.1;double you = 1.1;if(me==you)

printf("I love U");else

printf("I hate U");}

Answer: I hate U

Explanation:For floating point numbers (float, double, long double) the

values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.

Rule of Thumb: Never compare or at-least be cautious when using floating point

numbers with relational operators (== , >, <, <=, >=,!= ) .

29.main(){static int var = 5;printf("%d ",var--);if(var)

main();}Answer:

5 4 3 2 1 Explanation:

When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.

30.main()

21

Page 215: FRP C & DS dumps

{ int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) {

printf(" %d ",*c); ++q; } for(j=0;j<5;j++){

printf(" %d ",*p);++p; }

}Answer: 2 2 2 2 2 2 3 4 6 5

Explanation: Initially pointer c is assigned to both p and q. In the first loop,

since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.

31.main(){

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

}

Answer: Linker Error : Undefined symbol '_i'

Explanation: extern storage class in the following declaration, extern int i;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. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .

32.main(){

int i=-1,j=-1,k=0,l=2,m;m=i++&&j++&&k++||l++;printf("%d %d %d %d %d",i,j,k,l,m);

}

21

Page 216: FRP C & DS dumps

Answer: 0 0 1 3 1

Explanation :Logical operations always give a result of 1 or 0 . And also the

logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

33.main(){

char *p;printf("%d %d ",sizeof(*p),sizeof(p));

}

Answer: 1 2

Explanation:The sizeof() operator gives the number of bytes taken by its

operand. P is a character pointer, which needs one byte for storing its value (a character). 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.main(){

int i=3;switch(i) { default:printf("zero"); case 1: printf("one");

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

break; case 3: printf("three");

break; }

21

Page 217: FRP C & DS dumps

}Answer :

threeExplanation :

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

35.main(){

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

Answer: fff0

Explanation :-1 is internally represented as all 1's. When left shifted four

times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

36.main(){

char string[]="Hello World";display(string);

}void display(char *string){

printf("%s",string);}

Answer:Compiler Error : Type mismatch in redeclaration of function

display Explanation :

In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

37.main()

21

Page 218: FRP C & DS dumps

{int c=- -2;printf("c=%d",c);

}Answer:

c=2; Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.

Note: However you cannot give like --2. Because -- operator can only

be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

38.#define int charmain(){

int i=65;printf("sizeof(i)=%d",sizeof(i));

}Answer:

sizeof(i)=1Explanation:

Since the #define replaces the string int by the macro char

39.main(){

int i=10;i=!i>14;printf("i=%d",i);

}Answer:

i=0 Explanation:

In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

40.#include<stdio.h>main()

21

Page 219: FRP C & DS dumps

{char s[]={'a','b','c','\n','c','\0'};char *p,*str,*str1;p=&s[3];str=p;str1=s;printf("%d",++*p + ++*str1-32);

}Answer:

77

Explanation:p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p

is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.

Now performing (11 + 98 – 32), we get 77("M"); So we get the output 77 :: "M" (Ascii is 77).

41.#include<stdio.h>main(){

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };int *p,*q;p=&a[2][2][2];*q=***a;printf("%d----%d",*p,*q);

}Answer:

SomeGarbageValue---1Explanation:

p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.

42.#include<stdio.h>main()

21

Page 220: FRP C & DS dumps

{struct xx{ int x=3; char name[]="hello"; };struct xx *s;printf("%d",s->x);printf("%s",s->name);

}Answer:

Compiler ErrorExplanation:

You should not initialize variables in declaration

43.#include<stdio.h>main(){

struct xx{

int x;struct yy{

char s;struct xx *p;

};struct yy *q;

};}

Answer:Compiler Error

Explanation:The structure yy is nested within structure xx. Hence, the

elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

44.main(){

22

Page 221: FRP C & DS dumps

printf("\nab");printf("\bsi");printf("\rha");

}Answer:

haiExplanation:

\n - newline\b - backspace\r - linefeed

45.main(){

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

}Answer:

45545Explanation:

The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

46.#define square(x) x*xmain(){

int i;i = 64/square(4);printf("%d",i);

}Answer:

64

Explanation:the macro call square(4) will substituted by 4*4 so the

expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64 47.main()

22

Page 222: FRP C & DS dumps

{char *p="hai friends",*p1;p1=p;while(*p!='\0') ++*p++;printf("%s %s",p,p1);

}Answer:

ibj!gsjfoetExplanation:

++*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 ; is encountered the location will be incremented that is p++ will be

executedHence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by executing ++*p and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so on. Similarly blank space is converted to ‘!’. Thus, we obtain value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything.

48.#include <stdio.h>#define a 10main(){

#define a 50printf("%d",a);

}Answer:

50Explanation:

The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

49.#define clrscr() 100main(){

clrscr();printf("%d\n",clrscr());

}Answer:

22

Page 223: FRP C & DS dumps

100Explanation:

Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input program to compiler looks like this :

main(){ 100; printf("%d\n",100);}

Note:100; is an executable statement but with no action. So it doesn't

give any problem

50.main(){

printf("%p",main);}

Answer:Some address will be printed.

Explanation: Function names are just addresses (just like array names are

addresses).main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.

27) main(){clrscr();}clrscr();

Answer:No output/error

Explanation:The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).

22

Page 224: FRP C & DS dumps

28) enum colors {BLACK,BLUE,GREEN} main(){ printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1);}Answer:

0..1..2Explanation:

enum assigns numbers starting from 0, if not explicitly defined.

29) void main(){ char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }Answer:

4..2 Explanation: the second pointer is of char type and not a far pointer

30) main(){ int i=400,j=300; printf("%d..%d");}Answer:

400..300Explanation:

printf takes the values of the first two assignments of the program. Any number of printf's may be given. All of them take

22

Page 225: FRP C & DS dumps

only the first two values. If more number of assignments given in the program,then printf will take garbage values.

31) main(){ char *p; p="Hello"; printf("%c\n",*&*p);}Answer:

H Explanation:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.

32) main(){ int i=1; while (i<=5) { printf("%d",i); if (i>2)

goto here; i++; }}fun(){ here: printf("PP");}Answer:

Compiler error: Undefined label 'here' in function mainExplanation:

Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function fun() Hence it is not visible in function main.

22

Page 226: FRP C & DS dumps

33) main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]);}Answer:

Compiler error: Lvalue required in function mainExplanation:

Array names are pointer constants. So it cannot be modified.

34) void main(){

int i=5;printf("%d",i++ + ++i);

}Answer:

Output Cannot be predicted exactly.Explanation:

Side effects are involved in the evaluation of i

35) void main(){

int i=5;printf("%d",i+++++i);

}Answer:

Compiler Error Explanation:

The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators.

36) #include<stdio.h>

22

Page 227: FRP C & DS dumps

main(){int i=1,j=2;switch(i) { case 1: printf("GOOD");

break; case j: printf("BAD"); break; }}Answer:

Compiler Error: Constant expression required in function main.Explanation:

The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).

Note:Enumerated types can be used in case statements.

37) main(){int i;printf("%d",scanf("%d",&i)); // value 10 is given as input here}Answer:

1Explanation:

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.

38) #define f(g,g2) g##g2main(){int var12=100;printf("%d",f(var,12));}Answer:

100

22

Page 228: FRP C & DS dumps

39) main(){int i=0; for(;i++;printf("%d",i)) ;

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

1Explanation:

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).

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);}Answer:

MExplanation:

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(){

22

Page 229: FRP C & DS dumps

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 ErrorExplanation:

Initialization should not be done for structure members inside the structure declaration

42) #include<stdio.h>main(){struct xx { int x; struct yy { char s; struct xx *p; };

struct yy *q; }; }

Answer:Compiler Error

Explanation:in the end of nested structure yy a member have to be declared.

43) main(){ extern int i; i=20; printf("%d",sizeof(i));}

22

Page 230: FRP C & DS dumps

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.

44) 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.

45) main(){ extern out; printf("%d", out);} int out=100;Answer:

100Explanation:

This is the correct way of writing the previous program.

46) main(){ show();}void show(){ printf("I'm the greatest");

23

Page 231: FRP C & DS dumps

}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, 2114, 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( )

23

Page 232: FRP C & DS dumps

{ int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) {

printf(“%d” ,*a); a++;

} 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:

111222

23

Page 233: FRP C & DS dumps

333344

Explanation:Let us consider the array and the two pointers with some address

a0 1 2 3 4

100 102 104 106 108 p

100 102 104 106 108 1000 1002 1004 1006 1008

ptr10002000

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));

23

Page 234: FRP C & DS dumps

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 asM O U S E \0When 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 \0The third input starts filling from the location 102M T V I R T U A L \0This is the final value stored .The first printf prints the values at the position q, q+1 and q+2

= M T VThe second printf prints three strings starting from locations q,

q+1, q+2 i.e MTVIRTUAL, TVIRTUAL and VIRTUAL.

51) main( )

{ 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:

g20fyExplanation:

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

23

Page 235: FRP C & DS dumps

from second printf is ‘20’. The third printf statement type casts it to print the string from the 4th 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:

ckExplanation:

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’.

53) main(){ int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) {

printf(“%s\n”,x);x++;

} }Answer:

(blank space)

23

Page 236: FRP C & DS dumps

irlrll

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.

54) 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 NDEBUGand this will disable all the assertions from the source code.

Assertionis a good debugging tool to make use of.

55) main()

{int i=-1;+i;printf("i = %d, +i = %d \n",i,+i);}Answer:

23

Page 237: FRP C & DS dumps

i = -1, +i = -1Explanation:

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.

59) 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.

23

Page 238: FRP C & DS dumps

60) 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 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.

62) main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));}Answer:

2 5 5Explanation:

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'

23

Page 239: FRP C & DS dumps

termination character). The third sizeof is similar to the second one.

63) main(){char not;not=!2;printf("%d",not);}Answer:

0Explanation:

! 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.

64) #define FALSE -1#define TRUE 1#define NULL 0main() { if(NULL)

puts("NULL"); else if(FALSE)

puts("TRUE"); else

puts("FALSE"); }Answer:

TRUEExplanation:

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");

23

Page 240: FRP C & DS dumps

}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 TRUEExplanation:

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".

66) main(){int y;scanf("%d",&y); // input given is 2000if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year");else printf("%d is not a leap year");}Answer:

2000 is a leap yearExplanation:

An ordinary program to check if leap year or not.

67) #define max 5#define int arr1[max]main(){typedef char arr2[max];

24

Page 241: FRP C & DS dumps

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);}Answer:

30,20,10Explanation:

'{' introduces new block and thus new scope. In the innermost block i is declared as,

const volatile unsigned

24

Page 242: FRP C & DS dumps

which is a valid declaration. i is assumed of type int. So printf prints 30. In the next block, i has value 20 and so printf prints 20. In the outermost block, i is declared as extern, so no storage space is allocated for it. After compilation is over the linker resolves it to global variable i (since it is the only variable visible there). So it prints i's value as 10.

69) main(){ int *j; { int i=10; j=&i; } printf("%d",*j);}Answer:

10Explanation:

The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.

70) main(){int i=-1;-i;printf("i = %d, -i = %d \n",i,-i);}Answer:

i = -1, -i = 1Explanation:

-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i. After that the value of the expression -i = -(-1) is printed.

71) #include<stdio.h>main()

24

Page 243: FRP C & DS dumps

{ const int i=4; float j; j = ++i; printf("%d %f", i,++j); }Answer:

Compiler error Explanation:

i is a constant. you cannot change the value of constant

72) #include<stdio.h>main(){ int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q);}Answer:

garbagevalue..1Explanation:

p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.

73) #include<stdio.h>main() { register i=5; char j[]= "hello"; printf("%s %d",j,i);}Answer:

hello 5Explanation:

24

Page 244: FRP C & DS dumps

if you declare i as register compiler will treat it as ordinary integer and it will take integer value. i value may be stored either in register or in memory.

74) main(){ int i=5,j=6,z; printf("%d",i+++j); }Answer:

11Explanation:

the expression i+++j is treated as (i++ + j)

76) struct aaa{struct aaa *prev;int i;struct aaa *next;};

main(){ struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x);}Answer:

2Explanation:

above all statements form a double circular linked list;abc.next->next->prev->next->i this one points to "ghi" node the value of at particular node is 2.

77) struct point

24

Page 245: FRP C & DS dumps

{ int x; int y; };struct point origin,*pp;main(){pp=&origin;printf("origin is(%d%d)\n",(*pp).x,(*pp).y);printf("origin is (%d%d)\n",pp->x,pp->y);} Answer:

origin is(0,0)origin is(0,0)

Explanation:pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.

Note: Since structure point is globally declared x & y are initialized

as zeroes

78) main(){ int i=_l_abc(10);

printf("%d\n",--i);}int _l_abc(int i){ return(i++);}Answer:

9Explanation:

return(i++) it will first return i and then increments. i.e. 10 will be returned.

79) main(){ char *p; int *q;

24

Page 246: FRP C & DS dumps

long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r);}Answer:

0001...0002...0004Explanation:

++ operator when applied to pointers increments address according to their corresponding data-types.

80) main(){ char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x);}convert(z){ return z-32;}

Answer: Compiler error

Explanation:declaration of convert and format of getc() are wrong.

81) main(int argc, char **argv){ printf("enter the character"); getchar(); sum(argv[1],argv[2]);}sum(num1,num2)int num1,num2;{

24

Page 247: FRP C & DS dumps

return num1+num2;}Answer:

Compiler error.Explanation:

argv[1] & argv[2] are strings. They are passed to the function sum without converting it to integer values.

82) # include <stdio.h>int one_d[]={1,2,3};main(){ int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr);}Answer:

garbage valueExplanation:

ptr pointer is pointing to out of the array range of one_d.

83) # include<stdio.h>aaa() { printf("hi"); }bbb(){ printf("hello"); }ccc(){ printf("bye"); }main(){ int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2]();}

24

Page 248: FRP C & DS dumps

Answer:bye

Explanation:ptr is array of pointers to functions of return type int.ptr[0] is assigned to address of the function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. ptr[2]() is in effect of writing ccc(), since ptr[2] points to ccc.

85) #include<stdio.h>main(){FILE *ptr;char i;ptr=fopen("zzz.c","r");while((i=fgetch(ptr))!=EOF)

printf("%c",i);}Answer:

contents of zzz.c followed by an infinite loop Explanation:

The condition is checked against EOF, it should be checked against NULL.

86) main(){ int i =0;j=0; if(i && j++) printf("%d..%d",i++,j);printf("%d..%d,i,j);}Answer:

0..0 Explanation:

The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. The values of i and j remain unchanged and get printed.

87) main()

{

24

Page 249: FRP C & DS dumps

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

Answer:1000

Explanation:Normally the return value from the function is through the information from the accumulator. Here _AH is the pseudo global variable denoting the accumulator. Hence, the value of the accumulator is set 1000 so the function returns value 1000.

88) int i; main(){

int t;for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--);

}// If the inputs are 0,1,2,3 find the o/pAnswer: 4--0

3--12--2

Explanation:Let us assume some x= scanf("%d",&i)-t the values during

execution will be,

t i x 4 0 -4 3 1 -2 2 2 0

89) main(){

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y)

24

Page 250: FRP C & DS dumps

printf("hello"); }Answer:

hello Explanation:

The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.

90) main(){ unsigned int i; for(i=1;i>-2;i--)

printf("c aptitude");}Explanation:

i is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.

91) In the following pgm add a stmt in the function fun such that the address of

'a' gets stored in 'j'.main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }Answer:

*k = &aExplanation:

The argument of the function is a pointer to a pointer. 92) What are the following notations of defining functions known as?

25

Page 251: FRP C & DS dumps

i. int abc(int a,float b) { /* some code */

}ii. int abc(a,b) int a; float b;

{ /* some code*/ }

Answer:i. ANSI C notationii. Kernighan & Ritche notation

93) main(){char *p;p="%d\n";

p++; p++; printf(p-2,300);

}Answer:

300Explanation:

The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

94) main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a);}abc(char a[]){ a++;

printf("%c",*a); a++; printf("%c",*a);}Explanation:

25

Page 252: FRP C & DS dumps

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.

95) func(a,b)

int a,b;{

return( a= (a==b) );}main(){int process(),func();printf("The value of process is %d !\n ",process(func,3,6));}process(pf,val1,val2)int (*pf) ();int val1,val2;{return((*pf) (val1,val2)); }Answer:

The value if process is 0 !Explanation:

The function 'process' has 3 parameters - 1, a pointer to another function 2 and 3, integers. When this function is invoked from main, the following substitutions for formal parameters take place: func for pf, 3 for val1 and 6 for val2. This function returns the result of the operation performed by the function 'func'. The function func has two integer parameters. The formal parameters are substituted as 3 for a and 6 for b. since 3 is not equal to 6, a==b returns 0. therefore the function returns 0 which in turn is returned by the function 'process'.

96) void main(){

static int i=5;if(--i){

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

}}

25

Page 253: FRP C & DS dumps

Answer: 0 0 0 0

Explanation:The variable "I" is declared as static, hence memory for I will

be allocated for only once, as it encounters the statement. The function main() will be called recursively unless I becomes equal to 0, and since main() is recursively called, so the value of static I ie., 0 will be printed every time the control is returned.

97) void main(){

int k=ret(sizeof(float));printf("\n here value is %d",++k);

}int ret(int ret){

ret += 2.5;return(ret);

}Answer:

Here value is 7Explanation:

The int ret(int ret), ie., the function name and the argument name can be the same.

Firstly, the function ret() is called in which the sizeof(float) ie., 4 is passed, after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main() it is printed after and preincrement.

98) void main(){

char a[]="12345\0";int i=strlen(a);printf("here in 3 %d\n",++i);

}Answer:

here in 3 6Explanation:

25

Page 254: FRP C & DS dumps

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.

99) void main(){

unsigned giveit=-1;int gotit;printf("%u ",++giveit);printf("%u \n",gotit=--giveit);

}Answer:

0 65535

100) void main(){

int i;char a[]="\0";if(printf("%s\n",a))

printf("Ok here \n");else

printf("Forget it\n");}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, thus "Ok here" is printed.

101) void main()

{void *v;int integer=2;int *i=&integer;v=i;

25

Page 255: FRP C & DS dumps

printf("%d",(int*)*v);}Answer:

Compiler Error. We cannot apply indirection on type void*.Explanation:

Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void pointers are normally used for, 4. Passing generic pointers to functions and returning such

pointers.5. As a intermediate pointer type.6. Used when the exact pointer type will be known at a later

point of time.

102) void main(){

int i=i++,j=j++,k=k++;printf(“%d%d%d”,i,j,k);

}Answer:

Garbage values.Explanation:

An identifier is available to use in program code from the point of its declaration.

So expressions such as i = i++ are valid statements. The i, j and k are automatic variables and so they contain some garbage value. Garbage in is garbage out (GIGO).

103) void main(){

static int i=i++, j=j++, k=k++;printf(“i = %d j = %d k = %d”, i, j, k);

}Answer:

i = 1 j = 1 k = 1Explanation:

Since static variables are initialized to zero by default.

104) void main()

25

Page 256: FRP C & DS dumps

{while(1){

if(printf("%d",printf("%d")))break;

elsecontinue;

}}Answer:

Garbage valuesExplanation:

The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.

104) main(){

unsigned int i=10;while(i-->=0)

printf("%u ",i);

}Answer:

10 9 8 7 6 5 4 3 2 1 0 65535 65534…..Explanation:

Since i is an unsigned integer it can never become negative. So the expression i-- >=0 will always be true, leading to an infinite loop.

105) #include<conio.h>main(){

int x,y=2,z,a;if(x=y%2) z=2;a=2;printf("%d %d ",z,x);

} Answer:

25

Page 257: FRP C & DS dumps

Garbage-value 0Explanation:

The value of y%2 is 0. This value is assigned to x. 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.

106) main(){

int a[10];printf("%d",*a+1-*a+3);

}Answer:

4 Explanation:

*a and -*a cancels out. The result is as simple as 1 + 3 = 4 !

107) #define prod(a,b) a*bmain() {

int x=3,y=4;printf("%d",prod(x+2,y-1));

}Answer:

10Explanation:

The macro expands and evaluates to as:x+2*y-1 => x+(2*y)-1 => 10

108) main(){

unsigned int i=65000;while(i++!=0);printf("%d",i);

}Answer:

1Explanation:

25

Page 258: FRP C & DS dumps

Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1.

109) main()

{int i=0;while(+(+i--)!=0)

i-=i++;printf("%d",i);

}Answer:

-1

Explanation:Unary + is the only dummy operator in C. So it has no effect on the expression and now the while loop is, while(i--!=0) which is false and so breaks out of while loop. The value –1 is printed due to the post-decrement operator.

113) main()

{float f=5,g=10;enum{i=10,j=20,k=50};printf("%d\n",++k);printf("%f\n",f<<2);printf("%lf\n",f%g);printf("%lf\n",fmod(f,g));

}Answer:

Line no 5: Error: Lvalue requiredLine no 6: Cannot apply leftshift to floatLine no 7: Cannot apply mod to float

Explanation:Enumeration constants cannot be modified, so you cannot apply

++.Bit-wise operators and % operators cannot be applied on float

values.fmod() is to find the modulus values for floats as % operator is

for ints.

25

Page 259: FRP C & DS dumps

110) main(){

int i=10;void pascal f(int,int,int);f(i++,i++,i++);printf(" %d",i);

}void pascal f(integer :i,integer:j,integer :k){

write(i,j,k); }Answer:

Compiler error: unknown type integerCompiler error: undeclared function write

Explanation:Pascal keyword doesn’t mean that pascal code can be used. It

means that the function follows Pascal argument passing mechanism in calling the functions.

111) void pascal f(int i,int j,int k){

printf(“%d %d %d”,i, j, k); }void cdecl f(int i,int j,int k){

printf(“%d %d %d”,i, j, k); }main(){

int i=10;f(i++,i++,i++);printf(" %d\n",i);i=10;f(i++,i++,i++);printf(" %d",i);

}Answer:

10 11 12 1312 11 10 13

25

Page 260: FRP C & DS dumps

Explanation:Pascal argument passing mechanism forces the arguments to be

called from left to right. cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.

112). What is the output of the program given below

main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }Answer

-128Explanation

Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. 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 condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.

113) main()

{ unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }Answerinfinite loopExplanationThe 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.

26

Page 261: FRP C & DS dumps

114) main() {

char i=0; for(;i>=0;i++) ; printf("%d\n",i);

}Answer:

Behavior is implementation dependent.Explanation:

The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.Rule:

You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.

115) Is the following statement a declaration/definition. Find what does it mean?

int (*x)[10];Answer

Definition.x is a pointer to array of(size 10) integers.

Apply clock-wise rule to find the meaning of this definition.

116). What is the output for the program given below

typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }

26

Page 262: FRP C & DS dumps

AnswerCompiler error: Multiple declaration for error

ExplanationThe name error is used in the two meanings. One means

that it is a enumerator constant with value 1. The another use is that it is a type name (due to typedef) for enum errorType. Given a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used:

error g1;g1=error;

// which error it refers in each case?When the compiler can distinguish between usages then

it will not issue error (in pure technical terms, names can only be overloaded in different namespaces).

Note: the extra comma in the declaration,enum errorType{warning, error, exception,}

is not an error. An extra comma is valid and is provided just for programmer’s convenience.

117) typedef struct error{int warning, error,

exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }

Answer1

ExplanationThe three usages of name errors can be distinguishable by the

compiler at any instance, so valid (they are in different namespaces).Typedef struct error{int warning, error, exception;}error;

This error can be used only by preceding the error by struct kayword as in:

struct error someError;typedef struct error{int warning, error, exception;}error;

26

Page 263: FRP C & DS dumps

This can be used only after . (dot) or -> (arrow) operator preceded by the variable name as in :

g1.error =1; printf("%d",g1.error);

typedef struct error{int warning, error, exception;}error;This can be used to define variables without using the preceding struct keyword as in:

error g1;Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid.

NoteThis code is given here to just explain the concept behind. In

real programming don’t use such overloading of names. It reduces the readability of the code. Possible doesn’t mean that we should use it! 118) #ifdef something

int some=0;#endif

main(){

int thing = 0;printf("%d %d\n", some ,thing);

}

Answer:Compiler error : undefined symbol some

Explanation:This is a very simple example for conditional compilation. The name something is not already known to the compiler making the declaration int some = 0;effectively removed from the source code.

119) #if something == 0int some=0;#endif

26

Page 264: FRP C & DS dumps

main(){

int thing = 0;printf("%d %d\n", some ,thing);

}

Answer0 0

ExplanationThis code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.

120). What is the output for the following program

main() {

int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D ==

arr2D[0])) ); }

Answer1

ExplanationThis is due to the close relation between the arrays and pointers. N dimensional arrays are made up of (N-1) dimensional arrays. arr2D is made up of a 3 single arrays that contains 3

integers each .

The name arr2D refers to the beginning of all the 3 arrays. *arr2D refers to the start of the first 1D array (of 3

26

arr2Darr2D[1]

arr2D[2]

arr2D[3]

Page 265: FRP C & DS dumps

integers) that is the same address as arr2D. So the expression (arr2D == *arr2D) is true (1). Similarly, *arr2D is nothing but *(arr2D + 0), adding a zero doesn’t change the value/meaning. Again arr2D[0] is the another way of telling *(arr2D + 0). So the expression (*(arr2D + 0) == arr2D[0]) is true (1). Since both parts of the expression evaluates to true the result is true(1) and the same is printed.

121) void main() {

if(~0 == (unsigned int)-1)printf(“You can answer this if you know how values are represented in memory”);

} Answer

You can answer this if you know how values are represented in memoryExplanation

~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. –1 is represented in unsigned value as all 1’s and so both are equal.

122) int swap(int *a,int *b){ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

}Answer

x = 20 y = 10Explanation

This is one way of swapping two values. Simple checking will help understand this.

26

Page 266: FRP C & DS dumps

123) main(){char *p = “ayqm”;printf(“%c”,++*(p++));}Answer:

b

124) main(){

int i=5; printf("%d",++i++);

} Answer: Compiler error: Lvalue required in function

mainExplanation: ++i yields an rvalue. For postfix ++

to operate an lvalue is required.

125) main(){

char *p = “ayqm”;char c;c = ++*p++;printf(“%c”,c);

}Answer:

bExplanation:

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.

126)int aaa() {printf(“Hi”);}int bbb(){printf(“hello”);}iny ccc(){printf(“bye”);}

main(){int ( * ptr[3]) ();

26

Page 267: FRP C & DS dumps

ptr[0] = aaa;ptr[1] = bbb;ptr[2] =ccc;ptr[2]();

}Answer:

byeExplanation:

int (* ptr[3])() says that ptr is an array of pointers to functions that takes no arguments and returns the type int. 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. Similarly, the other two array elements also get initialized with the addresses of the functions bbb and ccc. Since ptr[2] contains the address of the function ccc, the call to the function ptr[2]() is same as calling ccc(). So it results in printing "bye".

127)main(){int i=5;printf(“%d”,i=++i ==6);}

Answer: 1Explanation: The expression can be treated as i = (++i==6), because

== is of higher precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.

128) main(){

char p[ ]="%d\n";p[1] = 'c';printf(p,65);

}Answer:

AExplanation:

26

Page 268: FRP C & DS dumps

Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.

129) void ( * abc( int, void ( *def) () ) ) ();

Answer:: abc is a ptr to a function which takes 2 parameters .(a). an integer variable.(b). a ptrto a funtion which returns void. the return type of the function is void.

Explanation:Apply the clock-wise rule to find the result.

130) main(){while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”);}Answer:

No outputExplanation:

Ending the string constant with \0 explicitly makes no difference. So “some” and “some\0” are equivalent. So, strcmp returns 0 (false) hence breaking out of the while loop.

131) main(){

char str1[] = {‘s’,’o’,’m’,’e’};char str2[] = {‘s’,’o’,’m’,’e’,’\0’};while (strcmp(str1,str2)) printf(“Strings are not equal\n”);

}Answer:

“Strings are not equal”“Strings are not equal”….

Explanation:If a string constant is initialized explicitly with characters, ‘\0’ is not appended automatically to the string. Since str1 doesn’t

26

Page 269: FRP C & DS dumps

have null termination, it treats whatever the values that are in the following positions as part of the string until it randomly reaches a ‘\0’. So str1 and str2 are not the same, hence the result.

132) main()

{int i = 3;for (;i++=0;) printf(“%d”,i);

}

Answer: Compiler Error: Lvalue required.Explanation:

As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation.

133) void main()

{int *mptr, *cptr;mptr = (int*)malloc(sizeof(int));printf(“%d”,*mptr);int *cptr = (int*)calloc(sizeof(int),1);printf(“%d”,*cptr);

}Answer:

garbage-value 0Explanation:

The memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros.

134) void main(){

static int i;while(i<=10)(i>2)?i++:i--;printf(“%d”, i);

}Answer: 32767Explanation:

26

Page 270: FRP C & DS dumps

Since i is static it is initialized to 0. Inside the while loop the conditional operator evaluates to false, executing i--. This continues till the integer value rotates to positive value (32767). The while condition becomes false and hence, comes out of the while loop, printing the i value.

135) main(){

int i=10,j=20;j = i, j?(i,j)?i:j:j;printf("%d %d",i,j);

}

Answer:10 10

Explanation:The Ternary operator ( ? : ) is equivalent for if-then-else

statement. So the question can be written as:if(i,j)

{if(i,j) j = i;else j = j;}

elsej = j;

136) 1. const char *a;2. char* const a; 3. char const *a;-Differentiate the above declarations.

Answer:1. 'const' applies to char * rather than 'a' ( pointer to a constant char )

*a='F' : illegala="Hi" : legal

27

Page 271: FRP C & DS dumps

2. 'const' applies to 'a' rather than to the value of a (constant pointer to char )

*a='F' : legala="Hi" : illegal

3. Same as 1.

137) main(){

int i=5,j=10;i=i&=j&&10;printf("%d %d",i,j);

}

Answer:1 10Explanation:

The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.

138) main(){

int i=4,j=7;j = j || i++ && printf("YOU CAN");printf("%d %d", i, j);

}

Answer:4 1

Explanation:The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to zero itself means that the expression’s truth value is 1. 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.Similarly when && operator is involved in an expression, when any of the operands become false, the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated.

27

Page 272: FRP C & DS dumps

false && (anything) => false where (anything) will not be evaluated.

139) main(){

register int a=2;printf("Address of a = %d",&a);printf("Value of a = %d",a);

}Answer:

Compier Error: '&' on register variableRule to Remember:

& (address of ) operator cannot be applied on register variables.

140) main(){

float i=1.5;switch(i){

case 1: printf("1");case 2: printf("2");default : printf("0");

}}Answer:

Compiler Error: switch expression not integralExplanation:

Switch statements can be applied only to integral types.

141) main(){

extern i;printf("%d\n",i);{

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

}}Answer: Linker Error : Unresolved external symbol i

27

Page 273: FRP C & DS dumps

Explanation:The identifier i is available in the inner block and so using extern has no use in resolving it.

142) main(){

int a=2,*f1,*f2;f1=f2=&a;*f2+=*f2+=a+=2.5;printf("\n%d %d %d",a,*f1,*f2);

}Answer:

16 16 16Explanation:

f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.

143) main(){

char *p="GOOD";char a[ ]="GOOD";printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p));printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));

}Answer:

sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4sizeof(a) = 5, strlen(a) = 4

Explanation:sizeof(p) => sizeof(char*) => 2sizeof(*p) => sizeof(char) => 1Similarly,sizeof(a) => size of the character array => 5When 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. 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.

144) #define DIM( array, type) sizeof(array)/sizeof(type)

27

Page 274: FRP C & DS dumps

main(){

int arr[10];printf(“The dimension of the array is %d”, DIM(arr, int));

}Answer:

10 Explanation:

The size of integer array of 10 elements is 10 * sizeof(int). The macro expands to sizeof(arr)/sizeof(int) => 10 * sizeof(int) / sizeof(int) => 10.

145) int DIM(int array[]) {return sizeof(array)/sizeof(int );}main(){

int arr[10];printf(“The dimension of the array is %d”, DIM(arr));

}Answer:

1 Explanation:

Arrays cannot be passed to functions as arguments and only the pointers can be passed. So the argument is equivalent to int * array (this is one of the very few places where [] and * usage are equivalent). The return statement becomes, sizeof(int *)/ sizeof(int) that happens to be equal in this case.

146) main(){

static int a[3][3]={1,2,3,4,5,6,7,8,9};int i,j;static *p[]={a,a+1,a+2};for(i=0;i<3;i++){

for(j=0;j<3;j++)printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));

27

Page 275: FRP C & DS dumps

}}Answer:

1 1 1 12 4 2 43 7 3 74 2 4 25 5 5 56 8 6 87 3 7 38 6 8 69 9 9 9

Explanation:*(*(p+i)+j) is equivalent to p[i][j].

147) main(){

void swap();int x=10,y=8; swap(&x,&y);printf("x=%d y=%d",x,y);

}

void swap(int *a, int *b){ *a ^= *b, *b ^= *a, *a ^= *b; }Answer:

x=10 y=8Explanation:

Using ^ like this is a way to swap two variables without using a temporary variable and that too in a single statement.Inside main(), void swap(); means that swap is a function that may take any number of arguments (not no arguments) and returns nothing. So this doesn’t issue a compiler error by the call swap(&x,&y); that has two arguments. This convention is historically due to pre-ANSI style (referred to as Kernighan and Ritchie style) style of function declaration. In that style, the swap function will be defined as follows,

void swap()

27

Page 276: FRP C & DS dumps

int *a, int *b{ *a ^= *b, *b ^= *a, *a ^= *b; }

where the arguments follow the (). So naturally the declaration for swap will look like, void swap() which means the swap can take any number of arguments.

148) main(){

int i = 257;int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}Answer:

1 1 Explanation:

The integer value 257 is stored in the memory as, 00000001 00000001, so the individual bytes are taken by casting it to char * and get printed.

149) main(){

int i = 258;int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}Answer:

2 1 Explanation:

The integer value 257 can be represented in binary as, 00000001 00000001. Remember that the INTEL machines are ‘small-endian’ machines. 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. The integer value 258 is stored in memory as: 00000001 00000010.

150) main(){

int i=300;

27

Page 277: FRP C & DS dumps

char *ptr = &i;*++ptr=2;printf("%d",i);

}Answer:

556Explanation:

The integer value 300 in binary notation is: 00000001 00101100. It is stored in memory (small-endian) as: 00101100 00000001. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. So the integer corresponding to it is 00000010 00101100 => 556.

151) #include <stdio.h>main(){

char * str = "hello";char * ptr = str;char least = 127;while (*ptr++)

least = (*ptr<least ) ?*ptr :least;printf("%d",least);

}Answer:

0Explanation:

After ‘ptr’ reaches the end of the string the value pointed by ‘str’ is ‘\0’. So the value of ‘str’ is less than that of ‘least’. So the value of ‘least’ finally is 0.

152) Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?Answer:

(char*(*)( )) (*ptr[N])( );

153) main(){ struct student

{char name[30];struct date dob;

27

Page 278: FRP C & DS dumps

}stud;struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}Answer:

Compiler Error: Undefined structure dateExplanation:

Inside the struct definition of ‘student’ the member of type struct date is given. 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.

154) main(){

struct date;struct student

{char name[30];struct date dob;

}stud;struct date

{ int day,month,year; };scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}Answer:

Compiler Error: Undefined structure dateExplanation:

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.

155) There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong?

27

Page 279: FRP C & DS dumps

void main(){

struct student{char name[30], rollno[6];}stud;FILE *fp = fopen(“somefile.dat”,”r”);while(!feof(fp)) {

fread(&stud, sizeof(stud), 1 , fp);puts(stud.name);

}}Explanation:

fread reads 10 records and prints the names successfully. It will return EOF only when fread tries to read another record and fails reading EOF (and returning EOF). So it prints the last record again. After this only the condition feof(fp) becomes false, hence comes out of the while loop.

156) Is there any difference between the two declarations, 3. int foo(int *arr[]) and4. int foo(int *arr[2])Answer:

No Explanation:

Functions can only pass pointers and not arrays. The numbers that are allowed inside the [] is just for more readability. So there is no difference between the two declarations.

157) What is the subtle error in the following code segment?void fun(int n, int arr[]){

int *p=0;int i=0;while(i++<n)

p = &arr[i];*p = 0;

27

Page 280: FRP C & DS dumps

}Answer & Explanation:

If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0 may result in problem (may rise to runtime error “NULL pointer assignment” and terminate the program).

158) What is wrong with the following code? int *foo(){

int *s = malloc(sizeof(int)100);assert(s != NULL);return s;

}Answer & Explanation:

assert macro should be used for debugging and finding out bugs. The check s != NULL is for error/exception handling and for that assert shouldn’t be used. A plain if and the corresponding remedy statement has to be given.

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. In assert, 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.

Rule to Remember:Don’t use expressions that have side-effects in assert

statements.

160) void main(){int *i = 0x400; // i points to the address 400*i = 0; // set the value of memory location pointed by i;}Answer:

28

Page 281: FRP C & DS dumps

Undefined behavior Explanation:

The second statement results in undefined behavior because it points to some location whose value may not be available for modification. This type of pointer in which the non-availability of the implementation of the referenced location is known as 'incomplete type'.

161) #define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort())

void main(){int i = 10;if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro");}Answer:

No outputExplanation:The else part in which the printf is there becomes the else for if in the assert macro. Hence nothing is printed. The solution is to use conditional operator instead of if statement,#define assert(cond) ((cond)?(0): (fprintf (stderr, "assertion failed: \ %s, file %s, line %d \n",#cond, __FILE__,__LINE__), 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,#define assert(cond) { \if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \

n",#cond,\ __FILE__,__LINE__), abort()) \}

28

Page 282: FRP C & DS dumps

162) Is the following code legal?struct a { int x;

struct a b; }Answer: NoExplanation:

Is it not legal for a structure to contain a member that is of the same

type as in this case. Because this will cause the structure declaration to be recursive without end.

163) Is the following code legal?struct a {

int x; struct a *b; }Answer:

Yes.Explanation:

*b is a pointer to type struct a and so is legal. The compiler knows, the size of the pointer to a structure even before the size of the structureis determined(as you know the pointer to any type is of same size). This type of structures is known as ‘self-referencing’ structure.

164) Is the following code legal?typedef struct a {

int x; aType *b;

}aTypeAnswer:

NoExplanation:

The typename aType is not known at the point of declaring the structure (forward references are not made for typedefs).

28

Page 283: FRP C & DS dumps

165) Is the following code legal?typedef struct a aType;struct a{

int x;aType *b;

};Answer:

YesExplanation:

The typename aType is known at the point of declaring the structure, because it is already typedefined.

166) Is the following code legal?void main(){

typedef struct a aType;aType someVariable;struct a

{ int x; aType *b;

};}Answer:

NoExplanation:

When the declaration,typedef struct a aType;is encountered body of struct a is not known. This is known as ‘incomplete types’.

167) void main()

{printf(“sizeof (void *) = %d \n“, sizeof( void *));printf(“sizeof (int *) = %d \n”, sizeof(int *));printf(“sizeof (double *) = %d \n”, sizeof(double *));printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *));}Answer :

28

Page 284: FRP C & DS dumps

sizeof (void *) = 2sizeof (int *) = 2sizeof (double *) = 2sizeof(struct unknown *) = 2

Explanation: The pointer to any type is of same size.

168) char inputString[100] = {0};To get string input from the keyboard which one of the following is

better?1) gets(inputString)2) fgets(inputString, sizeof(inputString), fp)

Answer & Explanation:The second one is better because gets(inputString) doesn't know the size of the string passed and so, if a very big input (here, more than 100 chars) the charactes will be written past the input string. When fgets is used with stdin performs the same operation as gets but is safe.

169) Which version do you prefer of the following two,1) printf(“%s”,str); // or the more curt one2) printf(str);

Answer & Explanation:Prefer the first one. If the str contains any format characters like %d then it will result in a subtle bug.

170) void main(){

int i=10, j=2;int *ip= &i, *jp = &j;int k = *ip/*jp;printf(“%d”,k);

}Answer:

Compiler Error: “Unexpected end of file in comment started in line 5”.Explanation:

The programmer intended to divide two integers, but by the “maximum munch” rule, the compiler treats the operator sequence / and * as /* which happens to be the starting of comment. To force what is intended by the programmer,

28

Page 285: FRP C & DS dumps

int k = *ip/ *jp;// give space explicity separating / and * //orint k = *ip/(*jp);// put braces to force the intention

will solve the problem.

171) void main(){char ch;for(ch=0;ch<=127;ch++)printf(“%c %d \n“, ch, ch);}Answer:

Implementaion dependentExplanation:

The char type may be signed or unsigned by default. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. Thus ch is always smaller than 127.

172) Is this code legal?int *ptr; ptr = (int *) 0x400;Answer:

YesExplanation:

The pointer ptr will point at the integer in the memory location 0x400.

173) main(){ char a[4]="HELLO";

printf("%s",a);}Answer:

Compiler error: Too many initializersExplanation:

The array a is of size 4 but the string constant requires 6 bytes to get stored.

174) main()

28

Page 286: FRP C & DS dumps

{ char a[4]="HELL";printf("%s",a);

}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.

175) main(){

int a=10,*j;void *k; j=k=&a;

j++; k++;

printf("\n %u %u ",j,k);} Answer:

Compiler error: Cannot increment a void pointerExplanation:

Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type. No pointer arithmetic can be done on it and you cannot apply indirection operator (*) on void pointers.

176) main(){

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

28

Page 287: FRP C & DS dumps

int i;

177) Printf can be implemented by using __________ list.Answer:

Variable length argument lists178) char *someFun()

{char *temp = “string constant";return temp;}int main(){puts(someFun());}

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, so this doesn’t lead to dangling pointers.

179) char *someFun1(){char temp[ ] = “string";return temp;}char *someFun2(){char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};return temp;}int main(){puts(someFun1());puts(someFun2());}

Answer:Garbage values.

Explanation:

28

Page 288: FRP C & DS dumps

Both the functions suffer from the problem of dangling pointers. In someFun1() temp is a character array and so the space for it is allocated in heap and is initialized with character string “string”. This is created dynamically as the function is called, 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. The function someFun2() also suffers from the same problem but the problem can be easily identified in this case.

28

Page 289: FRP C & DS dumps

C++ Aptitude and OOPS

C++ Aptitude and OOPSNote : All the programs are tested under Turbo C++ 3.0, 4.5 and Microsoft VC++ 6.0 compilers.

It is assumed that, Programs run under Windows environment, The underlying machine is an x86 based system, Program is compiled using Turbo C/C++ compiler.

The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

1) class Sample{public: int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr; } void PrintVal() { cout << "The value is " << *ptr; }};void SomeFunc(Sample x){cout << "Say i am in someFunc " << endl;}int main(){Sample s1= 10;SomeFunc(s1);s1.PrintVal();}

28

Page 290: FRP C & DS dumps

Answer:Say i am in someFunc Null pointer assignment(Run-time error)

Explanation:As the object is passed by value to SomeFunc the destructor of the

object is called when the control returns from the function. So when PrintVal is called it meets up with ptr that has been freed.The solution is to pass the Sample object by reference to SomeFunc:

void SomeFunc(Sample &x){cout << "Say i am in someFunc " << endl;}

because when we pass objects by refernece that object is not destroyed. while returning from the function.

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; base(){ bval=0;} };

class deri:public base { public: int dval; deri(){ dval=1;} };void SomeFunc(base *arr,int size){for(int i=0; i<size; i++,arr++) cout<<arr->bval;cout<<endl;

29

Page 291: FRP C & DS dumps

}

int main(){base BaseArr[5];SomeFunc(BaseArr,5);deri DeriArr[5];SomeFunc(DeriArr,5);}

Answer: 00000 01010

Explanation: The function SomeFunc expects two arguments.The first one is a

pointer to an array of base class objects and the second one is the sizeof the array.The first call of someFunc calls it with an array of bae objects, so it works correctly and prints the bval of all the objects. 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. But that is what the function expects to be sent. So the derived class pointer is promoted to base class pointer and the address is sent to the function. SomeFunc() knows nothing about this and just treats the pointer as an array of base class objects. 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) ).

4) class base { public: void baseFun(){ cout<<"from base"<<endl;} }; class deri:public base { public: void baseFun(){ cout<< "from derived"<<endl;} };void SomeFunc(base *baseObj){

29

Page 292: FRP C & DS dumps

baseObj->baseFun();}int main(){base baseObject;SomeFunc(&baseObject);deri deriObject;SomeFunc(&deriObject);}Answer:

from basefrom base

Explanation:As we have seen in the previous case, SomeFunc expects a pointer to

a base class. Since a pointer to a derived class object is passed, it treats the argument only as a base class pointer and the corresponding base function is called.

5) class base { public: virtual void baseFun(){ cout<<"from base"<<endl;} }; class deri:public base { public: void baseFun(){ cout<< "from derived"<<endl;} };

void SomeFunc(base *baseObj){ baseObj->baseFun();}int main(){base baseObject;SomeFunc(&baseObject);deri deriObject;SomeFunc(&deriObject);}

29

Page 293: FRP C & DS dumps

Answer:from basefrom derived

Explanation:Remember that baseFunc is a virtual function. That means that it

supports run-time polymorphism. So the function corresponding to the derived class object is called.

void main(){

int a, *pa, &ra;pa = &a;ra = a;cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;

}/*Answer :

Compiler Error: 'ra',reference must be initializedExplanation :

Pointers are different from references. One of the main differences is that the pointers can be both initialized and assigned,whereas references can only be initialized. So this code issues an error.*/

const int size = 5;void print(int *ptr){

cout<<ptr[0];}

void print(int ptr[size]){

cout<<ptr[0];}

void main(){

int a[size] = {1,2,3,4,5};int *b = new int(size);

29

Page 294: FRP C & DS dumps

print(a);print(b);

}/*Answer:

Compiler Error : function 'void print(int *)' already has a body

Explanation:Arrays cannot be passed to functions, only pointers (for arrays, base

addresses) can be passed. So the arguments int *ptr and int prt[size] have no difference as function arguments. In other words, both the functoins have the same signature andso cannot be overloaded. */

class some{public:

~some(){

cout<<"some's destructor"<<endl;}

};

void main(){

some s;s.~some();

}/*Answer:

some's destructorsome's destructor

Explanation:Destructors can be called explicitly. Here 's.~some()' explicitly calls

the destructor of 's'. When main() returns, destructor of s is called again,hence the result.*/

29

Page 295: FRP C & DS dumps

#include <iostream.h>

class fig2d{

int dim1;int dim2;

public:fig2d() { dim1=5; dim2=6;}

virtual void operator<<(ostream & rhs);};

void fig2d::operator<<(ostream &rhs){

rhs <<this->dim1<<" "<<this->dim2<<" ";}

/*class fig3d : public fig2d{

int dim3;public:

fig3d() { dim3=7;}virtual void operator<<(ostream &rhs);

};void fig3d::operator<<(ostream &rhs){

fig2d::operator <<(rhs);rhs<<this->dim3;

}*/

void main(){

fig2d obj1;// fig3d obj2;

obj1 << cout;// obj2 << cout;}

29

Page 296: FRP C & DS dumps

/*Answer :

5 6 Explanation:

In this program, the << operator is overloaded with ostream as argument.This enables the 'cout' to be present at the right-hand-side. Normally, 'cout' is implemented as global function, but it doesn't mean that 'cout' is not possible to be overloaded as member function. Overloading << as virtual member function becomes handy when the class in which it is overloaded is inherited, and this becomes available to be overrided. This is as opposed to global friend functions, where friend's are not inherited.*/

class opOverload{public:

bool operator==(opOverload temp);};

bool opOverload::operator==(opOverload temp){if(*this == temp ){

cout<<"The both are same objects\n";return true;

}else{

cout<<"The both are different\n";return false;

}}

void main(){opOverload a1, a2;a1= =a2;

}

Answer : Runtime Error: Stack Overflow

29

Page 297: FRP C & DS dumps

Explanation :Just like normal functions, operator functions can be called

recursively. This program just illustrates that point, by calling the operator == function recursively, leading to an infinite loop.

class complex{double re;double im;

public:complex() : re(1),im(0.5) {}bool operator==(complex &rhs);operator int(){}

};

bool complex::operator == (complex &rhs){if((this->re == rhs.re) && (this->im == rhs.im))

return true;else

return false;}

int main(){complex c1;cout<< c1;

}

Answer : Garbage value

Explanation:The programmer wishes to print the complex object using output

re-direction operator,which he has not defined for his lass.But the compiler instead of giving an error sees the conversion functionand converts the user defined object to standard object and printssome garbage value.

class complex{double re;double im;

29

Page 298: FRP C & DS dumps

public:complex() : re(0),im(0) {}complex(double n) { re=n,im=n;};complex(int m,int n) { re=m,im=n;}void print() { cout<<re; cout<<im;}

};

void main(){complex c3;double i=5;c3 = i;c3.print();

}

Answer: 5,5

Explanation:Though no operator= function taking complex, double is defined, the

double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue.

void main(){

int a, *pa, &ra;pa = &a;ra = a;cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;

}

Answer : Compiler Error: 'ra',reference must be initialized

Explanation : Pointers are different from references. One of the main

differences is that the pointers can be both initialized and assigned,whereas references can only be initialized. So this code issues an error.

Try it Yourself

1) Determine the output of the 'C++' Codelet.

29

Page 299: FRP C & DS dumps

class base{ public :

out() {

cout<<"base "; }

};class deri{ public : out() { cout<<"deri "; } };void main(){ deri dp[3];

base *bp = (base*)dp;for (int i=0; i<3;i++)(bp++)->out();

}

2) Justify the use of virtual constructors and destructors in C++.

3) Each C++ object possesses the 4 member fns,(which can be declared by the programmer explicitly or by the implementation if they are not available). What are those 4 functions?

4) What is wrong with this class declaration?class something{

char *str;public: something(){ st = new char[10]; } ~something() {

delete str; }

};

29

Page 300: FRP C & DS dumps

5) Inheritance is also known as -------- relationship. Containership as ________ 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.

8) Is there anything wrong with this C++ class declaration?class temp{ int value1; mutable int value2; public : void fun(int val)

const{ ((temp*) this)->value1 = 10; value2 = 10; } };

30

Page 301: FRP C & DS dumps

1. What is a modifier?Answer: A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as ‘mutators’.

2. What is an accessor?Answer: An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations

3. Differentiate between a template class and class template.Answer:Template class:

A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.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. It’s jargon for plain classes.

4. When does a name clash occur?Answer: A name clash occurs when a name is defined in more than one place. For example., two different class libraries could give two different classes the same name. If you try to use many class libraries at the same time, there is a fair chance that you will be unable to compile or link the program because of name clashes.

5. Define namespace.Answer: It is a feature in c++ to minimize name collisions in the global name space. 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. Furthermore, the compiler uses the namespace signature for differentiating the definitions.

6. What is the use of ‘using’ declaration.Answer:

30

Page 302: FRP C & DS dumps

A using declaration makes it possible to use a name from a namespace without the scope operator.

7. What is an Iterator class?Answer: A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators:

input iterators, output iterators, forward iterators, bidirectional iterators, random access.An iterator is an entity that gives access to the contents of a container

object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. 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). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class.

The simplest and safest iterators are those that permit read-only access to the contents of a container class. The following code fragment shows how an iterator might appear in code: cont_iter:=new cont_iterator(); x:=cont_iter.next(); while x/=none do ... s(x); ... x:=cont_iter.next(); end; In this example, cont_iter is the name of the iterator. It is created on the first line by instantiation of cont_iterator class, an iterator class defined to iterate over some container class, cont. Succesive elements from the container are carried to x. The loop terminates when x is bound to some empty value. (Here, none)In the middle of the loop, there is s(x) an operation on x, the current element from the container. The next element of the container is obtained at the bottom of the loop.

30

Page 303: FRP C & DS dumps

9. List out some of the OODBMS available.Answer: GEMSTONE/OPAL of Gemstone systems. ONTOS of Ontos. Objectivity of Objectivity inc. Versant of Versant object technology. Object store of Object Design. ARDENT of ARDENT software. POET of POET software.

10. List out some of the object-oriented methodologies.Answer: Object Oriented Development (OOD) (Booch 1991,1994). Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon

1991). Object Modelling Techniques (OMT) (Rumbaugh 1991). Object Oriented Software Engineering (Objectory) (Jacobson 1992). Object Oriented Analysis (OOA) (Shlaer and Mellor 1992). The Fusion Method (Coleman 1991).

11. 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.Example: int *i=0x400 // i points to address 400 *i=0; //set the value of memory location pointed by i.Incomplete types are otherwise called uninitialized pointers.

12. What is a dangling pointer?Answer:

A dangling pointer arises when you use the address of an object after its lifetime is over.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.

13. Differentiate between the message and method.Answer:

30

Page 304: FRP C & DS dumps

Message MethodObjects communicate by sending messages Provides response to a message.to each other.A message is sent to invoke a method. It is an implementation of an operation.

14. What is an adaptor class or Wrapper class?Answer:

A class that has no functionality of its own. Its member functions hide the use of a third party software component or an object with the non-compatible interface or a non- object- oriented implementation.

15. 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. 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.

16. What is class invariant?Answer:

A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.

17. 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. 18. Define precondition and post-condition to a member function.Answer:Precondition: A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An

30

Page 305: FRP C & DS dumps

operation is not responsible for doing anything sensible if its precondition fails to hold.

For example, 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.

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. A class is implemented correctly if post-conditions are never false.

For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation.

19. 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. The condition should hold at the end of every mutator(non-const)

operation. 20. What are proxy objects?Answer: Objects that stand for other objects are called proxy objects or surrogates.Example: template<class T> class Array2D { public: class Array1D { public: T& operator[] (int index); const T& operator[] (int index) const; ... }; Array1D operator[] (int index); const Array1D operator[] (int index) const; ...

30

Page 306: FRP C & DS dumps

}; The following then becomes legal: Array2D<float>data(10,20); ........ cout<<data[3][6]; // fine

Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in position(3,6) of the original two dimensional array. 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, conceptually, do not exist for clients of Array2D. Such clients program as if they were using real, live, two-dimensional arrays. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. In the above example, Array1D is a proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not exist. 21. Name some pure object oriented languages.Answer:

Smalltalk, Java, Eiffel, Sather.

22. Name the operators that cannot be overloaded. Answer:

sizeof . .* .-> :: ?:

23. What is a node class?Answer:

A node class is a class that, relies on the base class for services and implementation, provides a wider interface to te users than its base class, 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.

30

Page 307: FRP C & DS dumps

A node class is a class that has added new services or functionality beyond the services inherited from its base class.

24. What is an orthogonal base class?Answer:

If two base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. The same derived class may inherit such classes with no difficulty.

25. 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. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.

26. 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,

non-virtual functions, or private (or protected) members of any kind. it has a non-inline virtual destructor defined with an empty

implementation, all member functions other than the destructor including inherited

functions, are declared pure virtual functions and left undefined.

27. 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. Derivation done just for the purpose of redefining the virtual functions in the base classes is often called mixin inheritance. Mixin classes typically don't share common bases.

28. What is a concrete class?

30

Page 308: FRP C & DS dumps

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. 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.

29.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.Explanation:

In case of abstract classes, unless one manipulates the objects of these classes through pointers and references, the benefits of the virtual functions are lost. User code 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. Using pointers or references implies that the burden of memory management falls on the user. 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.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. The connection between the handle and the representation is typically a pointer in the handle. Often, handles have a bit more data than the simple representation pointer, but not much more. Hence the layout of the handle is typically stable, 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. 30. What is an action class?Answer:

The simplest and most obvious way to specify an action in C++ is to write a function. However, if the action has to be delayed, has to be transmitted 'elsewhere' before being performed, requires its own data, has to be combined with other actions, 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. Manipulators used with iostreams is an obvious example.Explanation:

30

Page 309: FRP C & DS dumps

A common form of action class is a simple class containing just one virtual function. class Action { public: virtual int do_it( int )=0; virtual ~Action( ); }

Given this, we can write code say a member that can store actions for later execution without using pointers to functions, without knowing anything about the objects involved, and without even knowing the name of the operation it invokes. For example:class write_file : public Action { File& f; public: int do_it(int) { return fwrite( ).suceed( ); } }; class error_message: public Action { response_box db(message.cstr( ),"Continue","Cancel","Retry"); switch (db.getresponse( )) { case 0: return 0; case 1: abort(); case 2: current_operation.redo( );return 1; } };

A user of the Action class will be completely isolated from any knowledge of derived classes such as write_file and error_message.

31. 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.

30

Page 310: FRP C & DS dumps

32.What is a parameterized type?Answer:

A template is a parameterized construct or type containing generic code that can use or manipulate any type. It is called parameterized because an actual type is a parameter of the code body. Polymorphism may be achieved through parameterized types. This type of polymorphism is called parameteric polymorphism. Parameteric polymorphism is the mechanism by which the same code is used on different types passed as parameters.

33. 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. In a deep copy, the two objects may contain ht same information but the target object will have its own buffers and resources. the destruction of either object will not affect the remaining object. The overloaded assignment operator would create a deep copy of objects.

Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two objects will share the same externally contained contents of the other object to be unpredictable.Explanation:

Using a copy constructor we simply copy the data values member by member. This method of copying is called shallow copy. If the object is a simple class, comprised of built in types and no pointers this would be acceptable. This function would use the values and the objects and its behavior would not be altered with a shallow copy, only the addresses of pointers that are members are copied and not the value the address is pointing to. The data values of the object would then be inadvertently altered by the function. When the function goes out of scope, the copy of the object with all its data is popped off the stack.

If the object has any pointers a deep copy needs to be executed. With the deep copy of an object, memory is allocated for the object in free store and the elements pointed to are copied. A deep copy is used for objects that are returned from a function.

34. 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. A translation unit is

31

Page 311: FRP C & DS dumps

the result of merging an implementation file with all its headers and header files.

35. What is a smart pointer?Answer:

A smart pointer is an object that acts, looks and feels like a normal pointer but offers more functionality. In C++, smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. They have a number of advantages over regular pointers. They are guaranteed to be initialized as either null pointers or pointers to a heap object. Indirection through a null pointer is checked. No delete is ever necessary. Objects are automatically freed when the last pointer to them has gone away. One significant problem with these smart pointers is that unlike regular pointers, they don't respect inheritance. Smart pointers are unattractive for polymorphic code. Given below is an example for the implementation of smart pointers.Example: template <class X> class smart_pointer { public: smart_pointer(); // makes a null pointer smart_pointer(const X& x) // makes pointer to copy of x

X& operator *( ); const X& operator*( ) const; X* operator->() const;

smart_pointer(const smart_pointer <X> &); const smart_pointer <X> & operator =(const smart_pointer<X>&); ~smart_pointer(); private: //... };

This class implement a smart pointer to an object of type X. The object itself is located on the heap. Here is how to use it:

smart_pointer <employee> p= employee("Harris",1333);Like other overloaded operators, p will behave like a regular pointer,cout<<*p;

31

Page 312: FRP C & DS dumps

p->raise_salary(0.5);

36. 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. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class. For example:

Printer is-a printer.

37. 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. Explanation:

Consider the following class declaration: class base { ... base& operator =(const base&); base (const base&); } void fun( ) { base e=m; e=m; } As base copy functions don't know anything about the derived only

the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.

38. What is name mangling?Answer:

Name mangling is the process through which your c++ compilers give each function in your program a unique name. In C++, all programs have at-

31

Page 313: FRP C & DS dumps

least a few functions with the same name. Name mangling is a concession to the fact that linker always insists on all function names being unique.Example:

In general, member names are made unique by concatenating the name of the member with that of the class e.g. given the declaration: class Bar { public: int ival; ... };

ival becomes something like: // a possible member name mangling ival__3BarConsider this derivation: class Foo : public Bar { public: int ival; ... }

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; int ival__3Foo; ... };

Unambiguous access of either ival members is achieved through name mangling. Member functions, because they can be overloaded, require an extensive mangling to provide each with a unique name. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique). 39. What are proxy objects?

31

Page 314: FRP C & DS dumps

Answer:Objects that points to other objects are called proxy objects or

surrogates. Its an object that provides the same interface as its server object but does not have any functionality. During a method invocation, it routes data to the true server object and sends back the return value to the object. 40. Differentiate between declaration and definition in C++.Answer:

A declaration introduces a name into the program; a definition provides a unique description of an entity (e.g. type, instance, and function). Declarations can be repeated in a given scope, it introduces a name in a given scope. There must be exactly one definition of every object, function or class used in a C++ program.

A declaration is a definition unless: it declares a function without specifying its body, it contains an extern specifier and no initializer or function body, it is the declaration of a static class data member without a class

definition, it is a class name definition, it is a typedef declaration.A definition is a declaration unless: it defines a static class data member, it defines a non-inline member function.

41. What is cloning?Answer: An object can carry out copying in two ways i.e. it can set itself to be a copy of another object, or it can return a copy of itself. The latter process is called cloning.

42. Describe the main characteristics of static functions.Answer:

The main characteristics of static functions include, It is without the a this pointer, It can't directly access the non-static members of its class It can't be declared const, volatile or virtual. It doesn't need to be invoked through an object of its class,

although for convenience, it may.

43. Will the inline function be compiled as the inline function always? Justify.Answer:

31

Page 315: FRP C & DS dumps

An inline function is a request and not a command. Hence it won't be compiled as an inline function always.Explanation:

Inline-expansion could fail if the inline function contains loops, the address of an inline function is used, or an inline function is called in a complex expression. The rules for inlining are compiler dependent.

44. Define a way other than using the keyword inline to make a function inline.Answer:

The function must be defined inside the class.

45. How can a '::' operator be used as unary operator?Answer:

The scope operator can be used to refer to members of the global namespace. Because the global namespace doesn’t have a name, the notation :: member-name refers to a member of the global namespace. This can be useful for referring to members of global namespace whose names have been hidden by names declared in nested local scope. Unless we specify to the compiler in which namespace to search for a declaration, the compiler simple searches the current scope, and any scopes in which the current scope is nested, to find the declaration for the name.

46. What is placement new?Answer:

When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that's already been allocated, and you need to construct an object in the memory you have. Operator new's special version placement new allows you to do it. class Widget { public : Widget(int widgetsize); ... Widget* Construct_widget_int_buffer(void *buffer,int widgetsize) { return new(buffer) Widget(widgetsize); } };

31

Page 316: FRP C & DS dumps

This function returns a pointer to a Widget object that's constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.

OOAD

1. What do you mean by analysis and design?Analysis:

Basically, it is the process of determining what needs to be done before how it should be done. In order to accomplish this, the developer refers the existing systems and documents. So, simply it is an art of discovery.

Design:It is the process of adopting/choosing the one among the many,

which best accomplishes the users needs. So, simply, it is compromising mechanism.

2. What are the steps involved in designing?Before getting into the design the designer should go through the SRS

prepared by the System Analyst.The main tasks of design are Architectural Design and Detailed

Design.In Architectural Design we find what are the main modules in the

problem domain.In Detailed Design we find what should be done within each module.

3. What are the main underlying concepts of object orientation? Objects, messages, class, inheritance and polymorphism are the main concepts of object orientation.

4. What do u meant by "SBI" of an object?SBI stands for State, Behavior and Identity. Since every object has the

above three. State:

It is just a value to the attribute of an object at a particular time. Behaviour:

It describes the actions and their reactions of that object.

31

Page 317: FRP C & DS dumps

Identity: An object has an identity that characterizes its own existence.

The identity makes it possible to distinguish any object in an unambiguous way, and independently from its state.

5. Differentiate persistent & non-persistent objects?Persistent refers to an object's ability to transcend time or space. A

persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object.

A non-persistent object is said to be transient or ephemeral. By default objects are considered as non-persistent.

6. 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. In simple words it can be referred as client.

Passive objects are one, which passively waits for the message to be processed. It waits for another object that requires its services. In simple words it can be referred as server.

Diagram:client server

(Active) (Passive)

7. What is meant by software development method?Software development method describes how to model and build

software systems in a reliable and reproducible way. To put it simple, methods that are used to represent ones' thinking using graphical notations.

8. What are models and meta models?Model:

It is a complete description of something (i.e. system).Meta model:

It describes the model elements, syntax and semantics of the notation that allows their manipulation.

9. 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. These are expressed using class, object and USECASE diagrams.

31

Page 318: FRP C & DS dumps

But Dynamic modeling refers representing the object interactions during runtime. It is represented by sequence, activity, collaboration and statechart diagrams.

10.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.g. for modeling element is class notation, object notation etc.

Relationships are used to represent the interaction between the modeling elements.

The following are the Relationships.

Association: Its' just a semantic connection two classes.e.g.:

Aggregation: Its' the relationship between two classes which are related in the fashion that master and slave. The master takes full rights than the slave. Since the slave works under the master. It is represented as line with diamond in the master area.

ex: car contains wheels, etc.

car

Containment: This relationship is applied when the part contained with in the whole part, dies when the whole part dies.

It is represented as darked diamond at the whole part. example:

class A{ //some code

};

class B { A aa; // an object of class A; // some code for class B; };

In the above example we see that an object of class A is instantiated

31

car wheels

class A class Buses

Page 319: FRP C & DS dumps

with in the class B. so the object class A dies when the object class B dies.we can represnt it in diagram like this.

Generalization: This relationship used when we want represents a class, which captures the common states of objects of different classes. It is represented as arrow line pointed at the class, which has captured the common states.

Dependency: It is the relationship between dependent and independent classes. Any change in the independent class will affect the states of the dependent class.

DIAGRAM:class A class B

11.Why generalization is very strong? Even though Generalization satisfies Structural, Interface, Behaviour

properties. It is mathematically very strong, as it is Antisymmetric and Transitive. Antisymmetric: employee is a person, but not all persons are employees. Mathematically all As’ are B, but all Bs’ not A. Transitive: A=>B, B=>c then A=>c. A. Salesman.

B. Employee. C. Person.

Note: All the other relationships satisfy all the properties like Structural properties, Interface properties, Behaviour properties.

12.Differentiate Aggregation and containment?Aggregation is the relationship between the whole and a part. We can

31

class A class B

class A

class B class C

Page 320: FRP C & DS dumps

add/subtract some properties in the part (slave) side. It won't affect the whole part.

Best example is Car, which contains the wheels and some extra parts. Even though the parts are not there we can call it as car.

But, in the case of containment the whole part is affected when the part within that got affected. The human body is an apt example for this relationship. When the whole body dies the parts (heart etc) are died.

13.Can link and Association applied interchangeably?No, You cannot apply the link and Association interchangeably. Since

link is used represent the relationship between the two objects.But Association is used represent the relationship between the two

classes.link :: student:Abhilash course:MCAAssociation:: student course

14.what is meant by "method-wars"? Before 1994 there were different methodologies like Rumbaugh, Booch, Jacobson, Meyer etc who followed their own notations to model the systems. The developers were in a dilemma to choose the method which best accomplishes their needs. This particular span was called as "method-wars"

15.Whether unified method and unified modeling language are same or different? Unified method is convergence of the Rumbaugh and Booch. Unified modeling lang. is the fusion of Rumbaugh, Booch and

Jacobson as well as Betrand Meyer (whose contribution is "sequence diagram"). Its' the superset of all the methodologies.

16.Who were the three famous amigos and what was their contribution to the object community?

The Three amigos namely, James Rumbaugh (OMT): A veteran in analysis who came up with an

idea about the objects and their Relationships (in particular Associations).

Grady Booch: A veteran in design who came up with an idea about partitioning of systems into subsystems.

Ivar Jacobson (Objectory): The father of USECASES, who described

32

Page 321: FRP C & DS dumps

about the user and system interaction.

17.Differentiate the class representation of Booch, Rumbaugh and UML? If you look at the class representaiton of Rumbaugh and UML, It is some what similar and both are very easy to draw. Representation: OMT UML. 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.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. It is represented elliptically.

Representation:

19.Who is an Actor?An Actor is someone or something that must interact with the

system.In addition to that an Actor initiates the process(that is USECASE).

It is represented as a stickman like this.Diagram:

32

Page 322: FRP C & DS dumps

20.What is guard condition?Guard condition is one, which acts as a firewall. The access from a

particular object can be made only when the particular condition is met.For Example,

customer check customer number ATM.Here the object on the customer accesses the ATM facility only when the guard condition is met.

21.Differentiate the following notations? I: :obj1 :obj2

II: :obj1 :obj2

In the above representation I, obj1 sends message to obj2. But in the case of II the data is transferred from obj1 to obj2.

22.USECASE is an implementation independent notation. 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.

Or example,

calculate pay calculate

class1 class2 class3

23.Suppose a class acts an Actor in the problem domain, how to represent it in the static model?

In this scenario you can use “stereotype”. Since stereotype is just a string that gives extra semantic to the particular entity/model element. It is given with in the << >>.

class A<< Actor>>

32

Page 323: FRP C & DS dumps

attributes

methods.

24.Why does the function arguments are called as "signatures"?The arguments distinguish functions with the same name (functional

polymorphism). The name alone does not necessarily identify a unique function. However, the name and its arguments (signatures) will uniquely identify a function.

In real life we see suppose, in class there are two guys with same name, but they can be easily identified by their signatures. The same concept is applied here.

ex:class person{ public:

char getsex();void setsex(char);void setsex(int);

};In the above example we see that there is a function setsex() with

same name but with different signature.

Playing with scanf function Operators & Expressions

_____ _____________________________________

[Q001]. Determine which of the following are VALID identifiers. If invalid, state the reason.

(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_ageAns. (a) VALID

(b) Invalid, since an identifier must begin with a letter or an underscore

(c) VALID

32

Page 324: FRP C & DS dumps

(d) Invalid, since return is a reserved word(e) Invalid, since an identifier must begin with a letter or an

underscore(f) VALID(g) Invalid, since an identifier must begin with a letter or an

underscore(h) Invalid, since blank spaces are not allowed(i) VALID(j) VALID

_________________________________________________________________________________________________

[Q002]. Determine which of the following are VALID character constants. If invalid, state the reason.

(a) 'y' (b) '\r' (c) 'Y' (d) '@' (e) '/r'(f) 'word' (g) '\0'(h) '\?'(i) '\065' (j) '\'' (k) ' '

Ans. (a) VALID(b) VALID(c) VALID(d) VALID(e) Invalid, since escape sequences must be written with a backward

slash (i.e. \)(f) Invalid, 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]. Determine which of the following are VALID string constants. If invalid, state the reason.

(a) 'Hi Friends' (b) "abc,def,ghi" (c) "Qualification(d) "4325.76e-8" (e) "Don\'t sleep" (f) "He said,

"You\'re great"(g) "" (h) " " (i) "Rs.100/-"

Ans. (a) Invalid, since a string constant must be enclosed in double quotation marks

32

Page 325: FRP C & DS dumps

(b) VALID(c) Invalid, since trailing quotation mark is missing(d) VALID(e) VALID (single-quote escape sequence)(f) Invalid, since the quotation marks and (optionally) apostrophe

within the string cannot be expressed without the escape sequences.(g) VALID(h) VALID(i) VALID

_________________________________________________________________________________________________

[Q004]. Determine which of the following numerical values are valid constants. If a constant isvalid, specify whether it is integer or real. Also, specify the base for each valid integer constant.

(a) 10,500 (b) 080 (c) 0.007 (d) 5.6e7 (e) 5.6e-7(f) 0.2e-0.3 (g) 0.2e 0.3 (h) 0xaf9s82(i) 0XABCDEFL (j) 0369CF(k) 87654321l (l) 87654321

Ans. (a) Invalid, since illegal character(,)(b) VALID(c) VALID(d) VALID(e) VALID(f) VALID(g) Invalid, since illegal character(blank space)(h) Invalid, since illegal character(s)(i) VALID(j) Invalid, since illegal characters (9, C, F), if intended as an octal

constant.(k) VALID(l) VALID

_________________________________________________________________________________________________

[Q005]. Determine which of the following floating-point constants are VALID for the quantity (5 * 100000).

(a) 500000 (b) 0.5e6 (c) 5E5 (d) 5e5 (e) 5e+5

32

Page 326: FRP C & DS dumps

(f) 500E3 (g) .5E6 (h) 50e4 (i) 50.E+4 (j) 5.0E+5(k) All of the above (l) None of these

Ans. (k)_________________________________________________________________________________________________

[Q006]. What will be the output of the following program : void main() { printf("%f",123.); }(a)123 (b)Compile-Time Error (c)123.00

(d)123.000000Ans. (d)_________________________________________________________________________________________________

[Q007]. What will be the output of the following program : void main() { printf("%d",sizeof(integer)); }(a)2 (b)Compile-Time Error (c)4

(d)None of theseAns. (b) since there is no such data type called 'integer'._________________________________________________________________________________________________

[Q008]. What will be the output of the following program : void main() { char str[]="C For Swimmers";

printf("%d",sizeof str); }(a)14 (b)Compile-Time Error (c)15

(d)None of theseAns. (a)--c_________________________________________________________________________________________________

32

Page 327: FRP C & DS dumps

[Q009]. What will be the output of the following program : void main() { char str[]="C For Swimmers";

printf("%d",++(sizeof(str))); }(a)14 (b)Compile-Time Error (c)15

(d)None of theseAns. (b)_________________________________________________________________________________________________

[Q010]. What will be the output of the following program : void main() { char str[]="C For Swimmers";

printf("%d",-sizeof(str)); }(a)14 (b)Compile-Time Error (c)-15 (d)-14Ans. (c)_________________________________________________________________________________________________

[Q011]. What will be the output of the following program : void main() { printf("%d",!(100==100)+1); }(a)100 (b)0 (c)1 (d)2Ans. (c)_________________________________________________________________________________________________

[Q012]. What will be the output of the following program : void main() { int x=5,y=6,z=2;

z/=y/z==3?y/z:x*y; printf("%d",z);

}

32

Page 328: FRP C & DS dumps

(a)Compile-Time Error (b)2 (c)0 (d)1Ans. (c)_________________________________________________________________________________________________

[Q013]. What will be the output of the following program : void main() { printf("%d %d %d",5,!5,25 - !25); }(a)5 10 22 (b)5 5 25 (c)5 0 25 (d)5 1 24Ans. (c)_________________________________________________________________________________________________

[Q014]. What will be the output of the following program : int main() {

int a=500,b=100,c=30,d=40,e=19; a+=b-=c*=d/=e%=5; printf("%d %d %d %d %d",a,b,c,d,e);

}(a)500 100 30 40 4(b)Run-Time Error(c)700 200 300 10 4 (d)300 -200 300 10 4Ans. (d)_________________________________________________________________________________________________

[Q015]. What will be the output of the following program : void main() { int a=500,b=100,c=30,d=40,e=19;

if ((((a > b) ? c : d) >= e) && !((e <= d) ? ((a / 5) == b) : (c == d)))printf("Success");

elseprintf("Failure");

}(a)VALID : Success (b)VALID : Failure (c)INVALID

(d)None of theseAns. (b)

32

Page 329: FRP C & DS dumps

_________________________________________________________________________________________________

[Q016]. What will be the output of the following program : void main() { int a=1,b=2,c=3,d=4;

printf("%d",!a?b?!c:!d:a); }(a)1 (b)2 (c)3 (d)4Ans. (a)_________________________________________________________________________________________________

[Q017]. What will be the output of the following program : void main() {

int i=12345,j=-13579,k=-24680; long ix=123456789; short sx=-2222; unsigned ux=5555; printf("\n%d %d %d %ld %d %u",i,j,k,ix,sx,ux); printf("\n\n%3d %3d %3d\n%3ld %3d %3u",i,j,k,ix,sx,ux); printf("\n\n%8d %8d %8d\n%15ld %8d %8u",i,j,k,ix,sx,ux); printf("\n\n%-8d %-8d\n%-8d %-15ld\n%-8d %-8u",i,j,k,ix,sx,ux); printf("\n\n%+8d %+8d\n%+8d %+15ld\n%+8d %8u",i,j,k,ix,sx,ux); printf("\n\n%08d %08d\n%08d %015ld\n%08d

%08u",i,j,k,ix,sx,ux); }Ans. 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555

12345 -13579 -24680 123456789 -2222 5555

12345 -13579 -24680 123456789 -2222 5555

32

Page 330: FRP C & DS dumps

+12345 -13579 -24680 +123456789 -2222 5555

00012345 -0013579 -0024680 000000123456789 -0002222 00005555_________________________________________________________________________________________________

[Q018]. What will be the output of the following program : void main() { int i=12345,j=0xabcd9,k=077777;

printf("%d %x %o",i,j,k); printf("\n%3d %3x %3o",i,j,k); printf("\n%8d %8x %8o"i,j,k); printf("\n%-8d %-8x %-8o",i,j,k); printf("\n%+8d %+8x %+8o",i,j,k); printf("\n%08d %#8x %#8o",i,j,k);

}Ans. 12345 abcd9 77777 12345 abcd9 77777 12345 abcd9 77777 12345 abcd9 77777 +12345 abcd9 77777 00012345 0xabcd9 077777_________________________________________________________________________________________________

[Q019]. What will be the output of the following program : void main() {

char c1='A', c2='B', c3='C'; printf("%c %c %c",c1,c2,c3); printf("\n%c%c%c",c1,c2,c3); printf("\n%3c %3c %3c",c1,c2,c3); printf("\n%3c%3c%3c",c1,c2,c3); printf("\nc1=%c c2=%c c3=%c",c1,c2,c3);

33

Page 331: FRP C & DS dumps

}Ans. A B C ABC A B C A B C c1=A c2=B c3=C_________________________________________________________________________________________________

[Q020]. What will be the output of the following program : void main() {

float a=2.5, b=0.0005, c=3000.; printf("%f %f %f",a,b,c); printf("\n%3f %3f %3f",a,b,c); printf("\n%8f %8f %8f",a,b,c); printf("\n%8.4f %8.4f %8.4f",a,b,c); printf("\n%8.3f %8.3f %8.3f",a,b,c); printf("\n%e %e %e",a,b,c); printf("\n%3e %3e %3e",a,b,c); printf("\n%12e %12e %12e",a,b,c); printf("\n%8.2e %8.2e %8.2e",a,b,c); printf("\n%-8f %-8f %-8f",a,b,c); printf("\n%+8f %+8f %+8f",a,b,c); printf("\n%08f %08f %08f",a,b,c); printf("\n%#8f %#8f %#8f",a,b,c); printf("\n%g %g %g",a,b,c); printf("\n%#g %#g %#g"a,b,c);

}

Ans. 2.500000 0.000500 3000.000000 2.500000 0.000500 3000.000000 2.500000 0.000500 3000.000000 2.5000 0.0005 3000.0000 2.500 0.001 3000.000 2.500000e+000 5.000000e-004 3.000000e+003 2.500000e+000 5.000000e-004 3.000000e+003 2.500000e+000 5.000000e-004 3.000000e+003 2.5000e+000 5.0000e-004 3.0000e+003 2.50e+000 5.00e-004 3.00e+003

33

Page 332: FRP C & DS dumps

2.500000 0.000500 3000.000000 +2.500000 +0.000500 +3000.000000 2.500000 0.000500 3000.000000 2.500000 0.000500 3000.000000 2.5 0.0005 3000 2.500000 0.000500 3000.000000_________________________________________________________________________________________________

[Q021]. What will be the output of the following program : void main() {

char str[]="C For Swimmers"; printf("%s",str); printf("\n%.5s",str); printf("\n%8.*s",5,str); printf("\n%-10s %.1s",str+6,str);

}Ans. C For Swimmers C For C For Swimmers C _________________________________________________________________________________________________

[Q022]. What will be the output of the following program : void main() {

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

}[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. (d)_________________________________________________________________________________________________

[Q023]. What will be the output of the following program :

33

Page 333: FRP C & DS dumps

void main() {

char line[80]; // Max. length=80 Chars scanf("%[^,]s",line); printf("\n%s",line);

}[NOTE : THE USER INPUT IS:Dear Friends, What is the output?](a)Compile-Time Error (b)Dear Friends (c)What is the output? (d)None of theseAns. (b) _________________________________________________________________________________________________

[Q024]. What will be the output of the following program : void main() {

char a,b,c; scanf("%c%c%c",&a,&b,&c); printf("a=%c b=%c c=%c",a,b,c);

}[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 theseAns. (b)_________________________________________________________________________________________________

[Q025]. What will be the output of the following program : void main() {

int i=1; float f=2.25; scanf("%d a %f",&i,&f); printf("%d %.2f",i,f);

}[NOTE : THE USER INPUT IS:5 5.75](a)1 2.25 (b)5 5.75 (c)5 2.25 (d)None of theseAns. (c)

33

Page 334: FRP C & DS dumps

_________________________________________________________________________________________________

[Q026]. What will be the output of the following program : void main() {

char a,b,c; scanf("%c %c %c",&a,&b,&c); printf("a=%c b=%c c=%c",a,b,c);

}[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 theseAns. (b) _________________________________________________________________________________________________

[Q027]. What will be the output of the following program : void main() {

char a[80],b[80],c[80]; scanf("%1s %5s %3s",a,b,c);

printf("%s %s %s",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 theseAns. (b) _________________________________________________________________________________________________

[Q028]. What will be the output of the following program : void main() {

int a,b,c; scanf("%1d %2d %3d",&a,&b,&c); printf("Sum=%d",a+b+c);

}[NOTE : THE USER INPUT IS :123456 44 544]

33

Page 335: FRP C & DS dumps

(a)Sum=480 (b)Sum=594 (c)Sum=589 (d)None of theseAns. (a) _________________________________________________________________________________________________

[Q029]. What happens when the following program is executed : void main() {

char line[80]; scanf("%[^1234567890\n]",line);

}(a)Accepts the string that contains DIGITS only.(b)Accepts the string that contains DIGITS and NEWLINE characters.(c)Accepts the string that contains anything other than the DIGITS and NEWLINE characters.(d)None of theseAns. (c) _________________________________________________________________________________________________

[Q030]. What happens when the following program is executed : void main() {

char line[80]; scanf("%[^*]",line); }(a)Accepts the string that contains DIGITS & ALPHABETS only.(b)Accepts the string that contains * or asterisk characters only.(c)Accepts the string that contains anything other than the * or asterisk character.(d)None of theseAns. (c) _________________________________________________________________________________________________

[Q001]. What will be the output of the following program :void main()

{ printf();

33

Page 336: FRP C & DS dumps

}(a)Run-Time Error (b)Compile-Time Error (c)No Output

(d)None of theseAns. (b) Since there must be enough arguments for the format._____________________________________________________

[Q002]. What will be the output of the following program : void main() { printf(NULL); }(a)Run-Time Error (b)Compile-Time Error (c)No Output

(d)None of theseAns. (c) Since NULL is a constant value or NULL pointer value or a NULL string.____________________________________________________

[Q003]. What will be the output of the following program : void main() { printf("%%",7); }(a)7 (b)Compile-Time Error (c)% (d)%%Ans. (c) Since % is a format specifier & excess arguments (more than required by the format) aremerely ignored.__________________________________________________________

[Q004]. What will be the output of the following program : void main() { printf("//",5); }(a)5 (b)Compile-Time Error (c)/ (d)//Ans. (d) Since // is taken as string_____________________________________________________________

[Q005]. What will be the output of the following program : void main()

33

Page 337: FRP C & DS dumps

{ printf("d%",8); }(a)8 (b)Compile-Time Error (c)d%

(d)None of theseAns. (c) Since excess arguments (more than required by the format) are merely ignored.__________________________________________________________

[Q006]. What will be the output of the following program : void main() { printf("%d"+0,123); }(a)123 (b)Compile-Time Error (c)No Output

(d)None of theseAns. (a) since"%d"+0 has no effect on the output operation. __________________________________________________________________

[Q007]. What will be the output of the following program : void main()-----------------doubt { printf("%d"+1,123); }

(a)123 (b)Compile-Time Error (c)d (d)No Output

Ans. (c) since "%d"+1 (i.e 1 or > 0) affects the program output by considering "%d" as string and ignores 123Where 1 refers to the index i.e. 2nd character in the array or string "%d"._______________________________________________________________

[Q008]. What will be the output of the following program : void main() { printf("%d",printf("Hi!")+printf("Bye")); }

33

Page 338: FRP C & DS dumps

(a)ByeHi!6 (b)Hi!Bye6 (c)Compile-Time Error (d)None of theseAns. (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() { printf("%d",printf("Hi!")*printf("Bye")); }(a)ByeHi!6 (b)Hi!Bye9 (c)Hi!Bye (d)None of theseAns. (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",printf("")+printf("")); }(a)0 (b)No Output (c)Compile-Time Error (d)None of theseAns. (a) Since L->R priority & the length of the 2 empty strings are : 0+0=0____________________________________________________________

[Q011]. What will be the output of the following program : void main() { printf("Hi Friends"+3); }(a)Hi Friends (b)Friends (c)Hi Friends3 (d)None of these

Ans. (b) Since (base adress)+0 points to the value 'H'. Now the NEW (base address) equals (base address)+3 that points to the character 'F'. Thus it prints the string from 'F' onwards.___________________________________________________________

[Q012]. What will be the output of the following program :

33

Page 339: FRP C & DS dumps

void main() { printf("C For ") + printf("Swimmers"); }(a)Compile-Time Error (b)C For Swimmers (c)Run-Time Error

(d)None of theseAns. (b) It is a VALID C statement. ____________________________________________________________

[Q013]. What will be the output of the following program : void main() { printf("\/\*\-*\/"); }(a)Run-Time Error (b)\/*-*\/ (c)/*-*/ (d)None of theseAns. (c) Since \ is an escape sequence character. Be careful while analyzing such statements._______________________________________________________________

[Q014]. What will be the output of the following program : int main() {

int main=7; {

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

printf("Bye"); }(a)Compile-Time Error (b)Run-Time Error(c)7Bye (d)7

Ans. (d) It is a VALID C statement. Prints 7 and returns the same to the OS. NOTE: Last printf statement will not be executed.________________________________________________________

[Q015]. What will be the output of the following program : void main() {

33

Page 340: FRP C & DS dumps

main(); }(a)Compile-Time Error (b)Run-Time Error(c)Infinite Loop (d)None of theseAns. (c) It is a VALID C statement. It is like a recursive function & the statements get executed infinite number of times. (All compilers will not support)_____________________________________________________________

[Q016]. What will be the output of the following program : void main() { printf("Work" "Hard"); }(a)Work (b)Hard (c)No Output (d)WorkHardAns. (d) Since L->R priority. First it prints the word 'Work' & then 'Hard'.______________________________________________________________

[Q017]. What will be the output of the following program : void main() { char str[]="%d"; int val=25;

printf(str,val); }(a)Compile-Time Error (b)Run-Time Error(c)25 (d)None of theseAns. (c) It is a VALID C statement. First parameter contains the format specifier & the Second parameter contains the actual value 25.________________________________________________________

[Q018]. What will be the output of the following program : void main() { int val=75;

printf("%d",val,.,.); }(a)Compile-Time Error (b)Unpredictable (c)75 (d)None of theseAns. (b) Output is Unpredictable B'coz there are not enough arguments for the format. But it is a VALID C statement.

34

Page 341: FRP C & DS dumps

____________________________________________________

[Q019]. What will be the output of the following program : void main()---------------------doubt { int val=10;

printf("%d",val+1,"%d",val--); }(a)10 (b)11 10 (c)11 9 (d)10 9Ans. (a) Since R->L priority. The second format specifier “%d” is an excess argument and it is ignored.______________________________________________________________

[Q020]. What will be the output of the following program : void main() { int val=5;

printf("%d %d %d %d",val,--val,++val,val--); }(a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of theseAns. (c) Since R->L priority.___________________________________________________________

[Q021]. What will be the output of the following program : void main()

34

Page 342: FRP C & DS dumps

{ int val=5,num;

printf("%d",scanf("%d %d",&val,&num)); }[NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively.](a)1 (b)2 (c)5 (d)None of theseAns. (b) Since scanf statement returns the number of input fields successfully scanned, converted& stored._________________________________________________________________________________________________

[Q022]. What will be the output of the following program :#define Compute(x,y,z) (x+y-z)---------------doubt

void main() { int x=2,y=3,z=4;

printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); }(a)40 (b)30 (c)Compile-Time Error

(d)None of theseAns. (b) Since it is macro function. NOTE : Be careful while doing such type of calculations._________________________________________________________________________________________________

[Q023]. What will be the output of the following program : void main() { int m=10,n=20;

printf("%d %d %d",m/* m-value */,/* n-value */n,m*/* Compute m*n */n); }(a)Run-Time Error (b)10 20 200 (c)Compile-Time Error

(d)None of theseAns. (b) Since comments /*...*/ are ignored by the compiler._________________________________________________________________________________________________

34

Page 343: FRP C & DS dumps

[Q024]. What will be the output of the following program : void main() { int m=10,n=20;

/* printf("%d",m*n); }(a)VALID but No Output(b)VALID : Prints 200 (c)Compile-Time Error

(d)None of theseAns. (c) Since COMMENT statement not ended properly i.e */ is missing in the above program._________________________________________________________________________________________________

[Q025]. What will be the output of the following program : void main() { int val=97;

"Printing..."+printf("%c",val); }(a)Printing...97 (b)97 (c)Compile-Time Error (d)a Ans. (d) Since alphabet 'a' is the ASCII equivalent of 97._________________________________________________________________________________________________

[Q026]. What will be the output of the following program : void main() { int val=5;

val=printf("C") + printf("Skills"); printf("%d",val); }(a)Skills5 (b)C1 (c)Compile-Time Error

(d)CSkills7 Ans. (d) VALID Since 'printf' function return the no. of bytes output._________________________________________________________________________________________________

[Q027]. What will be the output of the following program : void main()

34

Page 344: FRP C & DS dumps

{ char str[]="Test";

if ((printf("%s",str)) == 4) printf("Success");

elseprintf("Failure");

}(a)TestFailure (b)TestSuccess (c)Compile-Time Error

(d)Test Ans. (b) VALID Since 'printf' function return the no. of bytes output._________________________________________________________________________________________________

[Q028]. What will be the output of the following program : void main() { int val=5; printf("%*d",val); }(a) 5 (b)5 (c)Compile-Time Error

(d)None of these Ans. (a) VALID Since '*' specifies the precision (i.e. the next argument in the precision). If noprecision is specified then the value itself will be the precision value. Thus it prints 5 BLANKSPACES & then the value 5._________________________________________________________________________________________________

[Q029]. What will be the output of the following program : void main()--------------------------doubt { int val=5; printf("%d5",val); }(a)Compile-Time Error (b)5 (c)55 (d) 5 Ans. (c) _________________________________________________________________________________________________

34

Page 345: FRP C & DS dumps

[Q030]. What will be the output of the following program : void main() } int val=5; printf("%d",5+val++); {(a)Compile-Time Error (b)5 (c)10 (d)11Ans. (a) Since incorrect usage of pair of braces } and {. Correct usage : Each compound statementshould be enclosed within a pair of braces, i.e { and }._________________________________________________________________________________________________

Topic : Decision-making, Branching, Looping & Bit-wise operations

[Q001]. What will be the output of the following program :void main(){ printf("Hi!"); if (-1) printf("Bye");}

(a)No Output (b)Hi! (c)Bye(d)Hi!Bye

Ans. (d)_________________________________________________________________________________________________

[Q002]. What will be the output of the following program :void main(){ printf("Hi!"); if (0 || -1) printf("Bye");}

(a)No Output (b)Hi! (c)Bye(d)Hi!Bye

34

Page 346: FRP C & DS dumps

Ans. (d) _________________________________________________________________________________________________

[Q003]. What will be the output of the following program :void main(){ printf("Hi!"); if (!1) printf("Bye");}

(a)Compile-Time error (b)Hi! (c)Bye(d)Hi!Bye

Ans. (b)_________________________________________________________________________________________________

[Q004]. What will be the output of the following program :void main(){ printf("Hi!"); if !(0) printf("Bye");}

(a)Compile-Time error (b)Hi! (c)Bye(d)Hi!Bye

Ans. (a)_________________________________________________________________________________________________

[Q005]. 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)No Output (b)Hi! (c)Bye(d)Hi!Bye

Ans. (d)

34

Page 347: FRP C & DS dumps

_________________________________________________________________________________________________

[Q006]. What will be the output of the following program :void main(){ if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int))

printf("Testing"); printf("OK");}

(a)No Output (b)OK (c)Testing(d)TestingOK

Ans. (b)_________________________________________________________________________________________________

[Q007]. What will be the output of the following program :void main(){ int a=1,b=2,c=3,d=4,e; if (e=(a & b | c ^ d)) printf("%d",e);}

(a)0 (b)7 (c)3 (d)No OutputAns. (b)_________________________________________________________________________________________________

[Q008]. What will be the output of the following program :void main(){ unsigned val=0xffff; if (~val) printf("%d",val); printf("%d",~val);}

(a)Compile-Time error (b)-1 (c)0 (d)-1 0Ans. (c)

34

Page 348: FRP C & DS dumps

_________________________________________________________________________________________________

[Q009]. What will be the output of the following program :void main(){ unsigned a=0xe75f,b=0x0EF4,c; c=(a|b); if ((c > a) && (c > b)) printf("%x",c);}

(a)No Output (b)0xe75f (c)0xefff .(d)None of theseAns. (c)_________________________________________________________________________________________________

[Q010]. What will be the output of the following program :void main(){ unsigned val=0xabcd; if (val>>16 | val<<16) {

printf("Success");return;

} printf("Failure");}

(a)No Output (b)Success (c)Failure(d)SuccessFailure

Ans.(b) _________________________________________________________________________________________________

[Q011]. What will be the output of the following program :void main(){

unsigned x=0xf880,y=5,z; z=x<<y; printf("%#x %#x",z,x>>y-1);

34

Page 349: FRP C & DS dumps

}(a)1000 f87 (b)8800 0xf88 (c)1000 f88

(d)0x1000 0xf88Ans. (d)_________________________________________________________________________________________________

[Q012]. What will be the output of the following program :void main(){ register int a=5; int *b=&a; printf("%d %d",a,*b);}

(a)Compile-Time error (b)Run-Time error (c)5 5(d)Unpredictable

Ans. (a)_________________________________________________________________________________________________

[Q013]. What will be the output of the following program :auto int a=5;void main(){ printf("%d",a);}

(a)Compile-Time error (b)Run-Time error (c)5(d)Unpredictable

Ans. (a)_________________________________________________________________________________________________

[Q014]. What will be the output of the following program :void main(){ auto int a=5; printf("%d",a);}

(a)Compile-Time error (b)Run-Time error (c)5(d)Unpredictable

34

Page 350: FRP C & DS dumps

Ans. (c)_________________________________________________________________________________________________

[Q015]. What will be the output of the following program :void main(){ int a=1,b=2,c=3,d=4; if (d > c) if (c > b)

printf("%d %d",d,c); else if (c > a)

printf("%d %d",c,d); if (c > a)

if (b < a) printf("%d %d",c,a);else if (b < c) printf("%d %d",b,c);

}(a)4 3 3 4 (b)4 3 3 2 (c)4 32 3 (d)4 33 1Ans. (c)_________________________________________________________________________________________________

[Q016]. What will be the output of the following program :void main(){ int a=1,b=2,c=3,d=4; if (d > c) if (c > b)

printf("%d %d",d,c); if (c > a)

printf("%d %d",c,d); if (c > a)

if (b < a) printf("%d %d",c,a);if (b < c) printf("%d %d",b,c);

35

Page 351: FRP C & DS dumps

}(a)4 32 3 (b)4 33 42 3 (c)4 3 3 4 2 3

(d)None of theseAns. (b)_________________________________________________________________________________________________

[Q017]. What will be the output of the following program :void main(){ int a=1; if (a == 2); printf("C Program");}

(a)No Output (b)C Program (c)Compile-Time ErrorAns. (b)_________________________________________________________________________________________________

[Q018]. What will be the output of the following program :void main(){ int a=1; if (a) printf("Test"); else; printf("Again");}

(a)Again (b)Test (c)Compile-Time Error(d)TestAgain

Ans. (d)_________________________________________________________________________________________________

[Q019]. What will be the output of the following program :void main(){ int i=1; for (; i<4; i++);

35

Page 352: FRP C & DS dumps

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

(a)No Output (b)1 (c)4(d)None of these

2 3

Ans. (c)_________________________________________________________________________________________________

[Q020]. What will be the output of the following program :void main(){ int a,b; for (a=0; a<10; a++); for (b=25; b>9; b-=3); printf("%d %d",a,b);}

(a)Compile-Time error (b)10 9 (c)10 7(d)None of these

Ans. (c)_________________________________________________________________________________________________

[Q021]. What will be the output of the following program :void main(){ float i; for (i=0.1; i<0.4; i+=0.1) printf("%.1f",i);}

(a)0.10.20.3 (b)Compile-Time Error (c)Run-Time Error (d)No OutputAns. (a)_________________________________________________________________________________________________

[Q022]. What will be the output of the following program :void main(){

35

Page 353: FRP C & DS dumps

int i; for (i=-10; !i; i++);

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

(a)0 (b)Compile-Time Error (c)10 (d)No OutputAns. (c)_________________________________________________________________________________________________

[Q023]. What will be the output of the following program :void main(){ int i=5; do; printf("%d",i--); while (i>0);}

(a)5 (b)54321 (c)Compile-Time Error(d)None of these

Ans. (c)_________________________________________________________________________________________________

[Q024]. What will be the output of the following program :void main(){

int i; for (i=2,i+=2; i<=9; i+=2)

printf("%d",i);}

(a)Compile-Time error (b)2468 (c)468(d)None of these

Ans. (c)_________________________________________________________________________________________________

[Q025]. What will be the output of the following program :void main(){

35

Page 354: FRP C & DS dumps

int i=3; for (i--; i<7; i=7) printf("%d",i++);}

(a)No Output (b)3456 (c)23456(d)None of these

Ans. (d)_________________________________________________________________________________________________

[Q026]. What will be the output of the following program :void main(){ int i; for (i=5; --i;)

printf("%d",i);}

(a)No Output (b)54321 (c)4321(d)None of these

Ans. (c)_________________________________________________________________________________________________

[Q027]. What will be the output of the following program :void main(){

int choice=3; switch(choice) { default: printf("Default");

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

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

35

Page 355: FRP C & DS dumps

}(a)No Output (b)Default (c)DefaultChoice1

(d)None of theseAns. (c)_________________________________________________________________________________________________

[Q028]. What will be the output of the following program :void main(){

static int choice; switch(--choice,choice-1,choice-1,choice+=2) { case 1: printf("Choice1"); break;

case 2: printf("Choice2"); break;

default: printf("Default"); }}

(a)Choice1 (b)Choice2 (c)Default (d)None of theseAns. (a)_________________________________________________________________________________________________

[Q029]. What will be the output of the following program :void main(){ for (;printf(""););}

(a)Compile-Time error (b)Executes ONLY once (c)Executes INFINITELY (d)None of theseAns. (b)

35

Page 356: FRP C & DS dumps

_________________________________________________________________________________________________

[Q030]. What will be the output of the following program :void main(){ int i; for (;(i=4)?(i-4):i++;) printf("%d",i);}

(a)Compile-Time error (b)4 (c)Infinite Loop (d)No OutputAns. (d)_________________________________________________________________________________________________

[Q031]. What will be the output of the following program :void main(){ static int j; for (j<5; j<5; j+=j<5)

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

(a)024 (b)Compile-Time Error (c)01234 (d)No Output

Ans._________________________________________________________________________________________________

[Q032]. What will be the output of the following program :void main(){ int i=9; for (i--; i--; i--) printf("%d ",i);}

(a)9 6 3 (b)Compile-Time Error (c)7 5 3 1 (d)Infinite Loop

Ans.

35

Page 357: FRP C & DS dumps

_________________________________________________________________________________________________

[Q033]. What will be the output of the following program :void main(){ int i; for (i=5; ++i; i-=3) printf("%d ",i);}

(a)6 4 2 (b)Compile-Time Error (c)6 3 1 (d)Infinite Loop

Ans. _________________________________________________________________________________________________

[Q034]. Which of the following code causes INFINITE Loop :(a)do while(1); (b)do;while(1); (c)do;

(d)do{}while(1); while(1);

(i)Only (a) (ii)Only (b), (c) & (d) (iii)None of these(iv)All of these

Ans. _________________________________________________________________________________________________

[Q035]. What will be the output of the following program :#define Loop(i) for (j=0; j<i; j++){ \

sum += i+j; \ }

void main(){ int i,j,sum=0; for (i=0; i<=3; i++) Loop(i) printf("%d",sum);}

35

Page 358: FRP C & DS dumps

(a)Run-Time Error (b)Compile-Time Error (c)18 (d)0Ans. _________________________________________________________________________________________________

(1) What will be output if you will compile and execute the following c code?void main(){

int i=320;

char *ptr=(char *)&i;

printf("%d",*ptr);

}

(a)320

(b)1

(c)64

(d)Compiler error

(e)None of above

Output: (c)

Explanation:

As we know size of int data type is two byte while char pointer can pointer one byte at time.

Memory representation of int i=320

So char pointer ptr is pointing to only first byte as shown above figure.

35

Page 359: FRP C & DS dumps

*ptr i.e. content of first byte is 01000000 and its decimal value is 64.

How to represent char, int and float data in memory?

Data type tutorial.

(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;

printf("%d",i);

}

(a)343

(b)27

(c)133

(d)Compiler error

(e)None of above

Output: (b)

35

Page 360: FRP C & DS dumps

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. If you will see intermediate file you will find:

test.c 1:

test.c 2: void main(){

test.c 3: int i;

test.c 4: i=5+2*5+2*5+2;

test.c 5: printf("%d",i);

test.c 6: }

test.c 7:

You can absorb #define only pastes the 5+2 in place of x in program. So,

i=5+2*5+2*5+2

=5+10+10+2

=27

What is intermediate file and how to see intermediate file?

Preprocessor tutorial.

36

Page 361: FRP C & DS dumps

(3) What will be output if you will compile and execute the following c code?void main(){

char c=125;

c=c+10;

printf("%d",c);

}

(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. 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,

125+1= 126

125+2= 127

36

Page 362: FRP C & DS dumps

125+3=-128

125+4=-127

125+5=-126

125+6=-125

125+7=-124

125+8=-123

125+9=-122

125+10=-121

What is cyclic nature of data type?

Data type tutorial.

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

void main(){

float a=5.2;

if(a==5.2)

printf("Equal");

else if(a<5.2)

printf("Less than");

else

36

Page 363: FRP C & DS dumps

printf("Greater than");

}(a)Equal

(b)Less than

(c)Greater than

(d)Compiler error

(e)None of above

Output: (b)

Explanation:

5.2 is double constant in c. In c size of double data is 8 byte while a is float variable. Size of float variable is 4 byte.So double constant 5.2 is stored in memory as:

101.00 11001100 11001100 11001100 11001100 11001100 11001101

Content of variable a will store in the memory as:

101.00110 01100110 01100110

It is clear variable a is less than double constant 5.2

Since 5.2 is recurring float number so it different for float and double. Number likes 4.5, 3.25, 5.0 will store same values in float and double data type.

Note: In memory float and double data is stored in completely different way. If you want to see actual memory representation goes to question number (60) and

36

Page 364: FRP C & DS dumps

(61).

Data type tutorial.

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

void main(){

int i=4,x;

x=++i + ++i + ++i;

printf("%d",x);

}

(a)21

(b)18

(c)12

(d)Compiler error

(e)None of above

Output: (a)

Explanation:

In ++a, ++ is pre increment operator. 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.

Step 2: Start assigning final value 7 to all variable i in the expression.

36

Page 365: FRP C & DS dumps

So, i=7+7+7=21

What is break point?

Operator tutorial.

(6) What will be output if you will compile and execute the following c code?void main(){

int a=2;

if(a==2){

a=~a+2<<1;

printf("%d",a);

}

else{ break;

}}

(a)It will print nothing.

(b)-3

(c)-2

(d)1

36

Page 366: FRP C & DS dumps

(e)Compiler error

Output: (e)

Explanation:

Keyword break is not part of if-else statement. 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;

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

}

(a)12 11 11

(b)12 10 10

(c)11 11 12

(d)10 10 12

(e)Compiler error

Output: (a)

36

Page 367: FRP C & DS dumps

Explanation:

In c printf function follows cdecl parameter passing scheme. In this scheme parameter is passed from right to left direction.So first ++a will pass and value of variable will be a=10 then a++ will pass now value variable will be a=10 and at the end a will pass and value of a will be a=12.

What is cedecl and pascal parameter passing convention?Function tutorial.

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

void main(){

char *str="Hello world";

printf("%d",printf("%s",str));

}

(a) 11Hello world

(b) 10Hello world

(c) Hello world10

(d) Hello world11

(e) Compiler error

Output: (d)

36

Page 368: FRP C & DS dumps

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. So, printf(“Hello world”) will return 13.

What is prototype of printf function?

Formatted I/O tutorial.

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

#include "stdio.h"

#include "string.h"

void main(){

char *str=NULL;

strcpy(str,"cquestionbank");

printf("%s",str);

}

(a)cquestionbank

36

Page 369: FRP C & DS dumps

(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.

String tutorial.

More questions of string.

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

#include "stdio.h"

#include "string.h"

void main(){

int i=0;

for(;i<=2;)

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

36

Page 370: FRP C & DS dumps

}

(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.

Complete tutorial of looping in C.

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

void main(){

int x;

for(x=1;x<=5;x++);

printf("%d",x);

}

37

Page 371: FRP C & DS dumps

(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.

Looping tutorial.

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

37

Page 372: FRP C & DS dumps

void main(){

printf("%d",sizeof(5.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.

Detail explanation of all types of constant in C.

37

Page 373: FRP C & DS dumps

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

#include "stdio.h"

#include "string.h"

void main(){

char c='\08';

printf("%d",c);

}

(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. As we know octal digits are: 0, 1, 2, 3, 4, 5, 6, and 7. So 8 is not an octal digit. Hence ‘\08’ is invalid octal character constant.

Octal character constantan.

37

Page 374: FRP C & DS dumps

Hexadecimal character constant.

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

#define call(x,y) x##y

void main(){

int x=5,y=10,xy=20;

printf("%d",xy+call(x,y));

}(a)35

(b)510

(c)15

(d)40

(e)None of above

Output: (d)

Explanation:

## is concatenation c preprocessor operator. It only concatenates the operands i.e.

a##b=ab

37

Page 375: FRP C & DS dumps

If you will see intermediate file then you will find code has converted into following intermediate code before the start of actual compilation.

Intermediate file:

test.c 1:

test.c 2: void main(){

test.c 3: int x=5,y=10,xy=20;

test.c 4: printf("%d",xy+xy);

test.c 5: }

test.c 6:

It is clear call(x, y) has replaced by xy.

What is macro call?

Preprocessor tutorial.

(15) What will be output if you will compile and execute the following c code?int * call();

void main(){

int *ptr;

37

Page 376: FRP C & DS dumps

ptr=call();

clrscr();

printf("%d",*ptr);

}

int * call(){

int a=25;

a++;return &a;}(a)25(b)26(c)Any address(d)Garbage value(e)Compiler error

Output: (d)

Explanation:

In this question variable a is a local variable and its scope and visibility is within the function call. After returning the address of a by function call variable a became dead while pointer ptr is still pointing to address of variable a. This problem is known as dangling pointer problem.

Complete pointer tutorial.

(16) What is error in following declaration?

37

Page 377: FRP C & DS dumps

struct outer{

int a;

struct inner{

char c;

};

};

(a)Nesting of structure is not allowed in c.

(b)It is necessary to initialize the member variable.

(c)Inner structure must have name.

(d)Outer structure must have name.

(e)There is not any error.

Output: (c)

Explanation:

It is necessary to assign name of inner structure at the time of declaration other wise we cannot access the member of inner structure. So correct declaration is:

struct outer{

int a;

37

Page 378: FRP C & DS dumps

struct inner{

char c;

}name;

};

Structure tutorial.

Union tutorial.

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

void main(){

int array[]={10,20,30,40};

printf("%d",-2[array]);

}

(a)-60

(b)-30

(c)60

37

Page 379: FRP C & DS dumps

(d)Garbage value

(e)Compiler error

Output: (b)

Explanation:

In c,

array[2]=*(array+2)=*(2+array)=2[array]=30

Array tutorial.

Array of pointer.

How to read complex pointers.

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

37

Page 380: FRP C & DS dumps

void main(){

int i=10;

static int x=i;

if(x==i)

printf("Equal");

else if(x>i)

printf("Greater than");

else

printf("Less than");}(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. We can not initialize any load time variable by the run time variable.

In this example i is run time variable while x is load time variable.

38

Page 381: FRP C & DS dumps

What is storage class?

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

void main(){

int i=5,j=2;

if(++i>j++||i++>j++)

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

}

(a)7

(b)11

(c)8

(d)9

(e)Compiler error

Output: (d)

Explanation:

38

Page 382: FRP C & DS dumps

|| is logical OR operator. In C logical OR operator doesn’t check second operand if first operand is true.

++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.

Hence i= 6 and j=3

Properties of && operator.

Operator tutorial with examples.

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

#define max 5;

void main(){

38

Page 383: FRP C & DS dumps

int i=0;

i=max++;

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

}

(a)5

(b)6

(c)7

(d)0

(e)Compiler error

Output: (e)

Explanation:

#define is token pasting preprocessor. If you will see intermediate file: test.i

test.c 1:

test.c 2: void main(){

test.c 3: int i=0;

test.c 4: i=5++;

test.c 5: printf("%d",i++);

test.c 6: }

38

Page 384: FRP C & DS dumps

test.c 7:

It is clear macro constant max has replaced by 5. It is illegal to increment the constant number. Hence compiler will show Lvalue required.

What is Lvalue and Rvalue?

How to see intermediate file?

Preprocessor questions and answer.

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

void main(){

double far* p,q;

printf("%d",sizeof(p)+sizeof q);

}

(a)12

38

Page 385: FRP C & DS dumps

(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.

What is near pointer?

What is far pointer?

What is huge pointer?

Complete pointer tutorial.

38

Page 386: FRP C & DS dumps

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

void main(){

int a=5;

float b;

printf("%d",sizeof(++a+b));

printf(" %d",a);

}

(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

38

Page 387: FRP C & DS dumps

//From the rule of automatic type conversion

Hence sizeof operator will return 4 because size of float data type in c is 4 byte.

Value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.

Properties of sizeof operator.

Operators tutorial

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

void main(){

char huge *p=(char *)0XC0563331;

char huge *q=(char *)0XC2551341;

if(p==q)

printf("Equal");

else if(p>q)

printf("Greater than");

else

printf("Less than");

38

Page 388: FRP C & DS dumps

}(a)Equal

(b)Greater than

(c)Less than

(d)Compiler error

(e)None of above

Output: (a)

Explanation:

As we know huge pointers compare its physical address.

Physical address of huge pointer p

Huge address: 0XC0563331

Offset address: 0x3331

Segment address: 0XC056

Physical address= Segment address * 0X10 + Offset address

38

Page 389: FRP C & DS dumps

=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

=0XC2550 + 0X1341

=0XC3891

Since both huge pointers p and q are pointing same physical address so if condition will true.

What is huge pointer?

What is normalization?

38

Page 390: FRP C & DS dumps

Pointer tutorial.

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

void main(){

char *str;

scanf("%[^\n]",str);

printf("%s",str);

}

(a)It will accept a word as a string from user.

(b)It will accept a sentence as a string from user.

(c)It will accept a paragraph as a string from user.

(d)Compiler error

(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.

39

Page 391: FRP C & DS dumps

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

Output: (d)

Explanation:

39

Page 392: FRP C & DS dumps

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]);

}

39

Page 393: FRP C & DS dumps

(a)5 garbage garbage

(b)5 0 0

(c)5 null null

(d)Compiler error

(e)None of abovetput: (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]);

}

39

Page 394: FRP C & DS dumps

(a)4

(b)5

(c)6

(d)7

(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.

39

Page 395: FRP C & DS dumps

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]]);

}

(a)15 18 21

(b)21 21 21

(c)24 24 24

(d)Compiler error

(e)None of above

39

Page 396: FRP C & DS dumps

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.

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?

39

Page 397: FRP C & DS dumps

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

Output: (b)

Explanation:

Default parameter passing scheme of c is cdecl i.e. argument of function will pass from right to left direction.

39

Page 398: FRP C & DS dumps

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");

}

39

Page 399: FRP C & DS dumps

(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.

39

Page 400: FRP C & DS dumps

Memory map tutorial.

More questions based on memory map.

(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

40

Page 401: FRP C & DS dumps

Output: (e)

Explanation:

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); }

40

Page 402: FRP C & DS dumps

(a)5 10

(b)6 11

(c)5 11

(d)6 10

(e)Compiler error

Output: (c)

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?

40

Page 403: FRP C & DS dumps

(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

Output: (c)

Explanation:

40

Page 404: FRP C & DS dumps

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

(b)-18

(c)1

40

Page 405: FRP C & DS dumps

(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.

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

void main(){

40

Page 406: FRP C & DS dumps

asm{

mov bx,8;

mov cx,10

add bx,cx;

}

printf("%d",_BX);

}

(a)18

(b)8

(c)0

(d)Compiler error

(e)None of above

Output: (a)

40

Page 407: FRP C & DS dumps

Explanation:

asm keyword is used to write assembly language program in c. mov command stores the constants in the register bx, cx etc. add command stores the content of register and stores in first register i.e. in bx.

How to write assembly language program by c?

Advance c tutorial.

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

void main(){

enum xxx{

a,b,c=32767,d,e

};

printf("%d",b);

}

(a)0

(b)1

40

Page 408: FRP C & DS dumps

(c)32766

(d)Compiler error

(e)None of above

Output: (d)

Explanation:

Size of enum constant is size of sign int. Since value of c=32767. Hence value of d will be 32767+1=32768 which is beyond the range of enum constant.

Tutorial of data type with examples.

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

void main(){

signed int a=-1;

40

Page 409: FRP C & DS dumps

unsigned int b=-1;

if(a==b)

printf("%d %d",a,b);

else

printf("Not equal");

}

(a)-1 -1

(b)-1 32767

(c)-1 -32768

(d)Not equal

(e)Compiler error

Output: (a)

Explanation:

40

Page 410: FRP C & DS dumps

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.5f;

float x;

x=f%2;

printf("%f",x);

}

(a)1.500000

(b)1.000000

(c)5.500000

(d)Compiler error

(e)None of above

41

Page 411: FRP C & DS dumps

Output: (d)

Explanation:

Modular division is not allowed with floating number.

Properties of modular division.

Operators tutorial with examples.

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

void main(){

int a=-20;

int b=-3;

printf("%d",a%b);

}

(a)2

(b)-2

41

Page 412: FRP C & DS dumps

(c)18

(d)-18

(e)Compiler error

Output: (b)

Explanation:

Sign of resultant of modular division depends upon only the sign of first operand.

Properties of modular division.

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';

printf("%d %d",sizeof(c),sizeof('0'));

41

Page 413: FRP C & DS dumps

}

(a)1 1

(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.

Why character constant is of two byte in c?

41

Page 414: FRP C & DS dumps

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

void main(){

char *url="c:\tc\bin\rw.c";

printf("%s",url);

}

(a)c:\tc\bin\rw.c

(b)c:/tc/bin/rw.c

(c)c: c inw.c

(d)c:cinw.c

(e)w.c in

Output: (e)

Explanation:

41

Page 415: FRP C & DS dumps

1. \t is tab character which moves the cursor 8 space right.

2. \b is back space character which moves the cursor one space back.

3. \r is carriage return character which moves the cursor beginning of the line.

Complete string tutorial with examples.

Properties of escape characters.

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

void main(){

clrscr();

goto abc;

printf("main");

getch();

}

41

Page 416: FRP C & DS dumps

void dispaly(){

abc:printf("display");

}(a)main

(b)display

(c)maindisplay

(d)displaymain

(e)Compiler error

Output: (e)

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.

41

Page 417: FRP C & DS dumps

Complete function tutorial with examples.

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

void main(){

int i=3;

if(3==i)

printf("%d",i<<2<<1);

else

printf("Not equal");

}

(a)1

(b)48

(c)24

(d)Not equal

(e)Compiler error

41

Page 418: FRP C & DS dumps

Output: (c)

Explanation:

Associative of bitwise left shifting operator is left to right. In the following expression:

i<<2<<1

There are two bitwise operators. From rule of associative leftmost operator will execute first.

i <<><<>

After execution of leftmost bitwise left shifting operator:

so i=i*pow(2,2)

=3*

What is associative?

What is precedence?

Tutorial of bitwise operators.

41

Page 419: FRP C & DS dumps

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

void main(){

int x=2,y=3;

if(x+y<=5)

printf("True");

else

printf("False");

}

(a)True

(b)False

(c)Compiler error: Lvalued required

(d)Compiler error: Invalid expression

(e)None of above

41

Page 420: FRP C & DS dumps

Output: (a)

Explanation:

Expression x+y<=5

=> 2+3 <=5

=> 5<=5 is true because 5 is either greater than 5 or equal to 5.

Operator tutorial with examples.

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

void main(){

const int i=5;

i++;

printf("%d",i);

}

(a)5

(b)6

42

Page 421: FRP C & DS dumps

(c)0

(d)Compiler error

(e)None of above

Output: (d)

Explanation:

We cannot modify the const variable by using increment operator.

Properties of const keyword.

Properties of volatile keyword.

Data type tutorial with examples.

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

42

Page 422: FRP C & DS dumps

void main(){

const int x=25;

int * const p=&x;

*p=2*x;

printf("%d",x);

}

(a)25

(b)50

(c)0

(d)Compiler error

(e)None of above

Output: (b)

Explanation:

42

Page 423: FRP C & DS dumps

const keyword in c doesn’t make any variable as constant but it only makes the variable as read only. With the help of pointer we can modify the const variable. In this example pointer p is pointing to address of variable x. In the following line:

int * const p=&x;

p is constant pointer while content of p i.e. *p is not constant.

*p=2*x put the value 50 at the memory location of variable x.

Properties of const keyword.

What is constant pointer?

Data type tutorial with examples.

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

void main(){

int i=11;

int const * p=&i;

p++;

printf("%d",*p);

42

Page 424: FRP C & DS dumps

}

(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;

*p i.e. content of p is constant pointer p is not constant pointer. So we can modify the pointer p. After incrementing the pointer it will point next memory location and its content will any garbage value.

42

Page 425: FRP C & DS dumps

Note: We have assumed arbitrary memory address.

To make pointer p as constant pointer write:

int const * const p=&i;

Properties of const keyword.

Properties of volatile keyword.

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

void main(){

int a=15,b=10,c=5;

if(a>b>c )

printf("Trre");

else

42

Page 426: FRP C & DS dumps

printf("False");

}

(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. So in the following expression

a > b > c

Associative of relational operators are left to right order of execution will be following manner:

42

Page 427: FRP C & DS dumps

Hence in this expression first solve bolded condition: a > b > c

Since condition a>b is true so result will be 1. Now expression became:

1 > c

Since this condition is false so result will be 0. Thus else part will execute.

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;

f=3/2;

42

Page 428: FRP C & DS dumps

printf("%f",f);

}

(a)1.5

(b)1.500000

(c)1.000000

(d)Compiler error

(e)None of above

Output: (c)

Explanation:

In the following expression:

f=3/2 both 3 and 2 are integer constant hence its result will also be an integer constant i.e. 1.

Properties of floating type numbers.

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

void main(){

int a=sizeof(a);

a=modify(a);

42

Page 429: FRP C & DS dumps

printf("%d",a);

}

int modify(int x){

int y=3;

_AX=x+y;return;}(a)2

(b)3

(c)5

(d)Garbage value

(e)None of above

Output: (c)

Explanation:

_AX is register pseudo variable. It stores return type of function.

What is register pseudo variable?

42

Page 430: FRP C & DS dumps

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++");

void main(){

float a=5.5;

if(a==5.5)

PRINT

else

printf("Not equal");

}(a)c c++

(b)Not equal

(c)c

c++

(d)Compiler error

(e)None of above

43

Page 431: FRP C & DS dumps

Output: (d)

Explanation:

First see intermediate file:

try.c 1:

try.c 2: void main(){

try.c 3: float a=5.5;

try.c 4: if(a==5.5)

try.c 5: printf("c");printf("c++");

try.c 6: else

try.c 7: printf("Not equal");

try.c 8: }

try.c 9:

try.c 10:

43

Page 432: FRP C & DS dumps

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.

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;

int c:3;

43

Page 433: FRP C & DS dumps

int m:2;

};

void main(){

struct marks s={2,-6,5};

printf("%d %d %d",s.p,s.c,s.m);

}(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

43

Page 434: FRP C & DS dumps

More questions

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

void main(){

static char *s[3]={"math","phy","che"};

typedef char *( *ppp)[3];

static ppp p1=&s,p2=&s,p3=&s;

char * (*(*array[3]))[3]={&p1,&p2,&p3};

char * (*(*(*ptr)[3]))[3]=&array;

p2+=1;

p3+=2;

printf("%s",(***ptr[0])[2]);

}

(a) math

(b) phy

43

Page 435: FRP C & DS dumps

(c) che

(d) Compiler error

(e) None of these

Answer: (c)

Explanation:

Here

ptr: is pointer to array of pointer to string.

P1, p2, p3: are pointers to array of string.

array[3]: is array which contain pointer to array of string.

Pictorial representation:

43

Page 436: FRP C & DS dumps

Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.

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?

Pointer tutorial.

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

#include"conio.h"

int display();

43

Page 437: FRP C & DS dumps

int(*array[3])();

int(*(*ptr)[3])();

void main(){

array[0]=display;

array[1]=getch;

ptr=&array;

printf("%d",(**ptr)());

(*(*ptr+1))();

}

int display(){

int x=5;

return x++;

}

(a)5

(b)6

(c)0

(d)Compiler error

(e)None of these

43

Page 438: FRP C & DS dumps

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: 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]

43

Page 439: FRP C & DS dumps

=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;

char far *ptr=(char *)0XB8000000;

*ptr='A';

*(ptr+1)=1;

*(ptr+2)='B';

*(ptr+3)=2;

*(ptr+4)='C';

*(ptr+5)=4;

}

43

Page 440: FRP C & DS dumps

Answer:

It output will be A, B and C in blue, green and red color respectively. As shown in following figure:

What is far pointer?

Advance c tutorial?

Working with text video memory.

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

44

Page 441: FRP C & DS dumps

#include "dos.h"

void main(){

int j;

union REGS i,o;

char far *ptr=(char *)0XA0000000;

i.h.ah=0;

i.h.al=0x13;

int86(0x10,&i,&o);

for(j=1;j<=100;j++){

*(ptr+j)=4;

}

}

Answer:

44

Page 442: FRP C & DS dumps

One red color line in the graphics console as shown in the following figure

What is union REGS?

Advance c tutorial.

Working with graphics video memory.

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

void main(){

int huge*p=(int huge*)0XC0563331;

int huge*q=(int huge*)0xC2551341;

*p=200;

44

Page 443: FRP C & DS dumps

printf("%d",*q);

}

(a)0

(b)Garbage value

(c)null

(d) 200

(e)Compiler error

Answer: (d)

Explanation:

Physical address of huge pointer p

Huge address: 0XC0563331

44

Page 444: FRP C & DS dumps

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

=0XC2550 + 0X1341

=0XC3891

44

Page 445: FRP C & DS dumps

Since both huge pointers p and q are pointing same physical address so content of q will also same as content of q.

What is huge pointer?

Pointer tutorial.

(57) Write c program which display mouse pointer and position of pointer.(In x coordinate, y coordinate)?

Answer:

#include”dos.h”

#include”stdio.h”

void main()

{

union REGS i,o;

int x,y,k;

44

Page 446: FRP C & DS dumps

//show mouse pointer

i.x.ax=1;

int86(0x33,&i,&o);

while(!kbhit()) //its value will false when we hit key in the key board

{

i.x.ax=3; //get mouse position

x=o.x.cx;

y=o.x.dx;

clrscr();

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

delay(250);

int86(0x33,&i,&o);

}

getch();

}

What is int86?

Advance c tutorial.

(58) Write a c program to create dos command: dir.

44

Page 447: FRP C & DS dumps

Answer:

Step 1: Write following code.

#include “stdio.h”

#include “dos.h”

void main(int count,char *argv[])

{

struct find_t q ;

int a;

if(count==1)

argv[1]="*.*";

a = _dos_findfirst(argv[1],1,&q);

if(a==0)

{

while (!a)

{

printf(" %s\n", q.name);

a = _dos_findnext(&q);

44

Page 448: FRP C & DS dumps

}

}

else

{

printf("File not found");

}

}

Step 2: Save the as list.c (You can give any name)

Step 3: Compile and execute the file.

Step 4: Write click on My computer of Window XP operating system and select properties.

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:

44

Page 449: FRP C & DS dumps

Variable name: path

Variable value: c:\tc\bin\list.c (Path where you have saved)

Step 8: Open command prompt and write list and press enter.

Command line argument tutorial.

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

void main(){

int i=10;

static int x=i;

if(x==i)

printf("Equal");

else if(x>i)

printf("Greater than");

else

44

Page 450: FRP C & DS dumps

printf("Less than");

}(a) Equal

(b) Greater than

(c) Less than

(d) Compiler error

(e) None of above

Answer: (d)

Explanation:

static variables are load time entity while auto variables are run time entity. We can not initialize any load time variable by the run time variable.

In this example i is run time variable while x is load time variable.

Properties of static variables.

45

Page 451: FRP C & DS dumps

Properties of auto variables.

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

void main(){

int i;

float a=5.2;

char *ptr;

ptr=(char *)&a;

for(i=0;i<=3;i++)

printf("%d ",*ptr++);

}

(a)0 0 0 0

(b)Garbage Garbage Garbage Garbage

(c)102 56 -80 32

(d)102 102 -90 64

(e)Compiler error

45

Page 452: FRP C & DS dumps

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.

Content of fourth byte:

Binary value=01100110

Decimal value= 64+32+4+2=102

Content of third byte:

Binary value=01100110

45

Page 453: FRP C & DS dumps

Decimal value=64+32+4+2=102

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.e. left most bit of above figure as sign bit.

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.2;

char *ptr;

ptr=(char *)&a;

45

Page 454: FRP C & DS dumps

for(i=0;i<=7;i++)

printf("%d ",*ptr++);

}

(a) -51 -52 -52 -52 -52 -52 20 64

(b) 51 52 52 52 52 52 20 64

(c) Eight garbage values.

(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.

Memory representation of double a=5.2

45

Page 455: FRP C & DS dumps

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.

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

45

Page 456: FRP C & DS dumps

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

Decimal value=64

Note: Character pointer treats MSB bit of each byte i.e. 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?

45

Page 457: FRP C & DS dumps

void main(){

printf("%s","c" "question" "bank");

}

(a) c question bank

(b) c

(c) bank

(d) cquestionbank

(e) Compiler error

Answer: (d)

Explanation:

In c string constant “xy” is same as “x” “y”

String tutorial.

45

Page 458: FRP C & DS dumps

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

void main(){

printf("%s",__DATE__);

}

(a) Current system date

(b) Current system date with time

(c) null

(d) Compiler error

(e) None of these

Answer: (a)

45

Page 459: FRP C & DS dumps

Explanation:

__DATE__ is global identifier which returns current system date.

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";

printf("%*.*s",10,7,str);

}

(a) c-pointer

(b) c-pointer

(c) c-point

(d) cpointer null null

(e) c-point

45

Page 460: FRP C & DS dumps

Answer: (e)

Explanation:

Meaning of %*.*s in the printf function:

First * indicates the width i.e. how many spaces will take to print the string and second * indicates how many characters will print of any string.

Following figure illustrates output of above code:

Properties of printf function.

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

void start();

46

Page 461: FRP C & DS dumps

void end();

#pragma startup start

#pragma exit end

int static i;

void main(){

printf("\nmain function: %d",++i);

}

void start(){

clrscr();

printf("\nstart function: %d",++i);

}

void end(){

printf("\nend function: %d",++i);

getch();

}

(a)

main function: 2

start function: 1

end function:3

46

Page 462: FRP C & DS dumps

(b)

start function: 1

main function: 2

end function:3

(c)

main function: 2

end function:3

start function: 1

(d) Compiler error

(e) None of these

46

Page 463: FRP C & DS dumps

Answer: (b)

Explanation:

Every c program start with main function and terminate with null statement. But #pragma startup can call function just before main function and #pragma exit

What is pragma directive?

Preprocessor tutorial.

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

void main(){

int a=-12;

a=a>>3;

printf("%d",a);

}

(a) -4

(b) -3

46

Page 464: FRP C & DS dumps

(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.e.

So binary value of -12 is: 11111111 11110100

46

Page 465: FRP C & DS dumps

Right shifting rule:

Rule 1: If number is positive the fill vacant spaces in the left side by 0.

Rule 2: If number is negative the fill vacant spaces in the left side by 1.

In this case number is negative. 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.

Hence final out put will be:

46

Page 466: FRP C & DS dumps

And its decimal value is: 2

Hence output will be:-2

More questions on shifting operator.

Operator tutorial.

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

#include "string.h"

void main(){

clrscr();

printf("%d %d",sizeof("string"),strlen("string"));

getch();

}

(a) 6 6

46

Page 467: FRP C & DS dumps

(b) 7 7

(c) 6 7

(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.

String tutorial.

Library functions of string.

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

46

Page 468: FRP C & DS dumps

void main(){

static main;

int x;

x=call(main);

clrscr();

printf("%d ",x);

getch();

}

int call(int address){

address++;

return address;

}(a) 0(b) 1(c) Garbage value(d) Compiler error(e) None of these

46

Page 469: FRP C & DS dumps

Answer: (b)

Explanation:

As we know main is not keyword of c but is special type of function. Word main can be name variable in the main and other functions.

What is main function in c?

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

void main(){

int a,b;

a=1,3,15;

b=(2,4,6);

clrscr();

printf("%d ",a+b);

getch();

}

46

Page 470: FRP C & DS dumps

(a) 3

(b) 21

(c) 17

(d) 7

(e) Compiler error

Answer: (d)

Explanation:

In c comma behaves as separator as well as operator.

a=1, 3, 15;

b= (2, 4, 6);

In the above two statements comma is working as operator. Comma enjoys least precedence and associative is left to right.

Assigning the priority of each operator in the first statement:

47

Page 471: FRP C & DS dumps

Hence 1 will assign to a.

Assigning the priority of each operator in the second statement:

Operator tutorial.

47

Page 472: FRP C & DS dumps

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

int dynamic(int,...);

void main(){

int x,y;

x=dynamic(2,4,6,8,10,12,14);

y=dynamic(3,6,9,12);

clrscr();

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

getch();

}

int dynamic(int s,...){

void *ptr;

ptr=...;

(int *)ptr+=2;

s=*(int *)ptr;

return s;

}

47

Page 473: FRP C & DS dumps

(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. After incrementing it will point third element.

What is variable number of argument?

47

Page 474: FRP C & DS dumps

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

int extern x;

void main()

printf("%d",x);

x=2;

getch();

}

int x=23;

(a) 0

(b) 2

(c) 23

(d) Compiler error

(e) None of these

47

Page 475: FRP C & DS dumps

Answer: (c)

Explanation:

extern variables can search the declaration of variable any where in the program.

Properties of extern storage class.

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

void main(){

int i=0;

if(i==0){

i=((5,(i=3)),i=1);

printf("%d",i);

}

else

printf("equal");

}

47

Page 476: FRP C & DS dumps

(a) 5

(b) 3

(c) 1

(d) equal

(e) None of above

Answer: (c)

Explanation:

Comma operator.

Operator tutorial.

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

47

Page 477: FRP C & DS dumps

void main(){

int a=25;

clrscr();

printf("%o %x",a,a);

getch();

}

(a) 25 25

(b) 025 0x25

(c) 12 42

(d) 31 19

(e) None of these

Answer: (d)

Explanation:

47

Page 478: FRP C & DS dumps

%o is used to print the number in octal number format.

%x is used to print the number in hexadecimal number format.

Note: In c octal number starts with 0 and hexadecimal number starts with 0x.

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();

printf("%s",message);

getch();

}

47

Page 479: FRP C & DS dumps

(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 \.

Preprocessor tutorial.

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

47

Page 480: FRP C & DS dumps

#define call(x) #x

void main(){

printf("%s",call(c/c++));

}

(a)c

(b)c++

(c)#c/c++

(d)c/c++

(e)Compiler error

Answer: (d)

Explanation:

48

Page 481: FRP C & DS dumps

# is string operator. It converts the macro function call argument in the string. First see the intermediate file:

test.c 1:

test.c 2: void main(){

test.c 3: printf("%s","c/c++");

test.c 4: }

test.c 5:

It is clear macro call is replaced by its argument in the string format.

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");

48

Page 482: FRP C & DS dumps

else

printf("I know c++");

}

(a) I know c

(b) I know c++

(c) cquestionbankI know c

(d) cquestionbankI know c++

(e) Compiler error

Answer: (c)

Explanation:

Return type of printf function is integer which returns number of character it prints including blank spaces. So printf function inside if condition will return 13. In if condition any non- zero number means true so else part will not execute.

48

Page 483: FRP C & DS dumps

Prototype of printf function.

1. Which of the following does not have an unary operator?

1) -7 2) ++i3) j 4) all of the above

2. In printf(),the appearance of the output of the output can be affected by

1) field with 2) conversion character3) flag 4) all of the above

3. Any of the following programs in c has access to three standard files:

1) standard input file, standard output file, standard error file2) stdin,stdout, stderr3) keyboard,screen,screen4) all the above

5) A variable can be declared static using the keyword.1) extern 2) static3) stat 4) auto

6) A program can be terminated at any time by calling the function

1) fflush() 2) ferror()3) exit() 4) clearerr()

7) Heap

48

Page 484: FRP C & DS dumps

1) is a region from where memory is allocated2) lies between you program and the stack3) is a finite area4) all of the above

8) A function can

1) perform a task 2) return a value3) change value of actual arguments in call by reference4) all of the above

9) Function definition void check(int i ,char*j) is1) call by value 2)call by reference3) 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 memory2) must be structure 3) are grouped next to each other in memory4) all have the same type

11) Which of the following array is defined in the statements Char name[30]?

1) name is one dimensiona,30-element integer array2) name is one dimensional,30-element floating point array3) name is one dimensional ,30-element character array4) name is one dimensional,30-elements string array

12) c program contains the following declaration:Static float table[2][3]={ {1.1,1.2,1.3},

{2.1,2.2,2.3}};

What is the value of *(*(table+1)+1)?

48

Page 485: FRP C & DS dumps

1) 2.2 2) 1.23) 2.1 4) 2.3

13) A c program contains the following declarations and initial Assignments:

int i=8,j=5; float x=0.0005,y=-0.01;Char c=’c’,d=’d’;What would be the value of the following expression?

(3*i-2*j)%(2*d-3) 1)14 2)18 3) 1 4) 0

14) The declaration : int f(int); means

1) f accepts an integer argument and returns an integer quantity2) f accepts two arguments and returns a double precision quantity, and the second is an integer3) f accepts three arguments and returns nothing. The first argumentsis a double-precision quantity, and the second is an integer4) f does not accepts any arguments but returns a single character

16) The arguments of a function are included between1) The parenthesis 2) double quotes3) curly braces 4) #

17) The int type of constraints are whole numbers in the range

1) -23677 to 23678 2) -32768 to 327673) -32767 to 32768 4) -32864 to 32864

18) If the variables i,j and k are assigned the values 5,3 and 2 respectively, then the expression i=j+(k++ =6)+7;

1) gives an error message 2) assigns a value 16 to i

48

Page 486: FRP C & DS dumps

3) assigns a value 18 to i 4) assigns a value 19 to i

19) In a relational expression involving characters, we actually Compare

1) the ASCII codes of the characters2) the characters themselves3) neither of the two4) binary code and hexadecimal code

21) The word case used in the switch statement represents a

1) function in the c language2) data type in the c language3) keyword in the c language4) global variable in the c language

22)The logical NOT operator represented by ! is a

1) unary operator 2) binary operator3) ternary operator 4) octal operator

23) The statement : scanf(“%d”,&i);

1) assigns an integer to the variable i2) gives an error message;3) does not assign any value to i4) assigns an float to the variable i

24) A pointer is declared by using a statement such as

1) int *p; 2) point; 3) pointer *p; 4) int &p;

25)The null character is represented by

1) \n 2)\0 3)\o 4)\t

48

Page 487: FRP C & DS dumps

26) The members in the union

1) have different memory locations2) share the memory with a structure3) have the same memory location4) have different memory variable

27) The global variables by default belong to

1) the register type 2) the static type3) the auto 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, 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 number2) controls the size of type used to print numbers3) controls the merging of the program listing4) specifies how many characters positions will be used for a number

31) The two operators && and || are

1) arithmetic operators 2) equality operators3) logical operators 4) relational operators

32) The library files that come with c are

48

Page 488: FRP C & DS dumps

1) text editor for program development 2) the compiler and liker3) program examples4) files that contain functions which carry out various commonly Used operations and calculations

33) Precedence determines which operator

1) is evaluated first2) is most important3) is fastest 4) operates on the largest number

37) The malloc() function

1) returns a pointer to the allocated memory2) returns a pointer to the first byte of region of memory3) changes the size of the allocated memory4) 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)XOR 4)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

48

Page 489: FRP C & DS dumps

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 message2) assigns a value 4 to p3) 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 2) curly braces3) parentesis 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 2) double quotes3) parenthesis 4) / and /

49) One structure can be

1) a member of some other structure2) a member of the same structure3) a member of a union4) all of the above

48

Page 490: FRP C & DS dumps

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( ) 3) putchar( ) 4) scanf( )

53) An expression

1) is a collection of data objects and operators that can be evaluated to a single value

2) is a name that substitutes for a sequence of characters3) causes the computer to carry out some action4) all of the above

54) The expression c=i++ causes

1) the value of I assigned to c and then I incremented by 12) I to be incremented by 1 and then the value of I assigned to @3) Value of I assigned to c4) I to be incremented by 1

55)The single character input/output functions are

1) scanf( ) and printf( ) 2) getchar( ) and printf( )3) scanf( ) and putchar( ) 4) getchar( ) and putchar( )

56) The conversion character ‘I’ for data output means that theData item is displayed as

49

Page 491: FRP C & DS dumps

1) a floating point value with an exponent2) an unsigned decimal integer3) a signed decimal integer4) an octal integer

58) In a circular linked list

1) components are all linked together in some sequential manner2) there is no beginning and no end3) components are arranged hierarchically4) forward and backward transversal within the list is permitted

60) A c function contain

1)function body 2)argument declaration3)a function header 4)all of the above C QUESTIONS ON ARRAYS

1. main(){Int a[5];a[-2]=10;a[2]=1;printf(“%d”,-2[a]);}

a) compilation error b)10 c)-1 d)none of the aboveAns c

2. main(){ Char a[3][3]={{‘a’,’b’,’c’},”pqr”,”xy”}; Printf(“%s\n”,&a[0][0]);}

a) a b)compilation error c)abcpqrxy d)abcAns c

3. main()

49

Page 492: FRP C & DS dumps

{ char a[3][3]={“abc”,”pqr”,”xyz”}; printf(“%c”,a[2][2]);}

a) q b) r c) z d) compilation errorAns c

4) main(){ Char a[100]={“abcdef”}; a++; printf(“%s”,&a[1]);}

b) bcdef b) abcdef c)compilation error d) none of the aboveAns c

5) main(){ Char *p=”algc”; Printf(“%c”,++*(p++)); Printf(“%c”,*++p);}

a) al b) bg c) lg d) none of the above

ans b

6) main() { Int n[25]; n[0]=100; n[24]=200; printf(“%d%d”,*n,*(n+24)+*(n+0)); }

a) 100 200 b) 100 300 c) 0,100 d) 0,200Ans b

49

Page 493: FRP C & DS dumps

7)main(){Int a[3]={1};Printf(“%d”,a[1]);}

a) 1 b) 0 c) compillation error d) none of the above

Ans b

8) main(){Static int n[3][3]={2,4,3,6,8,5,3,5,1};Printf(“%d%d%d”,n[2][1],n[1][1],n[3][1]);}

a)5 8 garbage value b) 845 c)623 d)825ans a)

9) main(){Char a=’ab’;Printf(“%c”,a);}

a) a b) b c) ab d) errorans a)

10) main(){Char *p;p=”%d\n”;p[1]=’c’;printf(p,65);}

a) A b) c c) 65 d) errorans a

11) main()

49

Page 494: FRP C & DS dumps

{int a=1;switch(a==5){

Case 1: pf(“hi”);Break;

Case 0:pf(“hello”);break;Default : pf(“wipro\n”);

}}

a) Hi b)hello c) hi d)wipro

Ans: b

12) main(){

Char a[]={“\012345\”};Printf(“%s %d %d\n”,a,sizeof(a),sizeof(*a));

}

13) main(){

Char a[]=”hell0009”;Printf(“%s\n”,a);

}

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.b) data & pointer to hold the address of next node.c) data & pointer to hold the address of previous node.d) pointer to hold the address of next and previous node. Ans b

49

Page 495: FRP C & DS dumps

2) what does the last node link containa) address of first nodeb) address of that nodec) nulld) address of previous nodeans c

3) steps involved in insertion of a nodea) Creating a new node.b) Accepting data into the nodec) If the list does not exist, assign start to the new node.d) If the list exists insert the new node at the end of the list.a) 1 2 3 4b) 1 3 2 4c) 4 3 2 1d) 3 1 2 4 Ans a)

4) steps involved in traversing the list 1) store the address of the start node in a temporary variable.2) Repeat steps 2 & 3 until the the temporary pointer points to null.3) Print data in the node.4) Move the temporary pointer pointer to the next node. a) 1 2 3 4b) 1 4 3 2c) 1 3 4 2d) 2 3 1 4Ans c

5) steps involved in traversing the list 1) Free the memory occupied by the deleted node.2) if the node to be deleted is the start then start 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.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. e) 1 2 3 4

49

Page 496: FRP C & DS dumps

f) 3 2 4 1g) 1 3 2 4h) 2 4 3 1

Ans f

6) if a node (q) is to be inserted at the beginning the operations which are performed is1) q->next =start->next

start =q;

2) start=q;q->next=start;

3) q->next=start;q=start;

4) q->next =start;start =q;

ans 4

7) when start and last points to same node,how many elements are present1) 0 2)1 3)2 4)3Ans 2

8)memory is allocated in single linked list a) dynamically b)compile time c)statically d) linking time.Ans : a

1).What would be the output of the following program. main() { int a[5]={2,3}; printf("\n %d %d %d",a[2],a[3],a[4]); } (a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0

ans::d

49

Page 497: FRP C & DS dumps

2).What would be the output of the following program. main() { int i=-3,j=2,k=0,m; m=++i&&++j||++k; printf("\n %d %d %d %d",i,j,k,m); }(a) -2 3 0 1 (b) -3 2 0 1 (c) -2 3 1 1 (d) errorans::a3) main() { Int n[25]; n[0]=100; n[24]=200; printf(“%d%d”,*n,*(n+24)+*(n+0)); }a)100 200 b) 100 300 c) 0,100 d) 0,2004)

main(){

char str[]="I am in wipro";printf("%s\n",&str[5]);

}

ans::in wipro

5) main(){ Char *p=”algc”; Printf(“%c”,++*p++); Printf(“%c”,*++p);}

a)al b) mg c) lg d) none

ans::none.....bg6)main(){

void fun(int);

49

Page 498: FRP C & DS dumps

int n=3;fun(n);

}void fun(int n){

if(n>0){

fun(--n);printf("%d",n);fun(--n);

}} ans::0120

7).What would be the output of the following program. main() { struct emp { char name[20]; int age; float sal; }; struct emp e = {"tiger"}; printf("\n %d %f",e.age,e.sal); } (a) 0 0.000000 (b) Garbage values (c) Error (d) none of the above

ans::a8).main( ){ int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) {

printf(“%d” ,*a); a++;

} p = a; for(j=0; j<5; j++) {

49

Page 499: FRP C & DS dumps

printf(“%d ” ,*p); p++;

} }Ans::Error Lvalue Required...can't change the base address a++9.main()

{ int c[ ]={2,3,4,6,5};

int j,*p=c,*q=c;

for(j=0;j<5;j++) {

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

} for(j=0;j<5;j++)

{printf(" %d ",*p);++p; }

}

ans::22222346510.#define ABC 20#define XYZ 10#define XXX ABC - XYZvoid main(){

int a;

a = XXX * 10;

printf("%d\n", a);}ans::-80

11. #define calc(a, b) (a * b) / (a - b)

49

Page 500: FRP C & DS dumps

void main(){

int a = 20, b = 10;

printf("%d\n", calc(a + 4, b -2));}12.void main(){

int cnt = 5, a;

do {a /= cnt;

} while (cnt --);

printf ("%d\n", a);}ans::Error..divide error13. void main(){

int a, b, c, abc = 0;

a = b = c = 40;

if (c) {int abc;

abc = a*b+c;}

printf ("c = %d, abc = %d\n", c, abc);}ans::40 014.main(){

int k = 5;

if (++k < 5 && k++/5 || ++k <= 8)

printf("%d\n", k);}

50

Page 501: FRP C & DS dumps

ans::715.main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++)

printf("%s",names[i]);}ans::Error......base address can't be changed names[3]=names[4]

16.main()

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

}ans::57 9417.Assume that integer is 4 bytes,pointer as 4 byter and character

as 1 byte,then predict the outputstruct student{ int a; char name[10]; int *p;}s1,*s2;printf("%d%d",sizeof(s1),sizeof(*s2));

a) 18,18b)18,4c) 4,18d) 4,4

18.int fun(int x) {

50

Page 502: FRP C & DS dumps

int y=55;return((x-y)?y:x);

} main() { int a=20; fun(a); printf("%d",y); }ans::20

19.int compute(int n) {

if(n>0) {

n=compute(n-3)+compute(n-1);return(n);

}return(1);

}void main(){printf("%d",compute(5));}

20.int main(){char *ptr="abcdefgh";char *sptr;sptr=ptr+5;printf("%s",sptr);}

ans::fgh

50

Page 503: FRP C & DS dumps

1. printf("%d %d %d",sizeof(25.75),sizeof(123),sizeof(‘p’))a. 2 2 2 b. 4 2 2 c. 8 4 1 d. 8 2 2ans::d

50

Page 504: FRP C & DS dumps

2. int i=5;fun( ){

printf("%d\n", i * 3);}main( ){

int i= 2;{int i = 3;printf(" %d", i);fun();}

}b. 3, 15 c. 3, 6d. 3 e. 0

Ans::a3. #define xsq(x) x*x

main( ){

int i, j;i = 5;j = xsq(i-2);printf(“%d\n”, j);

}a. –7 b. 9c. 13d. 29

Ans::-74. main( ) {

int a=35;printf(“ %d %d %d\n”, a == 35,a=50,a>40);

}a. 1 50 1

50

Page 505: FRP C & DS dumps

b. 1 50 0c. 0 50 0d. 0 50 1

ans::c

5. void main(){char a[]="123abcd";clrscr();printf("%d",strlen(a));getch();}

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

Ans::76. main(){static int var=5;if(var--){printf("%d",var);main();}}

a. 4 3 2 1 0 b. 4 3 2 1c. 5 4 3 2 1d. 5 4 3 2 1 0ans::a7. void main(){int i=1,j=2;switch(i){case 1: printf("One"); break;case j: printf("Two"); break;

50

Page 506: FRP C & DS dumps

default: printf(“Default”); break;}}a. Oneb. Twoc. Defaultd. Compiler Errorans::d8. void main(){switch('a'){case 'A': printf("Zero"); break;case 97: printf("One"); break;default: printf("Error"); break;}}

a. Zerob. Onec. Errord. Compiler Errorans::b9. void main(){

int p=1,sum=0;clrscr();while(p<20){

p++;sum+=p++;

}printf("\nsum=%d",sum);

}

a. 120b. 100c. 110d. Errorans::A

50

Page 507: FRP C & DS dumps

10. int x;int modifyvalue(){return(x+=10);}

int changevalue(int x){return(x+=1);}

void main(){int x=10;x++;changevalue(x);x++;modifyvalue();printf("First output : %d",x);changevalue(x);printf("\nSecond output : %d",x);}

a. 12 12b. 11 12c. 12 13d. 13 13

11. main(){static i=3;printf("%d",i--);return i>0?main():0;}

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

50

Page 508: FRP C & DS dumps

12. void main(){char *ptr="Hello World";*ptr++;printf("%s",ptr);ptr++;printf("%s",ptr);}

a. Iello World Iello Worldb. Hello World ello Worldc. ello World ello Worldd. ello World llo World

13. int const *p;*p=5;printf("%d",*p++);

a. 5b. 6c. Compiler Errord. Garbage Valueans::c14. void main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("ab"));}

a. 5 5 3b. 4 5 3c. 2 5 3d. 1 5 3ans::c15. P is a character pointer variable then, what will be the output of the following statement.printf("%d %d",sizeof(p),sizeof(*p));

a. 1 2

50

Page 509: FRP C & DS dumps

b. 2 1c. 2 2d. 1 1ans::b16. void main(){char *s[]={"dharma","hewlet-packard","siemens","ibm"};char **p;p=s;printf("%s",++*p);printf("\n%s",*p++);printf("\n%s",++*p);}

a. harma harma ewlet-packardb. dharma harma ewlet-packardc. harma hewlet-packard siemensd. harma harma hewlet-packardans::d17. void main(){char *ptr="Ramco Systems"; (*ptr)++;printf("%s\n",ptr);ptr++;printf("%s",ptr);}

a. Samco Systems Samco Systemsb. Samco Systems amco Systemsc. amco Systems amco Systemsd. amco Systems mco Systems

50

Page 510: FRP C & DS dumps

ans::b18. #define square(x) x*xvoid main(){int i=7;clrscr();i=64/square(4);printf("%d",i);}

a. 7b. 16c. 64d. 4ans::c19. #define man(x,y) (x)>(y)?(printf("%d",x)):(y)

void main(){int i=15,j=10,k=0;k=man(i++,++j);printf(" %d %d %d",i,j,k);}

a. 16 17 11 2b. 17 17 11 2c. 16 16 11 2d. 16 17 12 2ans::a20. struct one{int no:1;int pl:2;int x:3;};

void main(){struct one a;a.no=0;

51

Page 511: FRP C & DS dumps

a.pl=1;a.x=3;printf("%d %u",a.no,a.no);printf("\n%d %u",a.pl,a.pl);printf("\n%d %u",a.x,a.x);}

a. 0 0 1 1 3 3b. 0 0 2 2 3 3c. 1 1 2 2 3 3d. 1 1 2 2 2 2Ans:a21. void main(){ struct emp { struct e { int *a; }e1; int a; };

struct emp emp1;printf("%d %d",sizeof(emp1),sizeof(emp1.e1));}

a. 2 4b. 2 2c. 4 4d. 4 2ans::d

51

Page 512: FRP C & DS dumps

22. struct emp emp1;struct emp { int a; };main(){printf("Enter 1 values:");scanf("%d%d",&emp1.a,&emp1.a);//The given input is 10 and 25printf("a=%d a=%d",emp1.a,emp1.a);}

a. 10 25b. 25 25c. 10 10d. Compiler Errorans::b23. Arrange the code in order to delete a node being pointer by temp.

a) free(temp)b) temp->prev->next = temp->nextc) temp->next->prev = temp->prev;

a) b c a b) c b ac) a b cd) both a and b

ans::d24. What does below code do, if temp is pointing to a node other than first and last node

temp -> prev ->next = temp ->next;temp ->next -> prev = temp -> prev;

a) no effect b) inserts a nodec) deletes a noded) shuffling of pointers

51

Page 513: FRP C & DS dumps

ans::c25. 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

1. void main()

{

int a=1,b=2,c=3;

c=(--a, b++)-c;

printf("%d %d %d",a,b,c);

}

(a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3

0

Ans::3

2.

#define swap(a,b) temp=a; a=b; b=temp;

void main()

{

static int a=5,b=6,temp;

if (a > b)

swap(a,b);

printf("a=%d b=%d",a,b);

}

(a)a=5 b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of

these

Ans::c

51

Page 514: FRP C & DS dumps

3.

void main()

{

int i=5;

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

}

(a)Compile-Time Error (b)10 9 8 7 6 (c)9 8 7 6 6

(d)10 8 7 6 6

Ans:d

4.

void main()

{

int i, n =10;

for (i=1; i<n--; i+=2)

printf("%d", n-i);

}

(a)84 (b)840 (c)852

(d)864

Ans:c

5.

What is the output of the program?

    #include <stdio.h>

    int main(int argc, char *argv[])    {        printf(" %d", printf("Hello Genesis"));        return 0;    }

51

Page 515: FRP C & DS dumps

A. Hello GenesisB. 13 Hello GenesisC. Hello Genesis 13D. None of the above

6.

  #include <stdio.h>         main()     {         switch (5)        {             case 5: printf(" 5 ");             default: printf(" 10 ");             case 6: printf(" 6 ");         }     }

B. 5C. 5 10 6D. 5 10E. 5 6

Ans::b

7.

Which argument of function 'strncmp()' specifies number of characters to be compared?

A. first B. second C. between 2 strings D. third

ans::d

8.

51

Page 516: FRP C & DS dumps

Which of the following is not a storage class in C?

B. StackC. RegisterD. ExternE. Static

Ans::a

9.

What is the significance of the free() function?

A. It assigns the pointer a NULL valueB. It erases the contents of any type and cleans the pointer C. It places the memory address with the pointer in free store D. It disables the memory address with the pointer

Ans::a

10.

What is the data type of FILE?

A. integer B. union C. pointer D. structure

ans::d

11.

#include <stdio.h>    #define sq(a) a * a      

    void main()         {         printf("%d", sq(3 + 2));     }        

51

Page 517: FRP C & DS dumps

A. 25B. 11C. 10D. Compilation error 

Ans::b

12.

Which of the following is a non-linear data structure?

A. StackB. QueueC. Linked ListD. Tree

Ans::d

13.

Which of the following function does not return an integer value?

B. printfC. scanfD. strcpyE. strlen

ans:c

14.

Which of the following function does not support dynamic memory allocation?

A. allocB. reallocC. malloc D. free

ans::a

51

Page 518: FRP C & DS dumps

15.

What is the output of the program if the input is 103?

    main()    {        int p = 234;        printf(" %d ", printf("%d", p), scanf("%d", &p));    }

A. 3 103B. 103C. 103 3D. 103 2

Ans::c

16.

Where do we use a 'continue' statement?

B. In 'if' statementC. In 'switch' statement D. In 'goto' labels E. None of the above

Ans::d

17.

1. Queue is _________________

a) LIFOb) LILOc) FIFOd) Both b & c

Ans::d18.

What is the postfix expression for A + B * C / D – E * F / Ge) ABC*D/+EFG*/-

51

Page 519: FRP C & DS dumps

f) ABC*D/+EF*G/-g) ABCD/*+EF*G/-h) None of these.

Ans::b19.

Write one statement equivalent to the following two statements:   x=sqr(a);  return(x); Choose from one of the alternatives

(a) return(sqr(a));                                    (b) printf("sqr(a)");(c) return(a*a);                                    (d) printf("%d",sqr(a));

Ans::b 20.int i=5;

int abc(int z) { return i/2; } main() { int i=4; printf("%d",abc(i=i/4)); }

a) errorb) 5c) 2d) 0ans::c21.

union U { int x; float y; char s[2]; }; union U ob;

51

Page 520: FRP C & DS dumps

what is the size of ob in bytes,

a) 4b) 2c) 8d) 7ans::a

22.

The operation for adding and deleting an entry to a stack is traditionally called:

a.add , delete b.append , deletec.insert , deleted.push , pope. front , rearans::d

23.

What is the Infix expression for - + A / * B C D / * E F G

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 - B * C / D + E * F / G

Ans:c

24.

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, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69a)69b)25

52

Page 521: FRP C & DS dumps

c)26d)9

Ans::b

25.

what does the code below do, where head is pointing to first node & temp is a temporary pointer. 10 be the number of nodes

temp = head;while (temp->next->next!=NULL){

temp = temp ->next;}temp -> prev -> next = temp -> next;temp -> next -> prev = temp -> prev;free(temp);

a) no effect b) deletes some nodec) deletes 2nd last noded) deletes last node

ans::c

1.What will be the output of the following program :

int main() {

int val=5; printf("%d %d %d %d",val,--val,++val,val--); return(0);

}(a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of theseAns::c2.#define Compute(x,y,z) (x+y-z)

int main() { int x=2,y=3,z=4;

52

Page 522: FRP C & DS dumps

printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); return(0); }

(a)40 (b)30 (c)Compile-Time Error (d)None of theseAns::b3.What will be the output of the following program : int main()

{ int val=5; val=printf("C") + printf("Skills");

printf("%d",val); return(0); }

(a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 Ans::d4.What will be the output of the following program :

int main() {

char str[]="Test"; if ((printf("%s",str)) == 4)

printf("Success"); else printf("Failure");

return(0); }

a)Success b)TestSuccess c)Compile-Time Error(d)Failure ans::b5.What will be the output of the following program:

int main(){

int val=5; printf("%d",5+val++); return(0);

}(a)Compile-Time Error (b)Lvalue required Error (c)10 (d)11

Ans::c

52

Page 523: FRP C & DS dumps

6.void main() {

printf("%d",sizeof(int)); return(0);

} (a)Data types not allowed (b)Compile-Time Error(c)3 (d)2 Ans::27.In tree construction which is the suitable efficient data structure?

(a) Array (b) Linked list (c) malloc (d) Queue Ans:b8.

Traverse the given tree using Inorder, Preorder and Postorder traversals.

a)Inorder : D H B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G C A

b)Inorder : D H B E A F C I G JPreorder: D H E A B C F G I JPostorder: H D E B F I J G C A

c)Inorder : D H B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G A C

d)Inorder : H D B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G C A

52

A

B C

D E F G

H I J

Given tree:

Page 524: FRP C & DS dumps

Ans:a9.

main(){static int var = 5;printf("%d ",var--);if(var)

main();}

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

Ans:c10.

#include<stdio.h>main(){

struct xx{ int x=3; char name[]="hello"; };struct xx *s;

printf("%d",s->x);printf("%s",s->name);

}

b. 3 hello b. Compiler Error c. Run time error d. use dot (.) operator

Ans::s11.

#include<stdio.h>main() { const int i=4; float j; j = ++i;

52

Page 525: FRP C & DS dumps

printf("%d %f", i,++j); }

a. 5 6.000000 b. 5 5.000000 c. 6 6.000000 d. compiler error

Ans::d12.void main()

{int k=ret(sizeof(float));printf("\n %d",++k);

}int ret(int ret){

ret += 2.5;return(ret);

}a. Compiler Error b. 8 c. 6 d. 7

Ans::d13.

int swap(int *a,int *b){ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

}b. 20 10 b. 10 20 c. 20 20 d. 10 10

Ans:a14.

main(){

char *p = “ayqm”;char c;c = ++*p++;

52

Page 526: FRP C & DS dumps

printf(“%c”,c);}

a. a b. b c. y d. z

ans:b15.main()

{float i=1.5;switch(i){

case 1: printf("1");case 2: printf("2");default : printf("0");

}}

b. 0 b. 0 1 2 c. 1 2 0 d. Compiler Error e. 2 0

Ans:d16.

#define MESS junkmain(){printf(“MESS”); }

a. Junk b. Error c. MESS d. MESS junk

Ans:c17.main (){

int i = 5;switch (i) {static int i;i = 3;i = i * i;case 3:

i = i + i;case 4:

i = i + i;

52

Page 527: FRP C & DS dumps

case 5:i = i + i;printf (“%d”,i);

}printf (“%d”,i);

}a. 9 b. 10 10 c. 0 5 d. 18 18 e. 18 5

Ans:c18.What would be the output of the following program.Int fn(int); main() { int i=10; fn(i); printf("%d",i); } fn(int i) { return ++i; } (a) 10 (b) 11 (c) 12 (d) Compilation errorAns:a19.

main()

{

FILE *fp1,*fp2;             fp1=fopen("one","w");       fp2=fopen("one","w") ;      fputc('A',fp1) ;      fputc('B',fp2) ;      fclose(fp1) ;      fclose(fp2) ;     }

52

Page 528: FRP C & DS dumps

     Find the Error, If Any?

a. no error. But It will over writes on same file.b. no error. But It will create one more file.c. error. It will not allow.d. no error. The new content will append in existing file.

Ans:a

20.

void main()

{

int a=555,*ptr=&a,b=*ptr;

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

}

(a)Compile-Time Error (b)555 554 555 (c)556 554 555(d)557 554 555

Ans:c

21.

what type of Binary Tree is the following tree below

52

Page 529: FRP C & DS dumps

a. binary treeb. strictly binary treec. complete binary treed. not a binary tree

ans:d

22.

If suppose root to be deleted then which node will be the root node

A

B C

ED F

GH I

J K

52

Page 530: FRP C & DS dumps

a. Bb. Gc. Any noded. Both a and b are correct

Ans:a

23.

When fopen() fails to open a file it returnsa) NULL b) –1 c) 1 d) None of the above

ans:a

24.Which function is used to detect the end of file

a) EOF b) feof( ) c) ferror( ) d) NULL

ans:b

25.

If the CPU fails to keep the variables in CPU registers, in that case the variables are assumed

B

C E

A

D

G

I

J

H

K

53

Page 531: FRP C & DS dumps

a) static b) external c) global d) auto

ans::d

1. #include<stdio.h>

int x=40;main(){

int x = 20;printf("\n %d",x);

}

Predict the output204020, 40None of the above

2.#include<stdio.h>main(){

int x=40;{

int x = 20;printf("\n %d",x);

}printf("%d",x);

}Predict the output20 4040 204020

3.

53

Page 532: FRP C & DS dumps

#include<stdio.h>main(){

extern int a;printf("\n %d",a);

}int a=20;

Predict the output200Garbage valueError

4.#include<stdio.h>--------------------------------doubtmain(){

struct emp{

char name[20];int age;float sal;

};

struct emp e={"Raja"};printf("\n %d %f", e.age, e.sal);

}

0 0.000000Garbage valuesErrorNone of the above

5. #include<stdio.h>main(){

53

Page 533: FRP C & DS dumps

int x=10, y=20, z=5, i;

i= x < y < z;

printf("%d", i);}

o\p:1

6. Which of the following definition is correct?

int lengthchar intint longfloat doubleans::17. What will be the output#include<stdio.h>

main(){

int i=4;switch (i){

default:printf("Default Value \n");

case 1:printf("Value is 1 \n");break;

case 2:printf("Value is 2 \n");break;

case 3:printf("Value is 3 \n");break;

53

Page 534: FRP C & DS dumps

}}o\p:default value

8. #include<stdio.h>------------doubt

main(){

int i=1;

while(){

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

if (i >10){

break;}

}}Ans::Error9.#include<stdio.h>------------------------------doubtmain(){

int x=30, y =40;

if (x==y)printf("X is equal to Y");

else if (x>y)printf("x is greater than Y");

else if (x<y)printf("X is less than Y");

}

Ans: X is less than Y

53

Page 535: FRP C & DS dumps

10.#include<stdio.h>main(){

int i=10, j=15;

if(i%2= = j%3){

printf("Same");}else{

printf("Different err");}

} o\p same

11.#include<stdio.h>------------doubt

main(){

int x=4, y, z;y=--x;z= x--;printf("%d %d %d", x,y,z);

}

Output:4 3 34 3 23 3 22 3 32 2 3 Ans::233 12.#include<stdio.h>

53

Page 536: FRP C & DS dumps

main(){

float a = 0.7;if (a<0.7){

printf("C");}else{

printf("C++");}

} Try with 0.7f o\p c++

13.#include<stdio.h>

main(){

float fval=7.29;printf("%d" ,fval);

}

o\p 7

14.#include<stdio.h>-----------------------doubt

main(){

printf("Welcome");main();

}

How many times the program will execute? Ans:Infinte

53

Page 537: FRP C & DS dumps

15.#include<stdio.h>----------------------doubt

void fun(char *);

void main(){

char a[100];a[0] = 'A', a[1] = 'B';a[2] = 'C', a[3] = 'D';fun(&a[0]);

}

void fun(char *a){

a++;printf("%c", *a);a++;printf("%c", *a);

}

o\p b c

16.#include<stdio.h>

#define MESS "Junk"

main(){

printf("MESS");}o\p mess

53

Page 538: FRP C & DS dumps

18.#include<stdio.h>main(){

char str[] = "Sales\0man\0";printf("%d", strlen(str));

}o\p 5

19.#include<stdio.h>main(){

char str[] = "Sales\0man\0";printf("%d", sizeof(str));

}

o\p 11

20#include<stdio.h>-------------doubt#include<string.h>

main(){

char sentence[80];int i;printf("Enter the line of text");gets(sentence);for(i=strlen(sentence)-1;i>=0;i--){

putchar(sentence[i]);}

}

21#include<stdio.h>-----------------------doubt

53

Page 539: FRP C & DS dumps

main(){

float a=3.15529;printf("%6.2f \n",a);printf("%6.3f \n",a);printf("%5.4f \n",a);printf("%2.1f \n",a);printf("%0.0f \n",a);

}

1. Which of the following does not have an unary operator?

1) -7 2) ++i3) j 4) all of the above

2. In printf(),the appearance of the output of the output can be affected by

1) field with 2) conversion character3) flag 4) all of the above

3. Any of the following programs in c has access to three standard files:

1) standard input file, standard output file, standard error file2) stdin,stdout, stderr3) keyboard,screen,screen4) all the above

4. The comma operator(,) is used to

1) permit two different expressions to appear in situations where only one expression would ordinarily be used2) Terminate loops or to exit from switch3) alter the normal sequence of program execution by transferring control to some other part of the program4) 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.1) extern 2) static3) stat 4) auto

53

Page 540: FRP C & DS dumps

6) A program can be terminated at any time by calling the function

1) fflush() 2) ferror()3) exit() 4) clearerr()

7) Heap

1) is a region from where memory is allocated2) lies between you program and the stack3) is a finite area4) all of the above

8) A function can

1) perform a task 2) return a value3) change value of actual arguments in call by reference4) all of the above

9) Function definition void check(int i ,char*j) is1) call by value 2)call by reference3) 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 memory2) must be structure 3) are grouped next to each other in memory4) all have the same type

11) Which of the following array is defined in the statements Char name[30]?

5) name is one dimensiona,30-element integer array6) name is one dimensional,30-element floating point array7) name is one dimensional ,30-element character array8) name is one dimensional,30-elements string array

54

Page 541: FRP C & DS dumps

12) c program contains the following declaration:Static float table[2][3]={ {1.1,1.2,1.3},

{2.1,2.2,2.3}};

What is the value of *(*(table+1)+1)?

2) 2.2 2) 1.24) 2.1 4) 2.3

13) A c program contains the following declarations and initial Assignments:

int i=8,j=5; float x=0.0005,y=-0.01;Char c=’c’,d=’d’;What would be the value of the following expression?

(3*i-2*j)%(2*d-3) 1)14 2)18 3) 1 4) 0

14) The declaration : int f(int 1); means

1) f accepts an integer argument and returns an integer quantity2) f accepts two arguments and returns a double precision quantity, and the second is an integer3) f accepts three arguments and returns nothing. The first argumentsis a double-precision quantity, and the second is an integer4) f does not accepts any arguments but returns a single character

15) The c language was developed by

1) Marting Richards 2) Dennis Ritchie3) Ken Thompson 4) Smith Volt

16) The arguments of a function are included between

54

Page 542: FRP C & DS dumps

1) The parenthesis 2) double quotes3) curly braces 4) #

17) The int type of constraints are whole numbers in the range

1) -23677 to 23678 2) -32768 to 327673) -32767 to 32768 4) -32864 to 32864

18) If the variables i,j and k are assigned the values 5,3 and 2 respectively, then the expression i=j+(k++ =6)+7;

1) gives an error message 2) assigns a value 16 to i3) assigns a value 18 to i 4) assigns a value 19 to i

19) In a relational expression involving characters, we actually Compare

5) the ASCII codes of the characters6) the characters themselves7) neither of the two8) binary code and hexadecimal code

20) The getchar function is used to

1) print the ASCII code of the character2) to assign a character typed at the keyboard to a variable3) to print a character on the screen4) all of the above

21) The word case used in the switch statement represents a

5) function in the c language6) data type in the c language7) keyword in the c language8) global variable in the c language

22)The logical NOT operator represented by ! is a

1) unary operator 2) binary operator3) ternary operator 4) octal operator

54

Page 543: FRP C & DS dumps

23) The statement : scanf(“%d”,&i);

5) assigns an integer to the variable i6) gives an error message;7) does not assign any value to i8) assigns an float to the variable i

24) A pointer is declared by using a statement such as

1) int *p; 2) point; 3) pointer *p; 4) int &p;

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 locations2) share the memory with a structure3) have the same memory location4) have different memory variable

27) The global variables by default belong to

1) the register type 2) the static type3) the auto 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

54

Page 544: FRP C & DS dumps

30) A fields width specifier in a printf() function

1) specifies the maximum value of a number2) controls the size of type used to print numbers3) controls the merging of the program listing4) specifies how many characters positions will be used for a number

31) The two operators && and || are

1) arithmetic operators 2) equality operators3) logical operators 4) relational operators

32) The library files that come with c are

1) text editor for program development 2) the compiler and liker3) program examples4) files that contain functions which carry out various commonlyUsed operations and calculations

33) precedence determines which operator

1) is evaluated first2) is most important3) is fastest 4) operates on the largest number

34) The string containing certain required formatting informationis called

1) argument 2) character array3) character string 4) control string

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

54

Page 545: FRP C & DS dumps

3) several different conditions can cause one set of statements to executed in a switch4) 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 calls2) providing diagnostic and debugging assistance3) providing support for the string handling functions 4) none of the above

37) The malloc() function

1) returns a pointer to the allocated memory2) returns a pointer to the first byte of region of memory3) changes the size of the allocated memory4) deallocates the memory

38) which of the following expressions will return a 1 if both bits haveA value of 1; otherwise will return a value of 0?

1) AND 2)OR 3)XOR 4)1’stderr complement

39) If an error occurs while opening a file the file pointeris 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

54

Page 546: FRP C & DS dumps

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 2) assigns a value 4 to p3) assigns a value 3 to p 4) assigns a value 5 to p44) A compound statement is a group of statement included between a pair of

1) double quots 2) curly braces3) parentesis 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 2) double quotes3) parenthesis 4) / and /

49) One structure cannot be

5) a member of some other structure6) a member of the same structure7) a member of a union8) all of the above

54

Page 547: FRP C & DS dumps

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,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 variable4) 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( ) 3) putchar( ) 4) scanf( )

53) An expression

5) is a collection of data objects and operators that can be evaluated to a single value

6) is a name that substitutes for a sequence of characters7) causes the computer to carry out some action8) all of the above

54) The expression c=i++ causes

5) the value of I assigned to c and then I incremented by 16) I to be incremented by 1 and then the value of I assigned to @7) Value of I assigned to c

54

Page 548: FRP C & DS dumps

8) I to be incremented by 1

55)The single character input/output functions are

1) scanf( ) and printf( ) 2) getchar( ) and printf( )3) scanf( ) and putchar( ) 4) getchar( ) and putchar( )

56) The conversion character ‘I’ for data output means that theData item is displayed as

5) a floating point value with an exponent6) an unsigned decimal integer7) a signed decimal integer8) an octal integer

57) The header file “ctype.h” can be used for

1) providing links to assembly language for calls2) providing diagnostic and debugging assistance3) providing support for string handling functions4) providing character type identification (Boolean) and translation

58) In a circular linked list

5) components are all linked together in some sequential manner6) there is no beginning and no end7) components are arranged hierarchically8) forward and backward transversal within the list is permitted

59) The function ftell( )

1) reads a character from a file2) reads an integer form a file3) gives the current position in the file4) sets the position to the beginning of the file

60) A c function contain

54

Page 549: FRP C & DS dumps

1)function body 2)argument declaration3)a function header 4)all of the above

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

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

54

Page 550: FRP C & DS dumps

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() { char *str; char *fun(); str=fun(); printf("%s",str); } char * fun()

55

Page 551: FRP C & DS dumps

{ 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 aboveans::a

7) what is the prefix expression for the given Infix expression A+B*C/DAns::+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

10) In a function call, _____________ is passed as arguments.

55

Page 552: FRP C & DS dumps

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) /nb) /tc) /0d) none

14) The range of Unsigned integer is

a) 127 to -128b) 0 to 65535c) Depend up on the compilerd) -32768 to 32767

15) which one of the following is a illegal real constants

a) 32.535b) -1.5E25 to 3.5E65c) "53682"d) -6.583

16) main() { int i,a[5]; a[1]=5;

55

Page 553: FRP C & DS dumps

for(i=0;i<5;i++){

printf("%d",a[i]);a++;}

a) 0 0 0 0 0b) Garbage valuec) 0 5 0 0 0d) 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) 1b) 2c) 4d) 8

18) In a queue,what condition applies

a) First In First Outb) Last in first outc) Elements are inserted and deleted at one endd) 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) onlyb)ii) onlyc) Both i and iid) neither i nor ii

ans::c

20) main() { char str[]="Wipro Infotech";

char *s;

55

Page 554: FRP C & DS dumps

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; 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

55

Page 555: FRP C & DS dumps

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 & iid) neither i nor ii

27) what should be replace ????? in the program to get the output 25?

?????void main(){

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());

55

Page 556: FRP C & DS dumps

} 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,531) 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);

32) which is not a valid expressiona) 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 Emptyb) Queue Fullc) Queue has one element

d) Queue has max-1 elements

55

Page 557: FRP C & DS dumps

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 onlyb) ii onlyc) both i and iid) 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 onlyb) ii onlyc) both i and iid) neither i nor ii

37) Struct queue{

int rear; int front;

int a[100];}

struct queue *q; then how will you add a new element called 'item' in the queue?

55

Page 558: FRP C & DS dumps

a) q->rear[a]=item; b) q->a[q->rear]=item;c) q->a[rear]=item;d) q->rear[q->a]=item;

38) In which of the following we can sort the data without moving the data

a) Arrayb) Single Linked listc) Doubly linked listd) Binary search trees

39) Char d=128; printf("%c",d);

a)128b)-128c) errord) Garbage values

40) In the following definition

struct node *ptr;ptr=(struct node *)calloc(sizeof(ptr));

a) ptr is allocated 4 bytesb) ptr will be allocated sizeof struct nodec) Errord) ptr will have 8 bytes

41) In a doubly linked list ,if the first node is first and the last node is end,what will be the output?

traverse(struct node*end){ while(end!=NULL)

55

Page 559: FRP C & DS dumps

traverse(end->prev); printf("%d",end->data);}

if the input is 1,2,3,4,5 then the output will be

a) 1,2,3,4,5b) 5,4,3,2,1c) compilation errord) none

42) void main(){

int b=20;printf("%d"*&b++);}

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==NULLb)cursor->link=NULLc) Cursor->link=0d) 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->leftc) Cursor++d) cursor->left++

55

Page 560: FRP C & DS dumps

1. #include<stdio.h>

int x=40;main(){

int x = 20;printf("\n %d",x);

}

Predict the output204020, 40None of the above

2.#include<stdio.h>main(){

int x=40;{

int x = 20;printf("\n %d",x);

}printf("%d",x);

}Predict the output20 4040 2040

56

Page 561: FRP C & DS dumps

20

3. #include<stdio.h>main(){

extern int a;printf("\n %d",a);

}int a=20;

Predict the output200Garbage valueError

4.#include<stdio.h>--------------------------------doubtmain(){

struct emp{

char name[20];int age;float sal;

};

struct emp e={"Raja"};printf("\n %d %f", e.age, e.sal);

}

0 0.000000Garbage valuesErrorNone of the above

5.

56

Page 562: FRP C & DS dumps

#include<stdio.h>main(){

int x=10, y=20, z=5, i;

i= x < y < z;

printf("%d", i);}o\p 1

6. Which of the following definition is correct?int lengthchar intint longfloat double

7. What will be the output#include<stdio.h>

main(){

int i=4;

switch (i){

default:printf("Default Value \n");

case 1:printf("Value is 1 \n");break;

case 2:printf("Value is 2 \n");break;

case 3:printf("Value is 3 \n");

56

Page 563: FRP C & DS dumps

break;

}}o\p default value

8. #include<stdio.h>------------doubt

main(){

int i=1;

while(){

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

if (i >10){

break;}

}}

9.#include<stdio.h>------------------------------doubtmain(){

int x=30, y =40;

if (x==y)printf("X is equal to Y");

elseif (x>y)printf("x is greater than Y");

elseif (x<y)printf("X is less than Y");

}

Statement missingExpression Syntax

56

Page 564: FRP C & DS dumps

Lvalue requiredRValue required

10.#include<stdio.h>main(){

int i=10, j=15;

if(i%2 = j%3){

printf("Same");}else{

printf("Different err");}

} o\p same

11.#include<stdio.h>------------doubt

main(){

int x=4, y, z;

y=--x;

z= x--;

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

Output:4 3 34 3 23 3 22 3 32 2 3

56

Page 565: FRP C & DS dumps

12.#include<stdio.h>

main(){

float a = 0.7;if (a<0.7){

printf("C");}else{

printf("C++");}

} Try with 0.7f o\p c++

13.#include<stdio.h>

main(){

float fval=7.29;

printf("%d" ,fval);}o\p 7

14.#include<stdio.h>-----------------------doubt

main(){

printf("Welcome");main();

}

How many times the program will execute?

56

Page 566: FRP C & DS dumps

3276765535Till the stack doesn’t overflow

15.#include<stdio.h>----------------------doubt

void fun(char *);

void main(){

char a[100];a[0] = 'A', a[1] = 'B';a[2] = 'C', a[3] = 'D';

fun(&a[0]);}

void fun(char *a){

a++;printf("%c", *a);

a++;printf("%c", *a);

} o\p b c

16.#include<stdio.h>

#define MESS "Junk"

main(){

printf("MESS");}o\p mess

56

Page 567: FRP C & DS dumps

18.#include<stdio.h>main(){

char str[] = "Sales\0man\0";printf("%d", strlen(str));

}o\p 5

19.#include<stdio.h>main(){

char str[] = "Sales\0man\0";printf("%d", sizeof(str));

}o\p 11

20#include<stdio.h>-------------doubt#include<string.h>

main(){

char sentence[80];int i;

printf("Enter the line of text");gets(sentence);

for(i=strlen(sentence)-1;i>=0;i--){

putchar(sentence[i]);}

}

21#include<stdio.h>-----------------------doubt

main(){

56

Page 568: FRP C & DS dumps

float a=3.15529;printf("%6.2f \n",a);printf("%6.3f \n",a);printf("%5.4f \n",a);printf("%2.1f \n",a);printf("%0.0f \n",a);

}1. printf("%d %d %d",sizeof(25.75),sizeof(123),sizeof(‘p’))a. 2 2 2 b. 4 2 2 c. 8 4 1 d. 8 2 2

2. int i=5;fun( ){

printf("%d\n", i * 3);}main( ){

int i= 2;{int i = 3;printf(" %d", i);fun();}

}f. 3, 15 g. 3, 6h. 3 i. 0

3. #define xsq(x) x*xmain( ){

int i, j;i = 5;j = xsq(i-2);printf(“%d\n”, j);

}e. –7 f. 9g. 13

56

Page 569: FRP C & DS dumps

h. 29

4. main( ) {

int a=35;printf(“ %d %d %d\n”, a == 35,a=50,a>40);

}a. 1 50 1 b. 1 50 0c. 0 50 0d. 0 50 1

5. void main(){char a[]="123abcd";clrscr();printf("%d",strlen(a));getch();}

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

6. main(){static int var=5;if(var--){printf("%d",var);main();}}

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

56

Page 570: FRP C & DS dumps

7. void main(){int i=1,j=2;switch(i){case 1: printf("One"); break;case j: printf("Two"); break;default: printf(“Default”); break;}}a. Oneb. Twoc. Defaultd. Compiler Error

8. void main(){switch('a'){case 'A': printf("Zero"); break;case 97: printf("One"); break;default: printf("Error"); break;}}

a. Zerob. Onec. Errord. Compiler Error

9. void main(){int p=1,sum=0;clrscr();while(p<20){p++;sum+=p++;}printf("\nsum=%d",sum);

57

Page 571: FRP C & DS dumps

}

a. 120b. 100c. 110d. Error

10. int x;int modifyvalue(){return(x+=10);}

int changevalue(int x){return(x+=1);}

void main(){int x=10;x++;changevalue(x);x++;modifyvalue();printf("First output : %d",x);changevalue(x);printf("\nSecond output : %d",x);}

a. 12 12b. 11 12c. 12 13d. 13 13

11. main(){static i=3;printf("%d",i--);return i>0?main():0;

57

Page 572: FRP C & DS dumps

}

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

12. void main(){char *ptr="Hello World";*ptr++;printf("%s",ptr);ptr++;printf("%s",ptr);}

a. Iello World Iello Worldb. Hello World ello Worldc. ello World ello Worldd. ello World llo World

13. int const *p;*p=5;printf("%d",*p++);

a. 5b. 6c. Compiler Errord. Garbage Value

14. void main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("ab"));}

a. 5 5 3b. 4 5 3c. 2 5 3

57

Page 573: FRP C & DS dumps

d. 1 5 3

15. P is a character pointer variable then, what will be the output of the following statement.printf("%d %d",sizeof(p),sizeof(*p));

a. 1 2b. 2 1c. 2 2d. 1 1

16. void main(){char *s[]={"dharma","hewlet-packard","siemens","ibm"};char **p;p=s;printf("%s",++*p);printf("\n%s",*p++);printf("\n%s",++*p);}

a. harma harma ewlet-packardb. dharma harma ewlet-packardc. harma hewlet-packard siemensd. harma harma hewlet-packard

17. void main(){char *ptr="Ramco Systems"; (*ptr)++;printf("%s\n",ptr);ptr++;

57

Page 574: FRP C & DS dumps

printf("%s",ptr);}

a. Samco Systems Samco Systemsb. Samco Systems amco Systemsc. amco Systems amco Systemsd. amco Systems mco Systems

18. #define square(x) x*xvoid main(){int i=7;clrscr();i=64/square(4);printf("%d",i);}

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

19. #define man(x,y) (x)>(y)?(printf("%d",x)):(y)

void main(){int i=15,j=10,k=0;k=man(i++,++j);printf(" %d %d %d",i,j,k);}

a. 16 17 11 2b. 17 17 11 2c. 16 16 11 2d. 16 17 12 2

20. struct one{int no:1;int pl:2;

57

Page 575: FRP C & DS dumps

int x:3;};

void main(){struct one a;a.no=0;a.pl=1;a.x=3;printf("%d %u",a.no,a.no);printf("\n%d %u",a.pl,a.pl);printf("\n%d %u",a.x,a.x);}

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

21. void main(){ struct emp { struct e { int *a; }e1; int a; };

struct emp emp1;printf("%d %d",sizeof(emp1),sizeof(emp1.e1));

57

Page 576: FRP C & DS dumps

}

a. 2 4b. 2 2c. 4 4d. 4 2

22. struct emp emp1;struct emp { int a; };main(){printf("Enter 1 values:");scanf("%d%d",&emp1.a,&emp1.a);//The given input is 10 and 25printf("a=%d a=%d",emp1.a,emp1.a);}

a. 10 25b. 25 25c. 10 10d. Compiler Error

23. Arrange the code in order to delete a node being pointer by temp.

a) free(temp)b) temp->prev->next = temp->nextc) temp->next->prev = temp->prev;

a) b c a b) c b ac) a b cd) both a and b

24. What does below code do, if temp is pointing to a node other than first and last node

57

Page 577: FRP C & DS dumps

temp -> prev ->next = temp ->next;temp ->next -> prev = temp -> prev;

a) no effect b) inserts a nodec) deletes a noded) shuffling of pointers

25. which is the faster traversable dynamically growing list

a) Binary Search Tree b) Singly Linked List c) Doubly Linked List d) Using Array

57

Page 578: FRP C & DS dumps

1. void main()

{

int a=1,b=2,c=3;

c=(--a, b++)-c;

printf("%d %d %d",a,b,c);

}

(a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3

0

2.

#define swap(a,b) temp=a; a=b; b=temp;

void main()

{

static int a=5,b=6,temp;

if (a > b)

swap(a,b);

printf("a=%d b=%d",a,b);

}

(a)a=5 b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of

these

3.

void main()

{

int i=5;

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

57

Page 579: FRP C & DS dumps

}

(a)Compile-Time Error (b)10 9 8 7 6 (c)9 8 7 6 6

(d)10 8 7 6 6

4.

void main()

{

int i, n =10;

for (i=1; i<n--; i+=2)

printf("%d", n-i);

}

(a)84 (b)840 (c)852

(d)864

5.

What is the output of the program?

    #include <stdio.h>

    int main(int argc, char *argv[])    {        printf(" %d", printf("Hello Genesis"));        return 0;    }

E. Hello GenesisF. 13 Hello GenesisG. Hello Genesis 13H. None of the above

6.

57

Page 580: FRP C & DS dumps

  #include <stdio.h>         main()     {         switch (5)        {             case 5: printf(" 5 ");             default: printf(" 10 ");             case 6: printf(" 6 ");         }     }

F. 5G. 5 10 6H. 5 10I. 5 6

7.

Which argument of function 'strncmp()' specifies number of characters to be compared?

E. first F. second G. between 2 strings H. third

8.

Which of the following is not a storage class in C?

F. StackG. RegisterH. ExternI. Static

9.

What is the significance of the free() function?

58

Page 581: FRP C & DS dumps

E. It assigns the pointer a NULL valueF. It erases the contents of any type and cleans the pointer G. It places the memory address with the pointer in free store H. It disables the memory address with the pointer

10.

What is the data type of FILE?

E. integer F. union G. pointer H. structure

11.

#include <stdio.h>    #define sq(a) a * a      

    void main()         {         printf("%d", sq(3 + 2));     }        

E. 25F. 11G. 10H. Compilation error 

12.

Which of the following is a non-linear data structure?

E. StackF. QueueG. Linked ListH. Tree

13.

58

Page 582: FRP C & DS dumps

Which of the following function does not return an integer value?

F. printfG. scanfH. strcpyI. strlen

14.

Which of the following function does not support dynamic memory allocation?

E. allocF. reallocG. malloc H. free

15.

What is the output of the program if the input is 103?

    main()    {        int p = 234;        printf(" %d ", printf("%d", p), scanf("%d", &p));    }

E. 3 103F. 103G. 103 3H. 103 2

16.

Where do we use a 'continue' statement?

F. In 'if' statementG. In 'switch' statement H. In 'goto' labels I. None of the above

58

Page 583: FRP C & DS dumps

17.

2. Queue is _________________

a) LIFOb) LILOc) FIFOd) Both b & c

18.What is the postfix expression for A + B * C / D – E * F / Gi) ABC*D/+EFG*/-j) ABC*D/+EF*G/-k) ABCD/*+EF*G/-l) None of these.

19.Write one statement equivalent to the following two statements:   x=sqr(a);  return(x); Choose from one of the alternatives

(a) return(sqr(a));                                    (b) printf("sqr(a)");(c) return(a*a);                                    (d) printf("%d",sqr(a));

20.int i=5;

int abc(int z) { return i/2; } main() { int i=4; printf("%d",abc(i=i/4)); }

a) errorb) 5

58

Page 584: FRP C & DS dumps

c) 2d) 0

21.

union U { int x; float y; char s[2]; }; union U ob;

what is the size of ob in bytes,

a) 4b) 2c) 8d) 7

22.

The operation for adding and deleting an entry to a stack is traditionally called:

a.add , delete b.append , deletec.insert , deleted.push , pope. front , rear

23.

What is the Infix expression for - + A / * B C D / * E F G

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 - B * C / D + E * F / G

58

Page 585: FRP C & DS dumps

24.

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, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69e)69f) 25g)26h)9

25.

what does the code below do, where head is pointing to first node & temp is a temporary pointer. 10 be the number of nodes

temp = head;while (temp->next->next!=NULL){

temp = temp ->next;}temp -> prev -> next = temp -> next;temp -> next -> prev = temp -> prev;free(temp);

a) no effect b) deletes some nodec) deletes 2nd last noded) deletes last node

58

Page 586: FRP C & DS dumps

58

Page 587: FRP C & DS dumps

1.What will be the output of the following program :

int main() {

int val=5; printf("%d %d %d %d",val,--val,++val,val--); return(0);

}(a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of these

2.#define Compute(x,y,z) (x+y-z)

int main() { int x=2,y=3,z=4;

printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); return(0); }

(a)40 (b)30 (c)Compile-Time Error (d)None of these

3.What will be the output of the following program : int main()

{ int val=5; val=printf("C") + printf("Skills");

printf("%d",val); return(0); }

(a)7 (b)C7 (c)Compile-Time Error(d)CSkills7

4.What will be the output of the following program :

int main() {

char str[]="Test"; if ((printf("%s",str)) == 4)

printf("Success"); else

58

Page 588: FRP C & DS dumps

printf("Failure"); return(0); }

a)Success b)TestSuccess c)Compile-Time Error(d)Failure

5.What will be the output of the following program:

int main(){

int val=5; printf("%d",5+val++); return(0);

}(a)Compile-Time Error (b)Lvalue required Error (c)10 (d)11

6.void main() {

printf("%d",sizeof(int)); return(0);

} (a)Data types not allowed (b)Compile-Time Error(c)3 (d)2 7.In tree construction which is the suitable efficient data structure?

(a) Array (b) Linked list (c) malloc (d) Queue 8.

Traverse the given tree using Inorder, Preorder and Postorder traversals.

a)Inorder : D H B E A F C I G JPreorder: A B D H E C F G I J

58

A

B C

D E F G

H I J

Given tree:

Page 589: FRP C & DS dumps

Postorder: H D E B F I J G C A

b)Inorder : D H B E A F C I G JPreorder: D H E A B C F G I JPostorder: H D E B F I J G C A

c)Inorder : D H B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G A C

d)Inorder : H D B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G C A

9.main()

{static int var = 5;printf("%d ",var--);if(var)

main();}

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

10.#include<stdio.h>main(){

struct xx{ int x=3; char name[]="hello"; };struct xx *s;

printf("%d",s->x);printf("%s",s->name);

}

58

Page 590: FRP C & DS dumps

c. 3 hello b. Compiler Error c. Run time error d. use dot (.) operator

11.#include<stdio.h>

main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

b. 5 6.000000 b. 5 5.000000 c. 6 6.000000 d. compiler error

12.void main()

{int k=ret(sizeof(float));printf("\n %d",++k);

}int ret(int ret){

ret += 2.5;return(ret);

}b. Compiler Error b. 8 c. 6 d. 7

13.int swap(int *a,int *b)

{ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

59

Page 591: FRP C & DS dumps

}c. 20 10 b. 10 20 c. 20 20 d. 10 10

14.main()

{char *p = “ayqm”;char c;c = ++*p++;printf(“%c”,c);

}b. a b. b c. y d. z

15.main()

{float i=1.5;switch(i){

case 1: printf("1");case 2: printf("2");default : printf("0");

}}

c. 0 b. 0 1 2 c. 1 2 0 d. Compiler Error e. 2 0

16.#define MESS junkmain(){printf(“MESS”); }

b. Junk b. Error c. MESS d. MESS junk

17.main (){

59

Page 592: FRP C & DS dumps

int i = 5;switch (i) {static int i;i = 3;i = i * i;case 3:

i = i + i;case 4:

i = i + i;case 5:

i = i + i;printf (“%d”,i);

}printf (“%d”,i);

}b. 9 b. 10 10 c. 0 5 d. 18 18 e. 18 5

18.What would be the output of the following program.Int fn(int); main() { int i=10; fn(i); printf("%d",i); } fn(int i) { return ++i; } (a) 10 (b) 11 (c) 12 (d) Compilation error

19.

main()

{

59

Page 593: FRP C & DS dumps

FILE *fp1,*fp2;             fp1=fopen("one","w");       fp2=fopen("one","w") ;      fputc('A',fp1) ;      fputc('B',fp2) ;      fclose(fp1) ;      fclose(fp2) ;     }

     Find the Error, If Any?

e. no error. But It will over writes on same file.f. no error. But It will create one more file.g. error. It will not allow.h. no error. The new content will append in existing file.

20.

void main()

{

int a=555,*ptr=&a,b=*ptr;

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

}

(a)Compile-Time Error (b)555 554 555 (c)556 554 555(d)557 554 555

21.

what type of Binary Tree is the following tree below

59

Page 594: FRP C & DS dumps

e. binary treef. strictly binary treeg. complete binary treeh. not a binary tree

22.

If suppose root to be deleted then which node will be the root node

A

B C

ED F

GH I

J K

59

Page 595: FRP C & DS dumps

e. Bf. Gg. Any nodeh. Both a and b are correct

23.

When fopen() fails to open a file it returnsa) NULL b) –1 c) 1 d) None of the above

24.Which function is used to detect the end of file

a) EOF b) feof( ) c) ferror( ) d) NULL

25.

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

B

C E

A

D

G

I

J

H

K

59

Page 596: FRP C & DS dumps

1.main(){

int x,y,z;x=y=z=1;z=++x||++y&&++z;printf("%d %d %d",x,y,z);

}2.13. main(){

int i=5,j=10;i=i&=j&&10;

printf("%d %d",i,j);}ans::1 103.2. main(){

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

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

printf("%d %d %d %d %d",i,j,k,l,m);}ans::0 0 1 3 1

3.28. main(){

int i=4,j=7;j = j || i++ && printf("YOU CAN");

printf("%d %d", i, j);}ans::4 13.29main(){

int a=500,b=100,c=300,d=40,e=19;a+=b-=c*=d/=e%=5;printf("%d %d %d %d %d",a,b,c,d,e);

}

59

Page 597: FRP C & DS dumps

2.main( ){int k=35;printf(“ %d %d %d\n”, k == 35,k=50,k>40);}ans::0 5 03.main( ) { int x=4,y,z; y = --x; z = x--; printf(“%d %d %d\n”,x,y,z); } ans:2 3 31.6. main() {

int i=10;i=!i>14;printf ("i=%d",i);

}ans::01.20. main()

{int i=-1;+i;printf("i = %d, +i = %d \n",i,+i);}

ans -1,-11.34. #include<conio.h>main(){

int x,y=2,z,a;if(x=y%2) z=2;a=2;printf("%d %d ",z,x);

}1.42. main(){

int i=10,j=20;

59

Page 598: FRP C & DS dumps

j = i, j?(i,j)?i:j:j;

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

int main(){ int x=5,y=6,z=2; clrscr(); z/=y/z==3?y/z:x*y; printf("%d",z);return 0;

}

int main(){ int a=1,b=2,c=3,d=4; clrscr(); printf("%d\n",!a?b?!c:!d:a); printf("%d %d %d %d",a,b,c,d); return(0);}

5.main(){printf("\nab");printf("\bsi");printf("\rha");}

1. main(){char *p="hai friends",*p1;

59

Page 599: FRP C & DS dumps

p1=p;while(*p!='\0') ++*p++;printf("%s %s",p,p1);}

2.#include<stdio.h>#include<conio.h>

void main(){ char a[]="abcdef"; char *p=a; clrscr(); p++; p++; p[2]='z'; printf("%s",p); getch(); }ans::cdzf

2.6. main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));}

ans:: 2 5 5

2.1. main(){

char s[ ]="man";int i;for(i=0;s[ i ];i++)printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}ans:: m m m a a a n n n1.7. #define square(x) x*x

59

Page 600: FRP C & DS dumps

main(){int i;i = 64/square(4);printf("%d",i);

}ans::64

1.7.2 #define cube(x) x*x*xmain(){

int b=3,a;a=cube(b++);printf("%d %d",a,b);

}ans::27,6

1.8. #include <stdio.h>#define a 10main(){#define a 50printf("%d",a);}ans::50

3.3. #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);}

3.6. main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"};

60

Page 601: FRP C & DS dumps

int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++)

printf("%s",names[i]);}ans::Lvalue Required.....base address can't be changed names[3]=names[4];

1)Allocating a 2 blocks of memory for 'n' intgers is by usinga) mallocb) callocc) both malloc and callocd) none of the above

2) In queue using linked list, which is correct?a) both insertion and deltionis made at the front endb) insertion is made at the beginning and deletion is made at the lastc) insertion is made at the last and deletion is made at the beginningd) both insertion and deltionis made at the back end

3) for(i=0;i<2;i++){for(j=0;j<5;j++){if(i==j)break;printf("wipro");}

}how many times would wipro to be printed?1 time

4) all the local variables are stored in -----------------a) stackb) heapc) queue

60

Page 602: FRP C & DS dumps

d) noneans::a

5) Once you call a function,all the return addresses are stored in ----------------a) stackb) heapc) queued) none

6) Which of the following is true about binary treei) all nodes except leaf node has exactly two childii) root node is greater than the left sub tree and lesser than the right sub tree.a) i onlyb)ii onlyc) both i and iid) neither i nor ii

7) Which of the following is true about complete binary treei) all nodes except leaf node has exactly two childii) root node is greater than the left sub tree and lesser than the right sub tree.a) i onlyb)ii onlyc) both i and iid) neither i nor ii

8) 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 snippetfront=start;back=end;while(back!=NULL){printf("%d",back->data);back=back->left;}

60

Page 603: FRP C & DS dumps

Data Structure Questions & Answers

1)Consider the following structure struct node { int info; struct node *link; };

Suppose ptr is a pointer which is not pointing to the first or the last node. Then if we are going to delete a node after ptr, then the code will be

a) ptr=ptr->link;b) ptr->link=ptr;c) ptr->link=ptr->link->link;d) ptr=ptr->link->link;

2) Consider the following structure struct node { int info; struct node *link; };

Suppose start is a pointer pointing to the first node of the linked list.s1 and ptr are the two pointers (they are not pointing to the first or last node). Then if we are going to execute the following code,

i) start->link=s1;ii) s1->link=ptr;iii) ptr->link=start;

then the list is

60

Page 604: FRP C & DS dumps

a) It is having only 3 nodes with start, s1, ptr in the list, having start as the first nodeb) It is a circular linked listc) It is a doubly linked listd) None of the above

3) In a queue, if rear=front then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) None of the above

4) In a queue, if rear=0, front=0 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) None of the above

5) In a queue, if rear=0, front=1 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) Queue is circular

6) In a queue,if rear=-1,front=-1 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) None of the above 7) In a queue, if rear=max-1, front=0 then what will be the queuea) Queue is emptyb) Queue is fullc) Queue has only one elementd) None of the above

60

Page 605: FRP C & DS dumps

8) The postfix expression is ab+c*d/e-.The values of a, b, c, d, e are 2, 4, 5, 2, 1 respectively. Then the output is solution:a+b*c/d-e converted in 6 is ans confusion a) 14 b) 11 c) 20 d) 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 isa) Stack is emptyb) Stack is fullc) Stack has only one elementd) None of the above

11) Consider the structure struct node

{ int info;

struct node *left; struct node *right;

};

We have 10 elements in the list. If the following executes what will be the output?

for(ptr=start; ptr; ptr=ptr->right){ if(ptr->data%2==0)

60

Page 606: FRP C & DS dumps

printf("%d", ptr->data);}

a) Only even numbers are printedb) Only odd numbers are printedc) Compiler errord) Only garbage values

12) struct node { int data; struct node *left,*right;};

Suppose nd is a node which is not in the beginning and also not in the end. How will you delete a node after nd?

a) nd->right=nd->right->left;nd->right->left=nd->left->right;b) nd->right=nd->right->right;nd->right->left=nd;c) nd->right=nd->right->left;nd->right->left=nd->right;d) nd->right=nd->left->right;nd->left->right=nd;

13) struct node{ int data; struct node *left,*right;};

Suppose nd 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;nd->right->left=nd->left->right;b) nd->left=nd->right->right;nd->left->right=nd->right;c) nd->left=nd->left->left;nd->left->right=nd;d) nd->left=nd->left->right;nd->left->right=nd;

60

Page 607: FRP C & DS dumps

14) struct node{ int data; struct node *left,*right;};

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;ptr->right->left=ptr->left;free(ptr);b) ptr->left->right=ptr->right->right;ptr->left->right=ptr->right;free(ptr);c) ptr->left->right=ptr->left->left;ptr->left->right=ptr;free(ptr);d) ptr->left->right=ptr->left;ptr->left->right=ptr->left;free(ptr);

60

Page 608: FRP C & DS dumps

15) struct node{ int data; struct node *left,*right;};

Suppose ptr is a node which is not in the beginning and also not in the end. nd is the new node.

Here is the coding: i) ptr->right->left=nd; ii) nd->left=ptr; iii) ptr->right=nd; iv) nd->right=ptr->right;

Then what sequence does it follows for inserting nd after ptr?

a) i,ii,iii,ivb) ii,iv,i,iiic)iv,iii,ii,id) ii,iii,i,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,root);insert(25,root);insert(5,root);insert(8,root);insert(13,root);

60

Page 609: FRP C & DS dumps

insert(45,root);insert(70,root);insert(32,root);delete(13,root);insert(66,root);insert(13,root);insert(36,root);

What will be the preorder traversal is

a) 5,8,10,13,25,32,36,45,66,70b) 10,5,8,25,13,45,32,36,70,66c) 10,8,5,13,32,45,36,66,32,70d) 8,5,32,36,10,66,45,70,25,13

19) The preorder traversal is 5, 3, 66, 30, 77, 70 .What will be the root node

a) 5b) 66c) 70d) 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 ib) only iic) both i and iid) Neither i nor ii

1. What will be the output of the following program : void main() { printf("%f",123);

60

Page 610: FRP C & DS dumps

}(a)123 (b)Compile-Time Error (c)123.00

(d)123.0000002. What will be the output of the following program : void main() { int a = -1,b=2,c=3,d=4;

d=++a||++b&&++c;printf(“%d %d %d %d”,a,b,c,d);

}(a) 0 3 4 1 (b) 1 3 4 5 (c)1 3 4 0 (d) 1 2 3 43. What will be the output of the following program : void main() {

char line[80]; // Max. length=80 Chars scanf("%[^,]s",line); printf("\n%s",line);

}INPUT :Dear,how, are, you

(a)Compile Error (b)Dear Friends (c) dear (d) runtime error4.. main() { scanf(“%c%c%c”,&I,&j,&k); } Input is : hello India hi // VARIABLES NOT DECLARED What will be the values of i,j,k ?

a) hello , India, hi b) h , e , l (c ) compile time error (d) run time error5) What will be the output of the following program :

void main() { printf(); }(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 :

61

Page 611: FRP C & DS dumps

void main() { printf("d%",8); }(a)8 (b)Compile Error (c)%d (d)None of these7) void main() { int val=5; printf("%*d",val); }(a) 5 (b)5 (c)Compile-Time Error (d)None of these

8. void main(){ printf("Hi!"); if (0 || -1) printf("Bye");}

(a)No Output (b)Hi! (c)Bye(d)Hi!Bye

9) void main(){ printf("%d %d",sizeof ( 4.56),sizeof(4.56f));}

(a)8, 4 (b)4,8 (c)8,8 (d)4,410,. main()

{ for( i=-2;i ; i++) printf(“hi\n”); } here the loop is performed how many times ?

(a) 2 ( b) 1 ( c) 3 d) infinite11. ) which of the following doesnot change value of variable i .a) i++ (b) i+1 (c) i=i+1 (d) i+=1*12. union u { Int a; Char ch[2]; }u1;U1.a=5;

61

Page 612: FRP C & DS dumps

U1.ch[0]=4 ; u1.ch[1]=2; Printf(“%d”,a); // IT SHOULD BE u1.a ( ans: 516)}(a) 5 (b) 42 ( c) 1028 (d) 24 13. void main()

{ int x, y, z; x = 27 ; y = x % 5; z = x / 5 ; } what value y and z hold currently :

(a) 2,5 (b) 2,5.4 (c) 2,5.000000 (d) none of these14. int i=10,j=25; Double k;

K = j/i; Printf(“%lf”,k);(a) 2 (b) 2.5 (c) 2.499999 (d) invalid type conversion15. static int choice;

switch(++choice,choice+1,choice-2,choice+=1)//choice =2 Currently choice will hold what value in Switch statement: (a) 2 (b) 0 (c) invalid switch statement (d) -1

16,. struct s{ int rno=10;//cannot declare here}s1;printf(“%d”, s1.rno);

(a) compile error (b) runtime error (c) 10 (d) 0

16. void main(){ int a=1,b=2,c=3; c=(--a,b++)-c; printf("%d %d %d",a,b,c);

61

Page 613: FRP C & DS dumps

} (a)0 3 -3 (b)Compile-Time Error (c)0 3 -1

(d)0 3 017. #define swap(a,b) a=b ;temp=a; ; b=temp;

void main(){ static int a=5,b=6,temp; if (a > b) swap(a,b); printf("a=%d b=%d",a,b);}(a)a=5 b=6 (b)a=6 b=5 (c)a=5 b=5 (d)None of these

18. void main(){ unsigned int val=5; printf("%u %u",val,val-21);}(a)Compile-Time error (b)5 -6 (c)5 65520 (d)None of

these19. a=5,b=6;

(++a<++b) ?—a:--b;Printf(“%d %d”,a,b);}

(a) 5 6 (b) 6 7 (c) 5 7 (d) 6 6 20. void main()

{ int x=4,y=3,z=2; *&z*=*&x**&y;

printf("%d",z);}

(a)Compile-Time error (b)Run-Time Error(c)24 (d)Unpredictable21,. char a[2][11]={“morning”,”India”) printf(“%s”, *(a[0]+3));(a) compile error (b) n (c) i (d) none of these*22. #define f(g,g2) g##g2main() { int var12=100;printf("%d",f(var,12));

61

Page 614: FRP C & DS dumps

}a)compilation error b)runtime error c)100 d)var##12

23,. int I=40; Int *p= i;//there sud be p=&i;

I++; Int *q = i; Printf(”%d %d”, *p, *q);}(a) 40 41 (b) 41 41 (c) 40 40 (d) compile time error24. The syntax of a function call statement is

a) function name (argument list); b) [storage class] function name (parameter list); c) function name (parameter list); d) [return type] function name (argument list);25. int a[5] = { 1,2,3,4,5}; a++; printf(“%d”,*a);(a) 1 (b) 2 (c) address of a[0] (d) none of these26. feof ,NULL , EOF are used for the following commands respectively

(a) fgetc,fgets,fread (b) fread, fgetc,fgets (c) fread, fgets,fgetc (d) none of these//ans sud be c27, . which of the following mode is useful for editing a file ? (a) w+ (b) r+ (c) a+ (d) a28, the term FILE is a (a) header file (b) Predefined function (c) Predefined structure (d) none of these29,. int p[3][5] = { { 2, 4, 6, 8, 10}, { 3, 6, 9, 12, 15}, { 5, 10, 15, 20, 25} };What is the vlalue of *(*(p+1)+1)+1 , *(*(p+1)+2)//ans is 7 9 so none of these(a) 6, 7 (b) 7,12 (c) 6 , 13 (d) none of these

61

Page 615: FRP C & DS dumps

30.to locate the position of file pointer in a file, which of the following function is used (a) ftell() (b) fseek ( ) (c) fwrite( ) (d) fread( )

31.Which data structures used to perform recursion?

A. FIFO StructureB. LIFO StructureC. LILO StructureD. NON Linear Structure

32.The operation for adding an entry to a stack is traditionally called: a. add b. append c. insert d. push

33.I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into a NONEMPTY queue?

a. Neither changes b. Only front_ptr changes. c. Only rear_ptr changes. d. Both change.

34.Suppose we have an array implementation of the Queue, with ten items in the Queue stored at Que[0] through Que[9]. The CAPACITY is 30. From where does the DeleteQue function deletes item in the array?

a. Que[0] b. Que[1] c. Que[9] d. Que[10]

35.If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?

a. ABDC b. DCAB c. DCBA

61

Page 616: FRP C & DS dumps

d. ABCD

*36.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 is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?

e. 1 f. 2 g. 3 h. 4 i. 5

36.One difference between a queue and a stack is: a. Queues use two ends of the structure; stacks use only one. b. Queues require dynamic memory, but stacks do not. c. Stacks require dynamic memory, but queues do not. d. Stacks use two ends of the structure, queues use only one.

37.If we draw a binary Tree for the expression : A * B - (C + D) * (P / Q) and traversed in Preorder, then we will get the following output.

a. -*AB*+CD/PQb. AB*CD+PQ/*-c. ABCDPQ-*+*/d. *-+*/ABCDPQ

38.Suppose that p is a pointer variable that contains the NULL pointer. What happens if your program tries to read or write *p?

a. A syntax error always occurs at compilation time. b. A run-time error always occurs when the program finishes. c. The results are unpredictable. d. A run-time error always occurs when *p is evaluated.

39.Which of the following stack operations could result in stack Overflow flow?

a. is_full

61

Page 617: FRP C & DS dumps

b. pop c. push d. Two or more of the above answers

40.Suppose think there is a linked list with 10 nodes and a pointer Ptr pointing to the Second node. Then which of the following statement will cause Ptr to point 5th node data.

a. Ptr->next->next->datab. Ptr->next->datac. Ptr->next->next->next->datad. Ptr->next->next->next

41.A Full Binary Search Tree contains, How many Nodes? (where ‘n’ is height)

a. n nodesb. 2^(n-1) nodesc. 2^n nodesd. (2^n)-1 nodes

42.A Structure which can refer an another Structure of same type is called as:

a. Structure within structureb. Nested structurec. Self referential structured. Dynamic structure

43.Suppose think there is a Double linked list with 15 nodes and a pointer Ptr pointing to the Fifth node. Then which of the following statement will cause Ptr to point 3th node data.

a. Ptr->next->prior->priorb. Ptr->next->next->nextc. Ptr->next->prior->prior->priord. Ptr->next->prior->next->prior

44.What kind of list is best to access the item at given position n?" a. Doubly-linked lists. b. Lists implemented with an array. c. Singly-linked lists. d. Doubly-linked or singly-linked lists are equally best

45.Suppose Ptr points to a node in a linked list. What Boolean expression will be true when Ptr points to the tail node of the list?

61

Page 618: FRP C & DS dumps

a. Ptr == NULL

b. Ptr->link == NULL

c. Ptr->data == NULL

d. Ptr->data == 0.0

e. None of the above. 46.the given below is login for Reverse traversal of a double linked list,

replace the XXXXXXX with correct statements.

for( XXXXXXX )

{

printf(“%d”, ptr->marks);

}

a. ptr =first; (ptr); ptr = ptr->nextb. ptr = last; (ptr); ptr = ptr->priorc. ptr = last; (ptr); ptr = ptr->nextd. ptr = first; (ptr); ptr = ptr->prior

47.In a Binary Search tree a new node is always inserted as:a. Right childb. Left childc. Leaf noded. Non leaf node

48.Suppose Ptr needs to point last but one node in a Double linked list. Which of the statement will give me the result?

a. Ptr=first->priorb. Ptr=last->priorc. Ptr=last->nextd. Ptr=first->next->prior

49.Which of the following applications may use a stack? a. A parentheses balancing program.

61

Page 619: FRP C & DS dumps

b. Evolution of postfix expression. c. Syntax analyzer for a compiler. d. All of the above.

1.Consider the following statement :s= fscanf(infile, “%c”, &nextChar);what is true about the above statement?

A. infile is the name of a fileB. infile is the name of a variable of type FILE*C. after the fscanf executes, s contains the next character read

from the file (unless there is no data left on the file)

a. A onlyb. B onlyc. C onlyd. All of A, B and Ce. None of A, B, or C

Answer: b. B only

2. Which of the following can be used across filesa. externb. volatilec. staticd. const

Answer: a

3. When fopen() fails to open a file it returns _______a. NULLb. -1c. 1d. None of the above

61

Page 620: FRP C & DS dumps

Answer: a. NULL

4. The EOF is equivalent to a. -1b. 1c. 0d. None of the aboveAnswer: a

5. What will be the output of following code assuming file already exists with some contents

#include<stdio.h>main(){FILE *ptr;char i;ptr=fopen("zzz.c","r");while((i=fgetch(ptr))!=EOF);

printf("%c",i);}

a. contents of zzz.cb. errorc. contents of zzz.c followed by an infinite loopd. prints some data after EOF

reaches.

Answer: D6. what is the output of the following

#define assert(cond) if(!(cond)) \

(fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort())

void main(){int i = 10;if(i==0) assert(i < 100);

62

Page 621: FRP C & DS dumps

else printf("This statement becomes else for if in assert macro");}

a. no outputb. errorc. else part is printedd. prints assertion failed in the file

Answer: c

7. What will be the output of the following code segmet

FILE *fp1,*fp2; fp1=fopen("one","w") ;fp2=fopen("one","w") ;fputc('A',fp1) ;fputc('B',fp2) ;fclose(fp1) ;fclose(fp2) ;

a. No Error, but it will over writes on same fileb. Error in pointer declarationc. Runs successfullyd. None

Answer: C

8. Considering the code Char x[20];

---- -----

fgets(x,20,fp);printf(“%s”,x);

where fp points to the file which contains the data in the following formatwiproinnovationprogram

62

Page 622: FRP C & DS dumps

what is the output?

a. wiprob. wiproinnovationprogrc. ramd. wipro\ninnovation\npro

Answer: A

9. When file opened in mode “ab”a. pointer is placed at the beginning of fileb. end of the filec. error in openingd. none of the above

Answer: b

10.Consider the following statementfseek(fp,50,4);which among the following is correct

a. moves the file pointer to beginning of fileb. moves the file pointer to the 50th byte from beginning of filec. moves file pointer to the 50th byte from end of filed. compilation error

Answer: d

SESSION 1

1. main(){

float me = 1.1;double you = 1.1;if(me==you)

printf("Hello");

62

Page 623: FRP C & DS dumps

elseprintf("Welcome");

}

1. Answer: Welcome Explanation:

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.

Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= )

2. main(){

int i=3;switch(i) { default:printf("zero"); case 1: printf("one");

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

break; case 3: printf("three");

break; }

}

2. Answer :three

Explanation :The default case can be placed anywhere inside the loop. It is

executed only when all other cases doesn't match.

62

Page 624: FRP C & DS dumps

3. main(){

int i=10;i=!i>14;printf ("i=%d",i);

}

3. Answer:i=0

Explanation:In the expression !i>14 , NOT (!) operator has more precedence

than ‘ >’ symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

4. #include<stdio.h>main(){int i=1,j=2;switch(i) { case 1: printf("GOOD");

break; case j: printf("BAD"); break; }}4. Answer:

Compiler Error: Constant expression required in function main.Explanation:

The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).

Note:Enumerated types can be used in case statements.

5. main()

62

Page 625: FRP C & DS dumps

{int i;printf("%d",scanf("%d",&i)); // value 10 is given as input here}

5. 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.

6. main(){int i=0; for(;i++;printf("%d",i)) ;

printf("%d",i);}

6. 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).

7. main(){int i=-1;+i;printf("i = %d, +i = %d \n",i,+i);}

7. Answer:

62

Page 626: FRP C & DS dumps

i = -1, +i = -1Explanation:

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).

8. main(){char not;not=!2;printf("%d",not);}

8. 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.

9. main(){int k=1;printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");}

9. 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".

62

Page 627: FRP C & DS dumps

10. main(){int y;scanf("%d",&y); // input given is 2000if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year");else printf("%d is not a leap year");}

10. Answer:2000 is a leap year

Explanation:An ordinary program to check if leap year or not.

11. main(){int i=-1;-i;printf("i = %d, -i = %d \n",i,-i);}

11. Answer:i = -1, -i = 1

Explanation:-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i. After that the value of the expression -i = -(-1) is printed.

12. int i; main(){

int t;for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--);

}

62

Page 628: FRP C & DS dumps

// If the inputs are 0,1,2,3 find the o/p

12. Answer: 4--0

3--12--2

Explanation:Let us assume some x= scanf("%d",&i)-t the values during

execution will be,

t i x 4 0 -4 3 1 -2 2 2 0

13. main(){

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }

13. Answer:hello

Explanation:The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.

14. main(){ unsigned int i; for(i=1;i>-2;i--)

printf("c aptitude");}

62

Page 629: FRP C & DS dumps

14. Explanation:i is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.

15. void main(){

while(1){if(printf("%d",printf("%d")))

break;else

continue;}

}15. Answer:

Garbage valuesExplanation:

The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.

16. #include<conio.h>main(){

int x,y=2,z,a;if(x=y%2) z=2;a=2;printf("%d %d ",z,x);

}

16. Answer: Garbage-value 0

62

Page 630: FRP C & DS dumps

Explanation:The value of y%2 is 0. This value is assigned to x. 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.

17. main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

17. Answerinfinite loopExplanationThe 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.

18. main() {

char i=0; for(;i>=0;i++) ; printf("%d\n",i); }18. Answer:128

Behavior is implementation dependent.Explanation:

The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.Rule:

63

Page 631: FRP C & DS dumps

You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.

19. main(){

char p[ ]="%d\n";p[1] = 'c';printf(p,65);

}

19. Answer:A

Explanation:Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.

20. main(){

int i=10,j=20;j = i, j?(i,j)?i:j:j;printf("%d %d",i,j);

}20. Answer:

10 10Explanation:

The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the question can be written as:

if(i,j) {

if(i,j) j = i;else

63

Page 632: FRP C & DS dumps

j = j;}

elsej = j;

21. main(){

float i=1.5;switch(i){

case 1: printf("1");case 2: printf("2");default : printf("0");

}}

21. Answer:Compiler Error: switch expression not integral

Explanation:Switch statements can be applied only to integral types.

22. Which version do you prefer of the following two,1) printf(“%s”,str); // or the more curt one2) printf(str);

22. Answer & Explanation:Prefer the first one. If the str contains any format characters like %d then it will result in a subtle bug.

23. void main(){char ch;

63

Page 633: FRP C & DS dumps

for(ch=0;ch<=127;ch++)printf(“%c %d \n“, ch, ch);}

23. Answer: Infinite LoopImplementaion dependent

Explanation:The char type may be signed or unsigned by default. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. Thus ch is always smaller than 127.

24. main(){

char a[4]="HELLO";printf("%s",a);

}

24. Answer: Compiler error: Too many initializers

Explanation:The array a is of size 4 but the string constant requires 6 bytes to get stored.

25. main(){

char a[4]="HELL";printf("%s",a);

}

25. 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

63

Page 634: FRP C & DS dumps

continues to print garbage values till it accidentally comes across a NULL character.

Session -2

26. main(){

int c=- -2;printf("c=%d",c);

}

26. Answer: c=2; Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.

Note: However you cannot give like --2. Because -- operator can only

be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

27. void main(){

int i;char a[]="\0";if(printf("%s\n",a))

printf("Ok here \n");else

printf("Forget it\n");}

27. 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, thus "Ok here" is printed.

63

Page 635: FRP C & DS dumps

28. What is the output of the program given below

main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }28. Answer

-128Explanation

Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. 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 condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.

29. main() {

char i=0; for(;i>=0;i++) ; printf("%d\n",i);

}

29. Answer:Behavior is implementation dependent.

Explanation:The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –

63

Page 636: FRP C & DS dumps

128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.

Rule:You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.

30. main(){

int i = 3;for (;i++=0;) printf(“%d”,i);

}

30. Answer:Compiler Error: Lvalue required.

Explanation:As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation.

31. main(){

int i=5,j=10;i=i&=j&&10;printf("%d %d",i,j);

}

31. Answer:1 10

Explanation:The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.

63

Page 637: FRP C & DS dumps

Session – 3

32. main(){

int i=-1,j=-1,k=0,l=2,m;m=i++&&j++&&k++||l++;printf("%d %d %d %d %d",i,j,k,l,m);

}

32. Answer: 0 0 1 3 1

Explanation :Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

33. main(){

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

}

33. Answer:45545

Explanation:The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

63

Page 638: FRP C & DS dumps

34. main(){ int i=5,j=6,z; printf("%d",i+++j); }

34. Answer:11

Explanation:the expression i+++j is treated as (i++ + j)

35. main(){ int i =0;j=0; if(i && j++) printf("%d..%d",i++,j);printf("%d..%d,i,j);}

35. Answer:0..0

Explanation:The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. The values of i and j remain unchanged and get printed.

36. void main(){

unsigned giveit=-1;int gotit;printf("%u ",++giveit);printf("%u \n",gotit=--giveit);

}36. Answer:

0 65535

63

Page 639: FRP C & DS dumps

37. main(){

unsigned int i=10;while(i-->=0)

printf("%u ",i);

}

37. Answer:10 9 8 7 6 5 4 3 2 1 0 65535 65534…..

Explanation:Since i is an unsigned integer it can never become negative. So the expression i-- >=0 will always be true, leading to an infinite loop.

38. main(){

unsigned int i=65000;while(i++!=0) ;printf("%d",i);

}

38. Answer: 1

Explanation:Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1.

39. main(){int i=5;

63

Page 640: FRP C & DS dumps

printf(“%d”,i=++i ==6);}

39. Answer:1

Explanation:The expression can be treated as i = (++i==6), because == is of higher precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.

40. main(){

int i=4,j=7;j = j || i++ && printf("YOU CAN");printf("%d %d", i, j);

}

40. Answer:4 1

Explanation:The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to zero itself means that the expression’s truth value is 1. 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.Similarly when && operator is involved in an expression, when any of the operands become false, the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated. false && (anything) => false where (anything) will not be

evaluated.

SESSION 1

1. main(){

64

Page 641: FRP C & DS dumps

float me = 1.1;double you = 1.1;if(me==you)

printf("Hello");else

printf("Welcome");}

Ans: welcome

2. main(){

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

}

Ans: linker error.

3. main(){

int i=3;switch(i) { default:printf("zero"); case 1: printf("one");

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

break; case 3: printf("three");

break; }

}

Ans: Three4. main(){

char string[]="Hello World";display(string);

}

64

Page 642: FRP C & DS dumps

void display(char *string){

printf("%s",string);}Ans::Hello World

5. #define int charmain(){

int i=65;printf("sizeof(i)=%d",sizeof(i));

}

Ans: 1

6. main(){

int i=10;i=!i>14;printf ("i=%d",i);

}

Ans: 0

7. #define square(x) x*xmain(){

int i;i = 64/square(4);printf("%d",i);

}Ans: 64

8. #include <stdio.h>#define a 10main(){

64

Page 643: FRP C & DS dumps

#define a 50printf("%d",a);

}

Ans: 50

9. #define clrscr() 100main(){

clrscr();printf("%d\n",clrscr());

}

Ans: 100

10.main(){

printf("%p",main);}

Ans : address of main

11. main(){clrscr();}clrscr();

ans::error:type mismatch

12. main(){ int i=400,j=300; printf("%d..%d");}Ans::300 400

13. main(){ int i=1; while (i<=5)

64

Page 644: FRP C & DS dumps

{ printf("%d",i); if (i>2)

goto here; i++; }}fun(){ here: printf("PP");}

Ans: error::goto here sud be defined and called in same fuction

14. #include<stdio.h>main(){int i=1,j=2;switch(i) { case 1: printf("GOOD");

break; case j: printf("BAD"); break; }}

Ans: Error::case sud have a constant value

15. main(){int i;printf("%d",scanf("%d",&i)); // value 10 is given as input here}

Ans: 1

16. main()

64

Page 645: FRP C & DS dumps

{int i=0;for(;i++;printf("%d",i)) ;

printf("%d",i); }

Ans: 1 ya since i++ will not increment first time so I is o in for that’s why

17 . main(){ extern int i; i=20; printf("%d",sizeof(i));}

Ans: Linker error

18. main(){ extern out; printf("%d", out);} int out=100;

Ans: 100

19. main(){ show();}void show(){ printf("I'm the greatest");}Ans::I m the greatest

20. main(){

64

Page 646: FRP C & DS dumps

int i=-1;+i;printf("i = %d, +i = %d \n",i,+i);}

Ans: -1 -1

21. What are the files which are automatically opened when a C file is executed?

Ans: stdinput,stdoutput,stderror.

22. main(){main();}

Ans: runs until stack overflow.

23. main(){char not;not=!2;printf("%d",not);}

Ans: 0 if %c is used then a blank is printed as !2=0

24. #define FALSE -1#define TRUE 1#define NULL 0main() { if(NULL)

puts("NULL"); else if(FALSE)

puts("TRUE"); else

puts("FALSE"); }

64

Page 647: FRP C & DS dumps

Ans: TRUE ::print as it anythng in double quotes25. main()

{int k=1;printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");}

Ans: 1==1 is True.

26. main(){int y;scanf("%d",&y); // input given is 2000if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year",y);else printf("%d is not a leap year",y);}

Ans: 2000 leap year

27. main(){int i=-1;-i;printf("i = %d, -i = %d \n",i,-i);}

Ans: i=-1 i=1

28. main(){ char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c);

64

Page 648: FRP C & DS dumps

printf("%c",x);}

convert(z){ return z-32;}

Ans: Error//1ST convert (char);will do in fuction prtotype+fuc dec convert(char z) sud be used+getc() is not a library function

29. main(int argc, char **argv){ printf("enter the character"); getchar(); sum(argv[1],argv[2]);}sum(num1,num2)int num1,num2;{ return num1+num2;}

Ans:Error??

30. int i; main(){

int t;for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--);

}// If the inputs are 0,1,2,3 find the o/p

Ans: 4—0 3—1 2—2 //GUD 1 31. main(){

64

Page 649: FRP C & DS dumps

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }

Ans:hello

32. main(){

unsigned int i; for(i=1;i>-2;i--)

printf("c aptitude");}

Ans: infinite.

33. void main(){

while(1){

if(printf("%d",printf("%d")))break;

elsecontinue;

}}

Ans: (garbage or 0) 1(compiler dependent)

34. #include<conio.h>main(){

int x,y=2,z,a;if(x=y%2)

z=2;a=2;

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

Ans: garbage 0

64

Page 650: FRP C & DS dumps

35. main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

Ans: infinite36. main()

{ char i=0; for(;i>=0;i++) ; printf("%d\n",i);

}

Ans: -128

39. main(){

char p[ ]="%d\n";p[1] = 'c';printf(p,65);

}

Ans: A

40. main(){

while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”);

}

Ans: no output//strcmp(gives 0 if all letters are equal)

41. main(){

char str1[] = {‘s’,’o’,’m’,’e’};char str2[] = {‘s’,’o’,’m’,’e’,’\0’};while (strcmp(str1,str2))

65

Page 651: FRP C & DS dumps

printf(“Strings are not equal\n”);}

Ans: no output.

42. main(){

int i=10,j=20;j = i, j?(i,j)?i:j:j;printf("%d %d",i,j);

}

Ans: 10 10

43. main(){

register int a=2;printf("Address of a = %d",&a);printf("Value of a = %d",a);

}

Ans: error

44. main(){

float i=1.5;switch(i){

case 1: printf("1");case 2: printf("2");default : printf("0");

}}

Ans: error

45. main(){

extern i;

65

Page 652: FRP C & DS dumps

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

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

} }

Ans: linker error(run time error)

46. char inputString[100] = {0};To get string input from the keyboard which one of the following is better?

1) gets(inputString)2) fgets(inputString, sizeof(inputString), fp)

Ans: 1.

47. Which version do you prefer of the following two,1) printf(“%s”,str); // or the more curt one2) printf(str);

Ans: 148. void main()

{char ch;for(ch=0;ch<=127;ch++)printf(“%c %d \n“, ch, ch);}

Ans: infinite

49. main(){

char a[4]="HELLO";printf("%s",a);

}

65

Page 653: FRP C & DS dumps

Ans: error//too many intializers

50. main(){

char a[4]="HELL";printf("%s",a);

}

Ans: HELLgarbage

51. main(){printf("%d", out);}int out=100;

Ans: error

SESSION 2

1. main(){

char s[ ]="man";int i;for(i=0;s[ i ];i++)printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}

Ans: mmmm aaaa nnnn

2. main()

65

Page 654: FRP C & DS dumps

{char *p;printf("%d %d ",sizeof(*p),sizeof(p));

}

Ans: 1 2

*3. main(){

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

Ans: 0xfff0

4. main(){

int c=- -2;printf("c=%d",c);

}

Ans: 2

5.. main(){ char *p; p="Hello"; printf("%c\n",*&*p);}//here*&p==&*pAns: H

6. main(){char *str1="abcd";char str2[]="abcd";printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));}

Ans: 2 5 5

65

Page 655: FRP C & DS dumps

7. #include<stdio.h>main() { register i=5;//valid int can be dropped char j[]= "hello"; printf("%s %d",j,i);}

Ans: hello 5

8. void main(){

int i;char a[]="\0";if(printf("%s\n",a))

printf("Ok here \n");else

printf("Forget it\n");}

Ans: Ok here

9. What is the output of the program given below

main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

Ans : -128

10. main() {

char i=0; for(;i>=0;i++) ;

65

Page 656: FRP C & DS dumps

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

}

Ans : -128

*11. void main() {

if(~0 == (unsigned int)-1)printf(“You can answer this if you know how values are represented in memory”);

}

Ans : you can answer this if you know how values are represented in memory

12. main(){

int i = 3;for (;i++=0;) printf(“%d”,i);

}

Ans : L value required error.13. main()

{int i=5,j=10;i=i&=j&&10;printf("%d %d",i,j);

}Ans : 1 10

14. #define DIM( array, type) sizeof(array)/sizeof(type)main(){

int arr[10];printf(“The dimension of the array is %d”, DIM(arr, int));

}

65

Page 657: FRP C & DS dumps

Ans: 10

15. int DIM(int array[]) {return sizeof(array)/sizeof(int );}main(){

int arr[10];printf(“The dimension of the array is %d”, DIM(arr));

}

Ans: The dimension of the array is 10

16. #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);}

Ans: Error

SESSION 31. main()

{static int var = 5;printf("%d ",var--);if(var)

main();}

Ans : 5 4 3 2 1

2. main()

65

Page 658: FRP C & DS dumps

{int i=-1,j=-1,k=0,l=2,m;m=i++&&j++&&k++||l++;printf("%d %d %d %d %d",i,j,k,l,m);

}

Ans: 0 0 1 3 1

3. #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);//asc of ‘\n’==10 so 11+98-32==77//

}

Ans: 77

4. main(){

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

}

Ans : 4,5,5,4,5

5. main(){

char *p="hai friends",*p1;p1=p;while(*p!='\0')++*p++;//whever there is a pointer we consider r to l so 1st post increment

65

Page 659: FRP C & DS dumps

printf("%s %s",p,p1);}

Ans: ibj!gsjfoet

6. main(){ static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]);}

Ans: Error

7. void main(){

int i=5;printf("%d",i++ + ++i);

}

Ans: 12

8. void main(){

int i=5;printf("%d",i++ +++i);

}

Ans : Lvalue required error

9. #include<stdio.h>main(){ char s[]={'a','b','c','\n','c','\0'};

65

Page 660: FRP C & DS dumps

char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32);}

Ans : 77

10. #include<stdio.h>main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

Ans: error

11. main(){ int i=5,j=6,z; printf("%d",i+ + +j); }

Ans: 11

12. main(){ int i=_l_abc(10);

printf("%d\n",--i);}int _l_abc(int i){ return(i++);}

Ans : 9.

13. main()

66

Page 661: FRP C & DS dumps

{ int i =0;j=0; if(i && j++) printf("%d..%d",i++,j);printf("%d..%d,i,j);}

Ans: 0 0 *14. main()

{char *p;p="%d\n";

p++; p++; printf(p-2,300);

}//printf(name of string )==will print string..Ans: 300

15. void main(){

static int i=5;if(--i){

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

}}Ans: 0 0 0 0

16. void main(){

int k=ret(sizeof(float));printf("\n here value is %d",++k);

}int ret(int ret){

ret += 2.5;return(ret);

66

Page 662: FRP C & DS dumps

}

Ans: 7.

17. void main(){

char a[]="12345\0";int i=strlen(a);printf("%d\n",++i);

}Ans: 6

*18. void main(){

unsigned giveit=-1;int gotit;printf("%u ",++giveit);printf("%u \n",gotit=--giveit);

}

Ans: 0 65535

19. void main(){

int i=i++,j=j++,k=k++;printf(“%d%d%d”,i,j,k);

}Ans: garbage

20. void main(){

static int i=i++, j=j++, k=k++;printf(“i = %d j = %d k = %d”, i, j, k);

}Ans: Error

21. main(){

unsigned int i=10;while(i-->=0)

66

Page 663: FRP C & DS dumps

printf("%u ",i);

}

Ans: infinite

22. main(){

unsigned int i=65000;while(i++!=0);printf("%d",i);

}Ans: 1

23. main(){

int i=0;while(+(+i--)!=0)

i-=i++;printf("%d",i);

}Ans: -1//ya check while

24. main(){

float f=5,g=10;enum{i=10,j=20,k=50};printf("%d\n",++k);//cannot increment.printf("%f\n",f<<2);//illegal instructionprintf("%lf\n",f%g);//illegal instructionprintf("%lf\n",fmod(f,g)); //Legal instruction

}Ans: error

25.. main(){

int i=5; printf("%d",++i++);

}

66

Page 664: FRP C & DS dumps

Ans: l value required ++(i++) since (i++)will give an constatnt value and cant perform ++ on a constant value error

26. main(){int i=5;printf(“%d”,i=++i ==6);}

Ans: 1

27. void main(){

static int i;while(i<=10)(i>2)?i++:i--;printf(“%d”, i);

}

Ans: 32767//ya

28. main(){

int i=4,j=7;j = j || i++ && printf("YOU CAN");printf("%d %d", i, j);

}Ans: 4 1

29. char *someFun1(){char temp[ ] = “string";return temp;}char *someFun2(){char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};return temp;}

66

Page 665: FRP C & DS dumps

int main(){puts(someFun1());puts(someFun2());}

Ans: garbage

SESSION 41. main()

{ int a=10,*j;void *k; j=k=&a;

j++; k++;

printf("\n %u %u ",j,k);}

Ans: type of k is unknown hence ERROR

2. Is this code legal?int *ptr;

ptr = (int *) 0x400;

Ans: Legal

3. void main(){

int i=10, j=2;int *ip= &i, *jp = &j;int k = *ip/*jp;//ya but *ip/(*jp) is valid since /* is used for commentprintf(“%d”,k);

}

Ans : error

4. void main()

66

Page 666: FRP C & DS dumps

{printf(“sizeof (void *) = %d \n“, sizeof( void *));printf(“sizeof (int *) = %d \n”, sizeof(int *));printf(“sizeof (double *) = %d \n”, sizeof(double *));printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *));}

Ans: 2 2 2 2

5. void main(){int *i = 0x400; // i points to the address 400*i = 0; // set the value of memory location pointed by i;}

Ans : Legal

6. What is the subtle error in the following code segment?void fun(int n, int arr[]){

int *p=0;int i=0;while(i++<n)

p = &arr[i];*p = 0;

}

Ans: only one stmt executes with in while loop.

7. #include <stdio.h>main(){

char * str = "hello";char * ptr = str;char least = 127;while (*ptr++)

least = (*ptr<least ) ?*ptr :least;printf("%d",least);

}Ans: 0//gud 1

66

Page 667: FRP C & DS dumps

8. main(){

int i=300;char *ptr = &i;*++ptr=2;printf("%d",i);

}

Ans:300

*9. main(){

int i = 258;int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

} //Ans: 2 1

*10. main(){

int i = 257;//int *iPtr = &i;printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

}

Ans: 1 1

11. main(){

static int a[3][3]={1,2,3,4,5,6,7,8,9};int i,j;static *p[]={a,a+1,a+2};for(i=0;i<3;i++){

for(j=0;j<3;j++)printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));

}

66

Page 668: FRP C & DS dumps

}

Ans : 1 1 1 1 2 4 2 4 3 7 3 7

4 2 4 2

5 5 5 5 6 8 6 8 7 3 7 3 8 6 8 6 9 9 9 9//gud que12. main()

{char *p="GOOD";char a[ ]="GOOD";printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p));printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));

}

Ans: 2 1 4 5 413. main()

{int a=2,*f1,*f2;//a=2,f1=&a,f2=&a// f1=f2=&a;*f2+=*f2+=a+=2.5;printf("\n%d %d %d",a,*f1,*f2);

}

Ans: 16 16 16Gud1

14. 1. const char *a;2. char* const a; 3. char const *a;-Differentiate the above declarations.

66

Page 669: FRP C & DS dumps

Ans: data constantPointer constantData constant

15. main(){

char *p = “ayqm”;char c;c = ++*p++;printf(“%c”,c);

}Ans:b

16. main(){char *p = “ayqm”;printf(“%c”,++*(p++));}

Ans: b

17. What is the output for the following program

main() {

int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );

}Ans: 1

18. Is the following statement a declaration/definition. Find what does it mean?

int (*x)[10];Ans: pointer to an array of 10 integer data.

19. main(){

66

Page 670: FRP C & DS dumps

int a[10];printf("%d",*a+1-*a+3);

}Ans: 4Gud120. void main()

{void *v;int integer=2;int *i=&integer;v=i;printf("%d",(int*)*v);

}

Ans : 2

21. # include <stdio.h>int one_d[]={1,2,3};main(){ int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr);}

//if ptr+=2 then 3 will printedAns: garbage

22. main(){ char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r);}

67

Page 671: FRP C & DS dumps

Ans : 1 2 4

23. #include<stdio.h>main(){ int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q);}

Ans: 10 garbage

24. main(){ int *j; { int i=10; j=&i; } printf("%d",*j);}

Ans: 10

25. main(){char *cptr,c;void *vptr,v;c=10; v=0;cptr=&c; vptr=&v;printf("%c%v",c,v);}

Ans: error

26. main(){ int i, n; char *x = “girl”;

67

Page 672: FRP C & DS dumps

n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) {

printf(“%s\n”,x);x++;

} }

Ans: irlrl l

27. 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);}

Ans::ck28. main( )

{ void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp);//g vp = &j; printf(“%d”,*(int *)vp);//20 vp = cp; printf(“%s”,(char *)vp + 3);//fy}http://www.orkut.co.in/Main - Home?rl=t

Ans: g 20 fy

29. main( )

67

Page 673: FRP C & DS dumps

{ 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));}

Ans: Error (Null pointer assignment)

30. 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);

31. main( ){ int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) {

printf(“%d” ,*a); a++;

} p = a; for(j=0; j<5; j++) {

printf(“%d ” ,*p); p++;

} }

67

Page 674: FRP C & DS dumps

Ans: Error

32. 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);

}

Ans: let base address be 1000.

1000 1000 1000 2 1012 1004 1002 3

33. #include<stdio.h>main(){

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };int *p,*q;p=&a[2][2][2];*q=***a;printf("%d----%d",*p,*q);

}

Ans: garbage garbage

34. main(){

int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) {

printf(" %d ",*c); ++q; } for(j=0;j<5;j++){

printf(" %d ",*p);++p; }

}

67

Page 675: FRP C & DS dumps

Ans: 2 2 2 2 2 2 3 4 6 5

35. void main(){

int const * p=5;printf("%d",++(*p));

}

Ans: error

SESSION 51. # include<stdio.h>

aaa() { printf("hi"); }bbb(){ printf("hello"); }ccc(){ printf("bye"); }main(){ int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2]();}

Ans: bye.

2. In the following pgm add a stmt in the function fun such that the address of

'a' gets stored in 'j'.main(){

67

Page 676: FRP C & DS dumps

int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }

Ans: *k=&a;

3. main(){ char a[100]; a[0]='a';a[1]='b';a[2]='c';a[4]='d'; abc(a);}abc(char a[]){ a++;

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

Ans: b c

4. func(a,b)int a,b;{

return( a= (a==b) );}

main(){int process(),func();printf("The value of process is %d !\n ",process(func,3,6));}

process(pf,val1,val2)int (*pf) ();int val1,val2;

67

Page 677: FRP C & DS dumps

{return((*pf) (val1,val2)); }

Ans: error

5. #define prod(a,b) a*bmain() {

int x=3,y=4;printf("%d",prod(x+2,y-1));

}

Ans: 10

6. int swap(int *a,int *b){ *a=*a+*b;*b=*a-*b;*a=*a-*b;}main(){

int x=10,y=20;swap(&x,&y);printf("x= %d y = %d\n",x,y);

}

Ans: 20 10

8. Explain the statement:void ( * abc( int, void ( *def) () ) ) ();

10. Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

67

Page 678: FRP C & DS dumps

11. Is there any difference between the two declarations, int foo(int *arr[]) andint foo(int *arr[2])

12. char *someFun(){char *temp = “string constant";return temp;}

int main(){puts(someFun());}

Ans: string constant.

13. main() { int i=_l_abc(10); printf(”%d\n”,–i); }

int _l_abc(int i) { return(i++); }

Ans: -1014. main(){ char a[100]; a[0]=’a';a[1]]=’b';a[2]=’c';a[4]=’d'; abc(a); }

abc(char a[]){

67

Page 679: FRP C & DS dumps

a++; printf(”%c”,*a); a++; printf(”%c”,*a); }

15. void main() { static int i=5; if(–i){ main(); printf(”%d “,i); } }

Ans:Infinite Loop No Output

SESSION 61. what will be the position of the file marker?

a: fseek(ptr,0,SEEK_SET);b: fseek(ptr,0,SEEK_CUR);

Ans: 0 offset

2. What is the problem with the following code segment?while ((fgets(receiving array,50,file_ptr)) != EOF)

;Ans : while((fgets(receiving array,50,file_ptr))!=NULL).

3. #include<stdio.h>main(){FILE *ptr;char i;ptr=fopen("zzz.c","r");while((i=fgetch(ptr))!=EOF)

printf("%c",i);}

67

Page 680: FRP C & DS dumps

Ans: linker error.fgetch() no such built in function.

4. void main(){

int *mptr, *cptr;mptr = (int*)malloc(sizeof(int));printf(“%d”,*mptr);cptr = (int*)calloc(sizeof(int),1);printf(“%d”,*cptr);

}

Ans: garbage 0

5. The value of EOF is -1.

6. Using pointers to call a function is called as function pointer

7. The variable that contains address of another variable is called as Pointer

8. How many values can be returned by a C++ function?Ans: one

9. Which of the following is mandatory for all C++ program?

a) main()b) scanf()c) system()d) all the aboveAns : main()

10. The variables that can be used only within the function in which it is declared is called as Local variable.

68

Page 681: FRP C & DS dumps

SESSION 7

1. #include<stdio.h>main(){

struct xx{ int x=3; char name[]="hello"; };struct xx *s;printf("%d",s->x);printf("%s",s->name);

}

Ans: error//declare a data type of structure then add sud be given to struct pointer

*2. #include<stdio.h>main(){

struct xx{

int x;struct yy{

char s;struct xx *p;

};struct yy *q;

};}

Ans: Error

3. enum colors {BLACK,BLUE,GREEN} main(){ printf("%d..%d..%d",BLACK,BLUE,GREEN);

68

Page 682: FRP C & DS dumps

return(1);}

Ans: 0 1 2

6. struct aaa{struct aaa *prev;int i;struct aaa *next;};

main(){ struct aaa abc,def,ghi,jkl;

int x=100;

abc.i=0;abc.prev=&jkl; abc.next=&def;

def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i;

printf("%d",x);}

Ans : 2

*7. struct point { int x; int y; };struct point origin,*pp;

68

Page 683: FRP C & DS dumps

main(){pp=&origin;printf("origin is(%d%d)\n",(*pp).x,(*pp).y);printf("origin is (%d%d)\n",pp->x,pp->y);}

Ans: 0 0 0 0

8. What is the output for the program given below

typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }

Ans: Error (multiple declaration of error). 9. typedef struct error{int warning, error, exception;}error;

main() { error g1; g1.error =1; printf("%d",g1.error); }

Ans : error

10. main(){

struct student {

char name[30];struct date dob;

}stud;struct date { int day,month,year;

68

Page 684: FRP C & DS dumps

}; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}

Ans: error

11. main(){

struct date;struct student

{char name[30];struct date dob;

}stud;struct date

{ int day,month,year; };scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}Ans: error

12. There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong?

void main(){

struct student{char name[30], rollno[6];}stud;FILE *fp = fopen(“somefile.dat”,”r”);while(!feof(fp)) {

fread(&stud, sizeof(stud), 1 , fp);puts(stud.name);

}

68

Page 685: FRP C & DS dumps

}

Ans: last record will get printed twice when feof is used.

13. Is the following code legal?struct a {

int x; struct a b;

}

Ans : no

14. Is the following code legal?struct a {

int x; struct a *b; }

Ans: no//

15. Is the following code legal?typedef struct a {

int x; aType *b;

}aType

Ans: syntax error.16. Is the following code legal?

typedef struct a aType;struct a{

int x;aType *b;

};

Ans: yes

68

Page 686: FRP C & DS dumps

17. Is the following code legal?void main(){

typedef struct a aType;aType someVariable;struct a

{ int x; aType *b;

};}

Ans: no

18. Printf can be implemented by using __________ list.

19. main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf(”%d\n”,++k); printf(”%f\n”,f<<2); printf(”%lf\n”,f%g); printf(”%lf\n”,fmod(f,g)); }

Ans:error.

1) struct value{

int bit1:1;int bit3:4;int bit4:4;

}bit={1,2,2};printf("\n %d %d %d",bit.bit1,bit.bit3,bit.bit4);

68

Page 687: FRP C & DS dumps

ans::-1,2,2

2) enum value{VAL1=0,VAL2,VAL3,VAL4,VAL5}var; printf("%d",sizeof(var));ans::2

3) enum days{MON=-1,TUE,WED=55,THU,FRI,SAT};printf("%d %d %d %d %d %d",MON,TUE,WED,THU,FRI,SAT);

ans::-1,0,55,56,57,58

4) void main(){

union var{

int a,b; }; union var v; v.a=80; v.b=100;

printf("%d",v.a); }

ans::1005) void main()

{struct node{

int data;struct node *link;

};struct node *p,*q;p=(struct node *)malloc(sizeof(struct node));q=(struct node *)malloc(sizeof(struct node));

printf("%d %d",sizeof(p),sizeof(q));

}ans::2,2

68

Page 688: FRP C & DS dumps

6) struct byte{

int one:1;};struct byte var={1};printf("%d",var.one);

ans::-1

7) enum status{pass,fail,atkt};enum status stud1,stud2,stud3;stud1=pass;stud2=atkt;stud3=fail;printf("\n %d %d %d",stud1,stud2,stud3);

ans::0 1 2

8) int i=4,j=8; printf("%d %d %d ",i|j&j|i,i|j&&j|i,i^j);

9) union x{

int i;char ch[2];

}; union x u; u.ch[0]=3; u.ch[1]=2;

printf("%d %d %d ",u.ch[0],u.ch[1],u.i);

68

Page 689: FRP C & DS dumps

10) struct course{

int courseno;char coursename[25];

};void main(){

struct course c[]={{102,"Thermal"},{103,"Manufacturing"},{104,"Design"}

};printf("%d",c[1].courseno);

printf("%s",(*(c+2)).coursename);}

ans::103 Design

11) void main(){

union test{

int i;float f;char c;

};union test *t;t=(union test *)malloc(sizeof(union test));t->i=10;printf("%d\n",t->c);t->f=10.10f;printf("%f\n",t->f);t->c='a';printf("%c\n",t->i);}

68

Page 690: FRP C & DS dumps

12) void main(){

struct address{char phone[15];char city[25];int pin; }; struct emp {

char name[25];struct address a;

}; struct emp e={"jeru","2344","kerala",55}; printf("\n name=%s phone=%s",e.name,e.a.phone); printf("\n city=%s pin=%d",e.a.city,e.a.pin);

}ans:: name=jeru phone=2344 city=kerala pin=55

13) struct book{

char name[25];char author[25];int no;

};void display(struct book *);void main(){

struct book b1={"Let us C","YPK",101};display(&b1);

}void display(struct book *b){

printf("\n %s %s %d",b->name,b->author,b->no);}

ans:: Let us C,YPK,101

69

Page 691: FRP C & DS dumps

14) void main(){

struct sample{

int num;char m1[50];char m2[50];

}m;m.num=1;strcpy(m.m1,"i love India");strcpy(m.m2,"We are Indians");printf("\n %u %u %u",&m.num,m.m1,m.m2);

}

ans::garbage value will be printed

16) void main(){

struct sample{

int a:3;int b:2;unsigned int c:3;

};struct sample s;s.a=-2;s.b=1;s.c=3;printf("\nThe value of a is %d",s.a);printf("\nThe value of b is %d",s.b);printf("\nThe value of c is %d",s.c);

s.a=2;s.b=0;s.c=5;printf("\nThe value of a is %d",s.a);printf("\nThe value of b is %d",s.b);printf("\nThe value of c is %d",s.c);

69

Page 692: FRP C & DS dumps

printf("\n Total size of the structure sample is %d",sizeof(s));}

17) struct sample{

char name[10];int no;

}; void main() {

struct sample s;void passrecord(struct sample);printf("\n Enter the name:");scanf("%s",s.name);printf("\n Enter the Roll Number:");scanf("%d",s.no);passrecord(s);printf("\n values after the function:\n");printf("\n Name : %s",s.name);printf("\n No : %d",s.no);

} void passrecord(struct sample x) {

x.no=x.no+10;printf("\n Inside the function:\n");printf("\n Name : %s",x.name);printf("\n No : %s",x.no);

}

69

Page 693: FRP C & DS dumps

18) Point out if there is any error in the programvoid main(){struct employee{

char name[25];int age;float bs;

}; struct employee e; strcpy(e.name,"Hacker"); age=25; printf("\n %s %d",e.name,e.age);}

ans::error

1. can we have more than one data members in a doubly linked list structure

a) yesb) no

3. Arrange the code below, to delete a node being pointer by temp.a) free(temp)b) temp->prev->next=temp->nextc) temp->next->prev=temp->prev;

a) b c a b) c b ac) a b cd) both a and b

4.struct list{

69

Page 694: FRP C & DS dumps

int data;struct list* left, struct list* right;};

what are the steps required to insert a new node n at a point pointed by ptr? note: ptr is not the last node.

1. n->left = ptr->left2. n->left->right = n3. ptr->left = n4. n->right = ptr

a)1 2 3 4 b) 4 3 2 1 c) 4 2 1 3 d) 3 1 2 4.

5. where does the pointer temp pointing after the

code execution, where head is startning node in D.L.L of nine nodes,. for( i=1; head!=NULL;head=head ->next, i++){

If(i==1)temp=head;

else if (i%2==1)temp= temp->next;

}

a) middle nodeb) last but one nodec) cannot make outd) second node6. What does function do, if temp is pointing to a node in DLL and

temp1 is a newnode?temp1 -> prev = temptemp1 -> next =temp ->nexttemp -> next->prev = temp1temp -> next = temp1

69

Page 695: FRP C & DS dumps

a) inserts node before temp;b) inserts after tempc) deletes node pointed by temp;d) none of the above7. What does below code do, if temp is pointing to a node other than first and last node

temp -> prev ->next = temp ->next;temp ->next -> prev = temp -> prev;free(temp);

a) no effect b) inserts a nodec) deletes a noded) shuffling of pointers

8. What does the code below do, where head is starting node & temp is temporary pointertemp=head;

head= head -> next;head -> prev = null;free(temp);

a) no effectb) NULL data is storedc) Starting node is deletedd) First and second node are shuffled

9. what does the code below do, where head is pointing to first

node & temp is a temporary pointer. 10 be the number of nodestemp = head;

while (temp->next->next!=NULL){

Temp = temp ->next;}temp -> prev -> next = temp -> next;temp -> next -> prev = temp -> prev;

69

Page 696: FRP C & DS dumps

free(temp);

a) no effect b) deletes some nodec) deletes 2nd last noded) deletes last node10. what does the code do, if there are 100 nodes

temp=head;while ( temp -> next -> next -> next != NULL){

Temp = temp -> next;}temp -> prev -> next = temp -> next;temp -> next -> prev = temp -> prev;free ( temp );

a) deletes 3rd last nodeb) no effectc) 3rd node is deletedd) Middle node is deleted

1.main(){ printf("%c\n", '1' + 1);}

a)ASCII value of '1' is required to find out the answerb)2c)50d)Syntax Errorans::b2. main(){ char y[10] = "abcdefghi"; char *p = y; p = p + 9; printf("%c\n",*p);}

69

Page 697: FRP C & DS dumps

a)ib)Program will have runtime errorc)Unpredictabled)No visible outputans::d3. main(){ int y[2][2] = { {1,2}, {3,4} }; int *p = &y[1]; p = p + 1; printf("%d\n",*p);}

a)4b)3c)The program doesn't compiled)Output is unpredicatableans::a

4. int y = 10;main(){ int x = 10; int y = 20; x = x + y; if (x >= 30) { int y = 30; x = x + y; }

69

Page 698: FRP C & DS dumps

else { int y = 40; x = x + y; } printf("%d\n", x);}a)40b)50c)60d)70ans::b

5. main(){ unsigned int i = 5; while (--i >= 0) { printf("Hello World\n"); }}a)5b)6 c)Infinited)Program will not compile

ans::c

6. struct emp{int age;char name[10];struct emp e;};

69

Page 699: FRP C & DS dumps

void main(){

printf(“%d”.sizeof(struct emp));}

a)24b) No Output c) Compiler Errord) None Of the aboveans::c

7. what is the outpur of the following prog.void main(){

insert(root,2);insert(root,1);insert(root,3);insert(root,4);insert(root,5);

preorder(root);}

assume insert function inserts a node at its correct position in the tree. root is the root of the tree and preorder function prints the nodes as in preorder traversal.

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.void main(){

int x;push(top,10);push(top,20);push(top,5);push(top,40);

69

Page 700: FRP C & DS dumps

push(top,1);push(top,25);

x=pop(top);printf(“%d”, x);}consider push function pushes onto the stack the given value. and pop operation performs pop and returns the poped value.

(a) 10 (b) 5 (c) 1 (d) 25

9. 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. The operation for adding an entry to a stack is traditionally called: a.add b.append c.insert d.push

11. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? a.ABCD b.ABDC c.DCAB d.DCBA

14 / \

2 11 / \ / \ 1 3 10 30

/ / \ 7 40 50

12. There is a tree in the box at the top of this section. How many leaves does it have?

70

Page 701: FRP C & DS dumps

A. 5 B. 6 C. 4 D. 9

13.There is a tree in the box at the top of this section. How many of the nodes have at least one sibling?

E. 5 F. 6 G. 7 H. 8 I. 9

14.There is a tree in the box at the top of this section. What is the value stored in the parent node of the node containing 30?

J. 10 K. 11 L. 14 M. 40 N. None of the above

15.There is a tree in the box at the top of this section. How many descendants does the root have?

O. 0 P. 2 Q. 9R. 8

16.There is a tree in the box at the top of this section. What is the depth of the tree?

S. 2 T. 3 U. 4 V. 8

70

Page 702: FRP C & DS dumps

W.9 17.There is a tree in the box at the top of this section. How many children does the root have?

X. 2 Y. 4 Z. 6

18. What is the value of the postfix expression 6 3 2 4 + - *: a. Something between -15 and -100 b. Something between -5 and -15 c. Something between 5 and -5 d. Something between 5 and 15 e. Something between 15 and 100

19. Suppose cursor points to a node in a linked list (using the node definition with member functions called data and link). What statement changes cursor so that it points to the next node?

a. cursor++; b. cursor = link; c. cursor += link; d. cursor = cursor->link;

20. Consider the following queue which can be allocated eightintegers and five operations.front = 1 rear= 3Queue = -,2 , 4 ,5, - , - , -,-(for notational convenience “ – “ used to denote an empty cell)

The following operations have to be performed.(i) 6 is added to the queue.(ii) Two elements are deleted from the queue.(iii) 10 and 12 are added to the queue.(iv) Two elements are deleted from the queue.(v) 2 and 3 are added to the queue.

What are the final front and rear values when the above operations are performed into a circular queue?(a) front = 7 rear=2

70

Page 703: FRP C & DS dumps

(b) front = 2 rear=0 (c) front = 5 rear=8(d) front = 5 rear=0

21. Consider the following statements: (i) The queue can be implemented by a linked list.

(ii) The queue can be implemented only by stack.(iii) There are references kept at both the front and the back of the list.(iv) The Queue can be implemented only by an array-based method.

Which of the above statement(s) is/are valid for the queues?(a) (i) only(b) (i),(ii) and (iii) only(c) (i) and (iii) only(d) (i),(iii) and (iv) only(e) (ii) and (iv) only

22. main(){int i,b[]={1,2,3,4,5},*p;p=b;++*p;Printf(“%d”,*p);P+=2;Printf(“%d”,*p);}A. 2 3B. 2 4C. 3 4D. 2 5

Ans::2 3

23. void main(){ int a=1,b=2,c=3,d=4,e; e=(a,a)+(b,c)+(c,d)-(d,b);

70

Page 704: FRP C & DS dumps

printf("%d",e);}

(a)Compile-Time Error (b)10 (c)6 (d)2

Ans::624. struct aaa{

struct aaa *prev;int i;struct aaa *next;};

main(){ struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x);}

25. 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, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69

(a)

70

14

9 26

45

69

72

16

21

11

36

88

25

Page 705: FRP C & DS dumps

(b)

(c)

(d)

70

14

26

88

36

45

72

16

21

11

9

25

69

72

16

21

11

14

9

26

88

36

69

25

45

72

16

11

14

9

21

25

36

88

26

45

69

Page 706: FRP C & DS dumps

2) which of the following data structure is used in hierarchical data modeling

a) stacksb) queuesc) treesd) structureans: trees

3) a binary tree with 20 nodes have _____ null branchesa) 20b) 22c) 21d) 40Ans: 21

4) in tree construction which of the following is suitable efficient data structure

a) arrayb) doubly linked listc) stackd) queuee) noneans: doubly linked list

5) find output of the following code. #define min(a,b) (a<b?a:b)

70

Page 707: FRP C & DS dumps

main() {

int a;a=min(3+4,4+4);printf(“%d\n”,a);

}

a) 7b) 8c) Compile time errord) Garbage.

Ans::a

6) main(){

float f=2;switch(f){

default: puts(“hi”);break;

case 2.0 : puts(“helloo”);}

}a) compile time errorb) hic) hellood) No output

Ans::a

2. which finite set of elements that is either empty or is portioned into 3 disjoint subset.

a. single linked listb. double linked listc. stackd. binary treeAnswer: D

3. what type of Binary Tree is the following tree below

70

Page 708: FRP C & DS dumps

a. strictly binary treeb. complete binary treec. almost complete binary treed. not a binary tree

Answer: D

4. Which is the preorder of a Binary tree represented below

A

B C

ED F

GH I

J K

B

D E

A

I

H

C

G

J

F

K

70

Page 709: FRP C & DS dumps

a. ABDHIECFJKGb. IHDEBKJFGCAc. IHDBEAKJFCGd. ABCDEFKJGHIAnswer: A

5. If suppose root to be deleted then which node will be the root node

a. Bb. Gc. Any noded. Both a and b are correct

Answer B6. conver this expression in prefix form

(A+B * C/D * E /G – H + I) ^ ( J /K * L)

a. ^-+//*BC*DEGA+HI/J*KLb. ^+-//*BC*DEGA+HI*J/KLc. ^-+/*/BC*DEGA+HI*J/KLd. ^-+/*/BC*DEGA+HI*J/KL

Answer: A

B

C E

A

D

G

I

J

H

K

70

Page 710: FRP C & DS dumps

7. postfix form of the following expression is A*B*C*D*E*F/G+H-I^J

a. -/*****ABCDEFGH+^IJb. AB*C*D*E*F*G/H+IJ^-c. BA*D*C*F*GH/+IJ^-d. AB*CB*D*E*F/GH*IJ^

8. which is formula to find the total no. of node in complete B.Ta. tn=2d+1 – 1 where depth(d) !=levelb. tn ==2d+1 – 1 where depth != level(L)c. tn = 2L+1

d. 2n-1Answer: A

9. what type of B.T is the following tree

a. strictly B.Tb. completely B.Tc. stricktly complete B.Td. almost complete B.T

B

G

A

C

E

H

D

F

I

71

Page 711: FRP C & DS dumps

Answer: A

10.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;While(tempvalue!=key){temp1=temp;If(tempvalue<key){temp=tempright;}else if(tempvalue>key)temp=templeft;}

if(temp1value < key)temp1right=templeft;

else if(temp1value>key)temp1left=templeft;

free(temp);

what is the output after execution of this code?

a. Deletes the key value node & make leaf node connected to its parent

b. Deletes the leaf node of key nodec. Deletes the key noded. None of the above

Answer: A

71

Page 712: FRP C & DS dumps

71