You are on page 1of 261

1)

prefer?

If you dont know the array size which one do you a) array

7)

#define t 10 void main() { }

b) linked list 2) what is the postfix of the given infix expression (a+b)*c/d-e+f

printf("%d",t); a) 10

ans::ab+c*d/e-f+ 3)

b) Error:Unfined symbol 't' preprocessor

c) Error:Improper placement of d) none of the above

void main() { int i,*j;

i=35; ??????//j=&i; }

8)

data structures used for stack a) array b) linked list c) both d) none

printf("%d",*j);

replaced by ??????

To get the 35 as the output,which statement is

9)

Explicit datatype conversion is called a) Type casting b) conversion c) separation d) none

4)

is used?

To print a single character in ouptut,which function a) getchar() b) gets()

c) putchar() d) puts() 5) The effective way of sorting is done by _______________ a) single linked list b) arrays

10) the

what is the size of char *a,int *b,float *q,if the size of double pointer is 2 bytes a) 1 1 1 b) 2 2 2 c) 4 4 4

d) 1 2 4 11) The data structure used for searching is a) arrays b) single linked list

c) Doubly linked list d) Binary search trees 6) void main() { struct emp { int a;

c) double linked list D) Binary search trees 12) For what purpose queues are used? i) expression evaluation ii) device queue for processes

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

a) i only

b) ii only

c) both i and ii

d) neither i nor ii

13)

the data is

The data structure used for sorting without moving a) arrays

printf("Unequal"); ans::error 17) main() { int i,j;

b) single linked list

c) double linked list

D) Binary search trees

for(i=0;i<2;i++) { 14) struct stack { int a[10]; int top; } } {

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

};

continue; printf("wipro"); }

struct stack *s; How will add an element called 'item' in top the stack? ans::s->a[s->top]=item

wipro would be printed 8 times

15)

predict the ouput strcut emp { char name[50]; struct emp e;

18)

which one is used to get a multiword string? a) gets b) printf c) puts

d) getchar ans::a. 19) main() {

}*oemp;

oemp->name="wipro"; ans::error

} ans::2 20) int fun() {

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

16)

Predict the output struct a { int x;

int k=10;

}e1;

struct b { }e2;

return(&k);

int y;

main() {

int *p;

if(e1==e2)//structure cannot be compared.. printf("Equal"); else

p=fun(); } ans::10

printf("%d",*p);

21)

i) char *str="welcome";

for these 2 definitions will they give you the same output for the given statement? yes 22) printf("%c",str[3]);

ii) char str[50]="welcome";

struct emp *e; }

printf("%d",sizeof(e));

ans::2 3. which is the best thing for linked list than arrays? i) Insertion ii) Deletion

void fun() { }

return(a>100?100:200);

iii) Traversal a) (i) only

void main() { }

printf("%d",fun(5));

b) (i),(ii) only c) ii,iii only d) iii only

ans::error 23) void disp(int a,int b) { } return(a>b?a+b:a*b);

4. consider the character array of size 10.When a string is more than 10 a) Error

b) Overwrites c) Nothing

void main() { }

d) garbage value 5. main()

printf("%d",,disp(5,6));

-------------------------------------------------------------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 these 2. struct emp { char *name; int a;

ans::error

{ char *str;

char *fun();

str=fun(); printf("%s",str);

char * fun() { char *buffer;

a) hello world

strcpy(buffer,"Hello world"); return buffer;

b) Compiler error

c) Runtime error d) None of the above ans::runtime error //as buffer is lost when it goes out of a function bettet to use static char *buffer allocate memory for buffer. or malloc to

main() {

};

6. main() { char *str;

b) constants

c) Expressions

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

d) All the above 11) The value of EOF is 26__-1_______. 12) () is used for __________ a) function body b) Arguments c) Return type ascII=26

char * fun() { char *buffer;

buffer=(char *) malloc(sizeof(char)); strcpy(buffer,"Hello world"); return buffer;

d) Declaration of function 13) How does the string ends? a) /n b) /t c) /0 d) none

a) hello world b) Compiler error c) Runtime error d) None of the above 7) what is the prefix expression for the given Infix expression A+B*C/D

ans::it terminated by'\0' 14) The range of Unsigned integer is a) 127 to -128 b) 0 to 65535

8) int a; a=65535;

ans::+a/*bcd

printf("%d",a); a) 0 b) Garbage c) 65535 d) -32768

c) Depend up on the compiler d) -32768 to 32767 15) which one of the following is a illegal real constants a) 32.535 b) -1.5E25 to 3.5E65 c) "53682" d) -6.583 16) main() {

ans::to be precise will be -1//key here if no>+32767 then o/p is -(65536-number) and if no<-32768 then no=(65536+(-no)); 9) main() { char p=65;

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

printf("%c",p); // output capital "A"

a) 65 b) p c) error d) none of the above 10) In a function call, _____________ is passed as arguments. a) variables }

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

a++; //array cant be incremented

a) 0 0 0 0 0

b) Garbage value c) 0 5 0 0 0 d) Compiler error 17) The size of int is 2 bytes,then what is the size of short int? a) 1 b) 2

a) Malayalam c) error

b) malayalaM d) None of the above 22) struct main { int a; int b;

c) 4 d) 8 18) In a queue,what condition applies a) First In First Out b) Last in first out

};

struct main *e1;

printf("%d %d",sizeof(e1),sizeof(*e1));

c) Elements are inserted and deleted at one end ends

ans::2 6

d) Elements can be inserted and deleted in different

23) #define wipro Hai void main() {

19) which of the following statements are true in the case of doubly linked list i) Every node is connected to other node ii) We can traverse in both the directions a) i) only

printf("wipro"); } ans::wipro

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

b)ii) only c) Both i and ii

d) neither i nor ii 20) main()

{ char str[]="Wipro Infotech"; char *s; s=&str[13]-13; while(*s)

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

ans::wipro infotech 21) char *a="Malayalam"; char *s; Char *str; str=a; s=str+8;

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

26) Queue is used for i) Expression Evaluation

ii) Scheluding the job in First come First serve a) i) only b) ii only c) both i & ii

d) neither i nor ii 27) what should be replace ????? in the program to get the output 25?

for(;s>=str;s--)

printf("%c",*s);

????? void main()

int x=2,y=3,j;

4 5

7 6

printf("%d",j);

j=SQRT(x+y);

31) Which of these will pass the address of the pointer *ptr to the function demofun()?

a) #define SQRT(int) (int * int)

a) demofun(ptr) b) demofun(&ptr) 32) which is not a valid expression a) x!=y b) x! c) !x d) x!y

b) #define SQRT(int) (int) * (int) c) #define SQRT(int) (int + int) ans::b 28) void fun() {

c) demofun(*ptr) d) demofun(*&*ptr);

d) #define SQRT(int) (int) + (int)

33) If max=10,rear=max,front=0,then what will be my queue?

static char p[]="Hello"; return p;

a) Queue Empty b) Queue Full c) Queue has one element d) Queue has max-1 elements 34) which is an indefinite loop? a) do while(0); b) for(;0;); c) while(1);

} main()

{ printf("%s",fun()); what will be the output? a) Compiler Error b) Hello c) Garbage value d) }

d) while(0); 35) int *ptr;

None

ptr=(int *)malloc(10*sizeof(int)); which is correct?

29) void main() {

i) All Values are intialised to garbage values ii) Creates memory for 10 integer data a) i only b) ii only

int *p; p=(int *)malloc(sizeof(int)); for(i=0;i<5;i++) printf("%d ",p[i]);

c) both i and ii d) neither i nor ii 36) int *ptr; ptr=(int *)calloc(10*sizeof(int)); which is correct? i) All Values are intialised to zero

What is the output? ans::garbage 30) main() {

if calloc is used o/p is 00000

int i,j; for(i=1,j=10;i<j;i++,j--); printf("%d \t%d",i,j); 1 2 3 10 9 8

ii) Creates memory for 10 integer data a) i only

b) ii only

ans::

c) both i and ii 37) Struct queue {

d) neither i nor ii

int rear;

int a[100]; struct queue *q; }

int front;

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

b) 5,4,3,2,1 d) none 42) void main() {

queue?

then how will you add a new element called 'item' in the

c) compilation error

a) q->rear[a]=item; c) q->a[rear]=item;

b) q->a[q->rear]=item; d) q->rear[q->a]=item; 38) In which of the following we can sort the data without moving the data a) Array

int b=20;

what will be the output? a) 21 b)20 c) error d) Garbage value 43) how will you refer the last node in the doubly linked list which is pointed by the pointer variable 'cursor'? a)cursor==NULL

printf("%d"*&b++);//*&b will work

b) Single Linked list c) Doubly linked list

d) Binary search trees 39) Char d=128;

b)cursor->link=NULL c)Cursor->link=0

printf("%c",d); a)128 b)-128 c)error

44) how will you refer the previous node of the pointer 'cursor' in the doubly linked list (cursor is not in the first or in the last)? a)cursor->link++ b)cursor=cursor->left c) Cursor++ d) cursor->left++

d)cursor->data=NULL

d)Garbage values 40) In the following definition struct node *ptr;

ptr=(struct node *)calloc(sizeof(ptr)); a) ptr is allocated 4 bytes

-------------------------------------------------------------1)Consider the following structure struct node {

b) ptr will be allocated sizeof struct node c) Error d) 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)

Suppose ptr is a pointer which is not pointing to the first or then the code will be a) ptr=ptr->link;

};

int info; struct node *link;

the last node.Then if we are going to delete a node after ptr,

traverse(end->prev); }

b) ptr->link=ptr;

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

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

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

a) Queue is empty b) Queue is full c) Queue has only one element d) none of the above

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;

};

struct node *link;

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 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*+

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 node b) It is a circular linked list c) It is a doubly linked list d) None of the above

d) abcdef+-*/h*+ 10) In the stack,if top=0 then the stack is a) stack is empty b) stack is full c) stack has only one element d) none of the above 11) Conside the structure struct node { int info;

3) In a queue, if rear=front then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) none of the above

4) In a queue,if rear=0,front=0 then what will be the queue a) Queue is empty b) Queue is full

c) Queue has only one element d) none of the above 5) In a queue,if rear=0,front=1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) Queue is circular

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

6) In a queue,if rear=-1,front=-1 then what will be the queue a) Queue is empty b) Queue is full

c) Queue has only one element d) none of the above

a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values 12) Struct node

7) In a queue,if rear=max-1,front=0 then what will be the queue

9
int data;

not in the end.How will you delete a node after nd?

Suppose nd is a node which is not in the beginning and also

};

struct node *left,*right;

not in the end. nd is the new node. Here is the coding: ii) nd->left=ptr; i) nd->right->left=nd; iii) nd->left->right=nd;

Suppose ptr is a node which is not in the beginning and also

a) nd->right=nd->right->left;nd->right->left=nd->left>right; b) nd->right=nd->right->right;nd->right->left=nd; d) nd->right=nd->left->right;nd->left->right=nd; 13) Struct node {

iv) nd->right=ptr->right; Then what sequence does it follows for inserting nd after ptr? a) i,ii,iii,iv c)iv,iii,ii,i b) ii,iv,i,iii d) ii,iii,i,iv 16) In the Given Infix expression which is the root node for ur expression tree a) + b) c) * d) / (A+B)-(C*D)+G/H*I

c) nd->right=nd->right->left;nd->right->left=nd->right;

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; c) nd->left=nd->left->left;nd->left->right=nd; d) nd->left=nd->left->right;nd->left->right=nd; 14) Struct node { int data; struct node *left,*right; };

b) nd->left=nd->right->right;nd->left->right=nd->right;

17) Consider a binary search tree insert(10,root); insert(25,root); insert(5,root); insert(8,root);

not in the end.How will you delete a node ptr?

}; Suppose ptr is a node which is not in the beginning and also

insert(13,root); insert(45,root); insert(70,root); insert(32,root); insert(66,root); insert(13,root);

delete(13,root);

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); >left;free(ptr);

insert(36,root); What will be the preorder traversal is a) 5,8,10,13,25,32,36,45,66,70

d) ptr->left->right=ptr->left;ptr->left->right=ptr-

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

15) Struct node { int data;

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

struct node *left,*right; };

a) 3,5,7,14,17,22,55

b) 14,55,5,7,22,17,3 c) 3,5,14,7,22,17,55 d) 55,22,17,14,7,5,3 19) The preorder traversal is 5,3,66,30,77,70 .What will be the root node a) 5 b) 66 c)70 d)30

10

for(i=0;i<=2;i++) for(j=0;j<=2;++j) ans::2 3 4 5 6 7 8 9 10 5) ans::21 6) int b=20; printf("%d",*(*(arr+i)+j));

printf("%d",++*&b);

which can be replaced by a switch block? a) do..while b) for c) while d) else if

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 right sub tree a) only i

ii) root is lesser than the left sub tree and greater than the

7)

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

b) only ii c) both i and ii

d) neither i nor ii -------------------------------------------------------------1) void main() {

8)

which of these is not a valid character constant a) "A" b) '*' c) '+' d) 'h'

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

} ans::infinite loop 2) void main() int i=1; while(++i==1) { } printf("%d",i); } ans::14 10)

printf("%d",i);

struct student { int i; char c[10];

struct student *s; }; struct student stud,*stu;

stu=&stud; printf("%d ",sizeof(stud));

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

insert(root,2); insert(root,1); insert(root,3); insert(root,4); insert(root,5); What is the inorder for the above tree?

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

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?

11

used in operations

a) Precendence are used to replace the variables b) precendence are used to allocate memory space

first

c) precendence are used to evaluate the expression d) None of the above

ans::2 1 3 4 5 12)

a,b,c,d,e are 5,2,3,3,1

The prefix expression is ab+c*d/e-.If the values of respectively,then what will be the output?

17)

aaa(){ printf("Hai")}; ccc(){ printf("Bye")}; void main() {

bbb(){ printf("Hello")};

13) What is the order in which the preorder is evaluated? i) root node ii) left node

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

iii) right node a) i,ii,iii }

b) ii,iii,i c) iii,ii,i 14) which operations are more effective in linked list than arrays? i) insertion ii) deletion d) ii,i,iii

ans:: no output nothing it will print to call function we should write (*ptr[0])(); 18)

iii) traversal a) i,ii only

most significant bit. a) true

In Unsigned char,signed value is represented by 1 in

b) false

b) iii only c) all the above d) i,iii only 15)

19)

int i=1;

switch(i*2) { case 1: printf("case1"); break; printf("case 2"); printf("default");

what is the output of the following program? void main() { int i=12; int *q; q=&i; *q=*q-8; //12-8=4

case 2: default:

printf("%d",i); } ans::4

} a) case1 case2 default b) case2 c) case2 default

break;

16) what is the use of precedence in C programs for operators?

d) compiler error 20) struct node

12
int info;

25)

#define HELLO hai void main() { }

};

struct node *left,*right;

node,then which one of the

if nd is a pointer which is pointing to the first following is correct? 26)

printf("HELLO");

ans::hello a) true b) false

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

The formal arguments has a default value zero

27)

void fun() { ????? x++;

21)

struct a { char *i;

printf("%d",x);

char *j; }; struct b { int i; }*y;

int x;

void main() {

struct a x;

x=7; printf("%d",x); x++;

printf("%d %d",sizeof(y),sizeof(*y)); ans::2 6

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

22)

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

instead of ?????

} if the outputs are 7,8,9,then which is replaced a) extern int x; b) auto int x;

c) static int x; d) register int x;

28)

if rear=-1,front=-1 then what will be my queue? a) Queue is empty b) Queue is full

23)

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

c) Queue has one element

D) Queue has max-1 element 29) void main() {

24) which one is used to check the given string is palindrome or not a) Single Linked list c) Arrays b) doubly linked list D) none of the above

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 i) It allocates 20 bytes of memory

13

{ }

printf ("HAI");

true?

ans::hai hai hai....infinite 36) *Consider a linked list where ptr is a pointer which is like new-

zero

ii) The value in the memory is allocated to a) i only b)ii only

is not pointing to the first node and not to the last node.If there is another node called "new" which >next=NULL,then what is the scenario? a) It is the first node b) It is the last node d) none of these 37)

c) both i and ii

d) neither i nor ii 31) true? If p=(int *) calloc(sizeof(int)*10),then which one is i) It allocates 20 bytes of memory

c) It is in the middle

ii) The value in the memory is allocated to zero a) i only b)ii only

then what is the value of 'a'? a) zero

If 'a' is the integer which is not statically initialized

c) both i and ii d) neither i nor ii 32) Predict the output int i=1; while(i<3) { switch(i) {

b) garbage c) none of these 38) struct emp { int a=20;//intialization cannot be done here.. char name[10]="AAA";

}; void main() {

case 1:

struct emp oemp; printf("%s",oemp->name); printf("%d",oemp->a);

printf ("Case 1"); break;

case 2:

printf ("case 2"); break;

ans::error//if struct element cannot be intialized +oemp cannot use -> only ".". 39)

default: }

printf ("Default");

Which of the following is considered as tokens in C? a) Variables b) Keywords c) Constants

33) If rear=0 front=0 what is queue? 34) if rear=max, front=0, what is queue? ans::queue is full 35) for (i=1; i=2; i++) ans::queue has one element

} ans::case1 case2

i++:

d) All the above 40) C is a ____________________ language

a) Platform independent programming b) Platform dependent programming c) Object oriented programming d) None of the above

41)

main() { int i=3; {

14
46) int sample(int x) { int *y;

switch(i) default: printf("default"); case 1: printf("case 1"); case 2: printf("case 2"); break;

x=*y+2;

y=&x;

42)

ans::default case1 case2 #define FIRST 1 #define SECOND FIRST+FIRST main() { } printf("%d",SECOND * SECOND); 47)

} void main() { int x=5;

return(x);

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

ans::7 void main() { int *j,*k;

43)

ans::3 int b[5]; main() {

static int a[5]; int i; for(i=0;i<5;i++)

int a=5,b=8; j=&a; k=&b; j=j*2; k=j/2;

} 44)

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

output::o o o o o o o o o o

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

which is having the more precendence a) * b)+ c)== d) main() { char *x="girl"; int n,i;

ans::error//mul n div cannot be done on pointers 48) To make a pointer 'cursor'as a tail node,which line is a) cursor->right==NULL b) cursor->left==NULL c) cursor==NULL d) cursor->left==0 49) Single linked list has a lnk to the next address a) true b) false

45)

correct

n=strlen(x); *x=x[n];//g will be replaced by \0 { for(i=0;i<n;i++)

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

ans::a

} ans:: } irl rl l

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 in a) header file b) within main d) none

15

} 20.5

which line is replaced for ?????? to get the ouput of ans::nothing//not reqd %f sud be used tats it main() { float v; v=10/4.0;

58)

c) outside main ans::a 54) Queue is

printf("%f",v);

ans::2.500000 i) First in first out 59) In a doubly linked list, p1 and p2 are the 2 nodes nd->next=NULL

ii) used in expression evaluation. a) i only b) ii only c) both i and ii

and node nd is inserted as

d) neither i nor ii 55) which is correct?

provided 60) void main() {

nd->prev=p1->next ans::watever the question nd is last node till data

a) Auto variables are local variables b) Extern variables are global variables c) static variables are global variables d) registers are local variables

56)

main() {

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

ans::21 -------------------------------------------------------------1. What is the output of the following: unsigned i=32768; void main() { } a. 32768

j=++*p+8; //13+8 printf("%d",j);

int i=12,j,*p; p=&i;

ans::error//must take an adress of a variable 57) int foo(int a,float b) { float c;

printf("%d",i);

c=(float)a+b; printf("%c",c); } { main() ????? foo(8,12.5);

None of the above

b. -32768

c. Error

d.

2. {

void main() static int i=3;

int i;

printf("%d",i);

16
a. c. 3 0

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

b. d. 3.

Multiple declaration (since I is static) None of the above What is the output of the following:

main() {

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

int get() { }

return(60); a. 60 6. { int *t; t=a; a=b; b=t; c. nest d. None of the } b. Garbage swap(int *a,int *b) c. Error d. 20

} {

void change(char *t) char *ab="new test"; *t=*ab; new test above b. test

} a.

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

void main()

{ int a=10,b=20;

swap(&a,&b); printf(%d %d,a,b); }

switch(i) { break; break;

a. 7.

10 20 value

b. 20 10

c. Error

d. Garbage

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

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

printf("welcome"); } } } ++i;

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

++*++p;

a.

Hi

Error

b. Welcome

c. No output

d.

a.

ibj!gsjfoet

hbj!gsjfoet hbj!gsjfoet

b. hbj!gsjfoet d. None

c.

5. # include<stdio.h> int get();

8. main() { char a[100]={abcdef};

} a)

printf(%s,&a[1]);

a++;

17

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

printf("\n%s",*p++); printf("\n%s",++*p); c)compilation error d) }

bcdef

none of the above

b) abcdef

a. dharma ewlet-packard b. harma siemens harma

9. When fopen() fails to open a file it returns _______ a. NULL b. -1 c. 1 d. None of the above 10. int i=5; { } {

hewlet-packard

fun( ) printf("%d\n", i * 3);

c. harma

main( ) int i= 2; {

d. harma harma

harma hewlet-packard

ewlet-packard 14. void main()

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

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

a. 11. main()

b. 3, 6

c. 3

d. 0

{ static int i=3;

printf("%d",i--); return i>0?main():0; }

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

15. #include <stdio.h> b. 3 2 1 c. 2 1 0 d. 2 1 main() {

a. 3 2 1 0

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 }

switch (5) case 5: printf(" 5 ");

default: printf(" 10 "); } case 6: printf(" 6 ");

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

A. 5

B. 5 10 6

C. 5 10

D. 5 6

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

A. Stack B. Register C. Extern D. Static 17. Which of the following function does not return an integer value?

18

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

A. printf 18. int i=5; { }

B. scanf

C. strcpy

D. strlen

main() { int x=10,y=20;

int abc(int z) return i/2; } a.

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

main() {

22. main()

int i=4;

printf("%d",abc(i=i/4));

char *p = ayqm; char c; c = ++*p++; printf(%c,c); b) b c) y d) z

a) error

b) 5

c) 2

d) 0 a) 23. main() {

19. What will be the output of the following program : int main() { int val=5;

} a

float i=1.5; switch(i) {

val=printf("C") + printf("Skills"); printf("%d",val); return(0); (b) C7

case 1: printf("1");

} (a) 7

CSkills7

(c) Compile-Time Error

(d) } 0

} b. 0 1 2

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

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

a.

c. 1 2 0

d. Compiler Error

e. 2 0

struct xx int x=3;

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

struct xx *s;

};

char name[]="hello";

} a.

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

25. The EOF is equivalent to a. -1 above

b. 1

c. 0

d. None of the

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

26. In a queue, if rear=max-1, front=0 then what will be the queue

a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above

19

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;

Suppose ptr is a pointer which is not pointing to the

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

b) ptr->link=ptr;

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

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

28. In the stack, if top=0 then the stack is a) Stack is empty b) Stack is full element d) None 29. struct node { int data; struct node *left,*right;

c) Stack has only one

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

};

b) c)

no effect

d)

inserts a node deletes a node

shuffling of pointers

not in the end.How will you remove a node after nd from the list? a)

nd is a node which is not in the beginning and also

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/DE*F/G

>right;

nd->right=nd->right->left;nd->right->left=nd->left-

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;

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

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

34. What is the postfix expression for A + B * C / D E * F / G a) ABC*D/+EFG*/b) ABC*D/+EF*G/c) ABCD/*+EF*G/d) None of these.

35. A binary tree with 15 nodes have _____ null branches -------------------------------------------------------------1. union u { int a; a) 15 b) 14 c) 16 d) 17

31. Consider the following structure struct node { int info;

};

struct node *link;

}u1; u1.a=5;

char ch[2];

u1.ch[0]=4 ; u1.ch[1]=2; Printf(%d,a); } (a) 5

20

(b) 42 ( c) 1028 (d) 24

#include<stdio.h> void main() { union a { int i; };

36.

that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What is the AT ONE TIME during the conversion of this expression? a. b. c. e. 1 2 3 4 5

Here is an infix expression: 6+2*(1*5-9). Suppose

maximum number of symbols that will appear on the stack

char ch[2];

union a u;

d.

u.ch[0]= 3; u.ch[1]= 2; }

printf("%d %d %d",u.ch[0],u.ch[1],u.i);

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) 3 2 515 b)515 2 3 c) 3 2 5

d) none of these main()

b. A run-time error always occurs when the program finishes.

a. A syntax error always occurs at compilation time.

c. The results are unpredictable. d. A run-time error always occurs when *p is evaluated

{ struct student

{ char name[30]; struct date dob; }stud; struct date

45.

position n? a. Doubly-linked lists. b. c. d.

What kind of list is best to access the item at given

Lists implemented with an array.

{ int day,month,year; };

equally best

Singly-linked lists. Doubly-linked or singly-linked lists are

scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

50.

stack? a. b. c.

Which of the following applications may use a A parentheses balancing program. Evolution of postfix expression. Syntax analyzer for a compiler. All of the above.

a) It scans perfectly with error b) scanf format is incorrect c) No Error d) compilation Error In printf(),the appearance of the output of the output can be affected by 1) field width

d.

2) conversion character 3) flag

4) all of the above Any of the following programs in c has access to three standard files:

21

The global variables by default belong to 1) the register type 2) the static type 3) the auto type

1) standard input file, standard output file, standard error file 2) stdin,stdout, stderr 3) keyboard,screen,screen 4) all the above

4) the dynamic type

Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above

What will be the output of the following program : void main() { z=x<<y; } (a)1000 f87

unsigned x=0xf880,y=5,z; printf("%#x %#x",z,x>>y-1); (b)8800 0xf88

Function definition void check(int i ,char*j) is 1) call by value 2)call by reference 3) both (1) and (2) 4)invalid 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

Ans. 0x1f1000 0xf88

int num[26],temp;

num[0]=100; num[25]=200;

temp=num[25];

with 0s(using the bitwise AND) 2) to copy a portion of a given bit pattern to a new

num[25]=num[0]; num[0]=temp;

printf("\n%d %d",num[0],num[25]); o/p: 200 100 2. int array[26],i;

variable,while the reminder of the new variable is filled with 1s (using the bitwise OR) 3) to copy a portion of a given bit pattern to a new variable, while the remainder of the original bit pattern is inverted within the new variable 4) all of the above

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

array[i]='A'+i;

A fields width specifier in a printf() function 1) specifies the maximum value of a number 3.

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

o/p:65=A to 97-Z int sub[50],i; {

2) controls the size of type used to print numbers 3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number

for(i=0;i<=48;i++) sub[i]=i; printf("\n%d", sub[i]);

} o/p:0-48 4. int a[5]={3,4,5,6,7}; printf("%d",a);

22

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

printf("%d , %d\n",a[i]+1); o/p:8682,8999 8686,8999

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

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",

adresss of all ints is printed printf("%s",a); o/p: akshay

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

6.

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

o/p: adress of a[5] is printed 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; 14.

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

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

printf("%s",a+2); o/p:chirag 15.

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]); o/p: 1,4 10. int i,a[2][2]={1,2,3,4}; for (i=0;i<2;i++) printf("%d",a[i]);

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

"Parag", "Chirag", "Hemal",

printf("%s",a[+2]); o/p:chirag 16.

"Hetal"};

char a[5][10]={"akshay", "Parag",

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

o/p: 8230 8234 ( adresss of ints) 11. int i,a[2][2]={1,2,3,4};

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

o/p:chirag 17. char a[5][10]={"akshay",

23

22.

char str1[]={'H','e','l','l','o'}; char str2[]="Hello"; printf("\n%s", str1); printf("\n%s", str2); o/p: Hello garbage values Hello

"Parag",

"Chirag", "Hemal", printf("%c",a[2][4]); o/p:a 18. char a[5][10]={"akshay", "Hetal"};

23. 24.

printf(5+"Good Morning"); o/p: Morning printf("%c","abcdefgh"[4]); o/p:e

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

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

printf("%c",a[2][7]); o/p: (some symbol) 1. #include<stdio.h> void display(); void main() {

19.

char c[2]="A";

printf("\n%c",c[0]); printf("\n%s",c); o/p:A A

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

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

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

2.

o/p: infinite times two statements will print #include<stdio.h> void main() {

21.

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

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

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

3.

o/p: infinite times statement will print #include<stdio.h> int check(int); void main() {

} All characters will print twice

int i=45,c;

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

c=check(i); }

printf("\n%d",c);

int check(int ch) { if(ch>=45) return (100); else } o/p:100 return (10); 6.

o/p: 20,inside display 10

#include<stdio.h> int i; void increment();

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

4.

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

int i=45,c;

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

decrement(); decrement();

int check(int ch) { if(ch>=40000) return (ch/10); else } o/p:10 return (10);

void increment() { i=i+1;

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

void decrement() {

5.

int x=10;

void display(); void main() { 7.

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

o/p:0 1 2 1 0 void fun(int,int) void main() { int i=5,j=2; fun(i,j); } printf("\n%d%d",i,j);

int x=20;

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

25
void fun(int i,int j) { i=i*i; j=j*j;

fun(vptr);

void fun(void *p) { int **q;

o/p:5,2 (call by value ex:) 8. void fun(int *,int *); void main() {

q=(int **)&p; } o/p:0 30. float x=1.1; while(x==1.1) {

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

int i=5,j=2; fun(&i,&j);

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

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

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

o/p: no output 31. int x=3,y=0,z;

o/p: 25 4(call by reference) 9. void fun(int *x,int y); void main() {

while (x>=0) { x--; y++;

if(x==y) else } o/p: 2 1 12

int i=4,j=2;

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

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

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

03 -1 4

o/p:16,2 10.

32. int x=4,y=0,z; {

while(x>=0) if(x==y) else x--; y++;

void fun(void *); int i; { void main() void *vptr; vptr=&i;

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

} o/p:4 0 31

26

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

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

33. int i=0;

for(i=1;i<=5;printf("\n%d",i)); i++;

default: prize");

printf("Ofcourse provided you win a

o/p: infinite 1s 34. int i;

} o/p: You always lose the gold prize

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

38. int i=3; {

o/p:no output 35. int i=1, j=1; for(;;) {

switch(i) case 0:

if(i>5) else

printf("\nCustomers are dicey"); case 1+0: break; case 4/2: printf("\nMarkets are pricey");

j+=i; printf("\n%d",j); } o/p:2 5 36. char suite=3; i+=j;

good");

case 8%5: printf("\nAtleast employees are } o/p: Atleast employees are good

printf("\nInvestors are moody");

switch(suite) { case 1: case 2: default: } printf("\n Diamond"); printf("\n Spade"); printf("\n Heart");

39. int k;

float j=2.0; switch(k=j+1) { case 3: printf("\n Trapped"); break;

default: }

o/p:Heart

printf("\n Caught");

37. int c=3;

o/p:Trapped

switch(c) { case '3':

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

27
case 'a':

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

case 'b': case 'A':

printf("\nYou entered b"); printf("\na as in ashar"); printf("\n You entered a and b");

2.

int b[]={0,20,0,40,5}; int i,*k; k=b; {

case 'b' + 'a': }

for(i=0;i<=4;i++) printf("\n%d",*k); k++;

o/p: You entered a and b

41. int i=1; {

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

switch(i-2) case -1: case 0: case 1: default : }

3. printf("\nFeeding Fish"); printf("\n Weeding grass"); printf("\n Mending roof"); printf("\n Just to survive");

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++;

} o/p: every char will print twice 4. char s[]="Churchgate:no church no gate"; char t[25]; char *ss,*tt; ss=s;

42.

o/p:0 50 1 43.

int x=25; printf("%d%d%d",x==25,x=50,x<78);

int x=25;

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

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

o/p:0 100 1

int x=50; printf("%d%d%d",x<78,x=100,x==50);

o/p:error(garbage value)

5.

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

1.

int b[]={10,20,30,40,50}; int i; for(i=0;i<=4;i++)

j=&arr[4]; k=(arr +4); if(j==k) location"); else

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

printf("The two pointers point to the same

same location");

printf("The two pointers do not point to the

28

a=20;

p=&a;

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

scanf("%d",p);

printf("A= %d and *P = %d",a,*p); o/p:20 20

6.

#include<stdio.h> void main() { int s[2][2]={ 10.

int **q,*p,a,b=40; a=20; p=&a;

{2,2}, {3,3}

q=&p;

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

o/p: 20 40 40 11.

*q=&b; printf("A= %d and *P = %d and **Q = %d",a,*p,**q);

float *p; int a; a=30;

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

o/p:2 2 3 3

o/p: A=30 *P=0.000000 12. float *p; int a; a=30; p=&a;

p=&a; printf("A= %d and *P=%f",a,*p);

7.

void main() { float a=13.5; float *b,*c; b=&a; c=b;

o/p:address will print

printf("Address of A= %u and Value of P=%u",&a,p);

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

13.

float a; int *p; a=30.90; p=&a;

o/p:same address and 13.500000 will print 8. int *p,a[3]={1,2,3}; p=a; printf("%d",*p++); printf("%d",*a); printf("%d",*p); o/p:1 1 2

printf("Address of A= %u and Value of P=%u",&a,p); o/p:address will print 14. int a[]={10,20,30,40,50}; int *p; p=a; printf("The value of *P is %d\n",*p); p++; o/p:10 20 15. printf("Now the value of *P is %d\n",*p);

9.

int *p,a;

int a[]={10,20,30,40,50};

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

29
}

printf("%d",i**j*i+*j);

o/p:30 21.

printf("Now the value of a[1] is %d\n",a[1]); o/p: 10 300 16. int a[]={10,20,30,40,50}; int *p; p=a;

#define disp printf void main() { } disp("Hello World");

printf("%d",*p); o/p: error 17. void main() { char *str; str="%d\n";

p=p*2;

o/p:Hello World 2. #define newline "\n" void main() { printf("Hello newline World");

o/p: 300 18.

printf(str,300);

} o/p: Hello newline World 3. #define pi 3.14 void main() {

void main() { char *str;

str="%d\n";

o/p: 300 19.

str++; printf(str-1,300);

} o/p:3.140000 4.

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

#define pi 3.14 void main() {

void main() {

char *str; str="%4s";

} o/p:K 20.

printf(str,"K");

o/p:error 5.

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

#define pi 3.14 void main() { printf("%f",pi); printf("%f",pi);

void main() { int i,*j; i=3; j=&i;

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

o/p:error

30

(3) void main() { static int arr[12]; }

6.

#define maxi(a,b) a>b?a:b void main() { float x,y; scanf("%f%f",&x,&y);

printf("%d",sizeof(arr));

o/p:0.000000

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

o/p: 24

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

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

lint1: line2: line3: line4: line5: line6: line7:

int i=20;

void main() { int *k,**j; j=&i; k=&j; printf("\n%d",i);

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

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

o/p: 1.200000 3.400000 5.700000 12.300000 0.000000 0.000000

(1) only 5 (3) only 6

(2)only 7

(4)all 5,6,7

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

(2) void main() { int x,y=6;

(6)In a normal c program the library will be defined in ________________

x=y+NULL;

(7) void main() { }

printf("%d",x); }

printf("%s",7["wipro infortech");

o/p: 6

o/p:error

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

31

case 2: break;

printf("case2"); default: } } }

char *p="hello";

printf("Default"); ++i;

char q[]={'h','e','l','l','o'};

printf("%d %d",sizeof(*p),sizeof(*q)); } o/p: 1 1 (9) #include<stdio.h> void main() { int i=0; while() { switch(i) case 3<2: break; case 3>2:

o/p:default case1 case2 case2 (11) #include<stdio.h> void main() {

char str1[]="Hello"; char str2[]="Hello" if(str1==str2) printf("\nEqual"); else

printf("Hi");

printf("\nNot equal"); } o/p:

printf("Hello"); break; default: } } } o/p: printf("welcome");

Error (12)

++i;

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

error (10) {

(4) /&hello world &/ (13)The value of EOF is _____ (1) NULL (3)-1 (14) #include<stdio.h> void main() { int i;

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

(2)0 (4)1

for(i=2;i=0;i--) { } } printf("%d",&i);

32

0/p: 50 (18)

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

No output (15) struct addr { char city[5];

printf("HELLO"); } o/p: HELLO

char street[5]; }; struct emp {

(19) Convert to prefix (a+b)*(c/d) ans: *+ab/cd (20) #include<stdio.h> struct person { char *name; char *age; char *c; };

char name[20]; int empno; struct addr *a; };

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

struct emp { int a; struct person *addr; }; void main() { struct emp *e1;

(c)neither (a)&(b) (d)either (a)&(b) (17) #include<stdio.h> void main() { int i=10; }

(b)calloc

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

printf("%d ",i=50);

o/p: 4

(21) #include<stdio.h> void main() { int i;

33

(25) #include<stdio.h> void main() { int i=10; }

i=10/4;

printf("%d",i); } o/p: 2

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

o/p: 1 #include<stdio.h> int get(); void main() { int x=20; x=get(); printf("%d ",x); } int get() { return(60); } o/p: 60 (26)

(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

(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]);

4)all the above (24) int i=6,*j;

line1: j=&i;

line2: j=&35; line&: j=&(i+25);

Which of the above lines are correct? Ans: line1

} o/p: 0 0 0 0 (29) which is better memory allocation when size is not known

34

1) a alone

(b) 4)both (a) and (b)

2)b alone

3)neither (a) nor

(33)Linked list is better than array because of 1) insertion a) (1) & (2) 2)deletion

3)traversal

1)static 2)dynamic 3)both 4)neither (30) struct city {

b) (2) & (3)

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

char name[10]; }; struct details { struct city c; };

(35)#include<stdio.h> #define wipro main void wipro() { }

char address[0];

printf("main");

o/p: main (36)#include<stdio.h> void main() {

struct details *d; How will u access address(member) 1)d->c.address >adddress 2)d.c.address 3)d.c-

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

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

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

o/p: 2 3 (37) #include<stdio.h> #define wipro printf void main() { }

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

wipro("welcome");

Ans:50 40 30 20 10 (32) A complete binary tree is

o/p: welcome (38) Which one of the following statement is false for binary search tree 1) root is less than left and right subtree

(a) non-leaf nodes have two child which is correct

(b) all left subtree less than root and root less than right tree

2)root is less than left subtree but greater than right

a) 1 only (39)

d)neigher 1 nor 2

b) 2 only

c)both 1 and 2

35

How many times wipro will be printed o/p: 1 time 42)

#include<stdio.h> aaa() {

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

printf("hi"); } bbb() {

int a=10,b=10; a+=1; }

printf((a>b)?"hi":"hello");

printf("hello"); } ccc() { }

o/p: hi 43)which is not an operator in c? 1)& 2)! 3)~ 4)::

printf("bye"); void main() {

44)Which operator is highest precedence? a)"==" b)"*" c)"+"

d)"->"

int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[1](); } o/p: hello

45)

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

static int a[5]; int i;

(40) If a=15,b=3,c=5,d=3 then a*b+c-d evaluate the expression Ans:47 (41) #include<stdio.h> void main() { int i,j; {

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 3)calloc( ) 47)

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

4)neither malloc( ) nor calloc( )

#include<stdio.h> struct emp { int i; };

printf("wipro");

char name[15];

void main() { struct emp e1={1,"hi"},*e2; e2=&e1; if(e1==e2) else

36
53)which statement used to read from file 1)fgets 2)fread

printf("\nstructures are equal"); printf("\nstructures are not equal"); } Ans:error

3)fscanf

4)sscanf 54) #include<stdio.h> fun1() {

48)The arguments in a function call are known as a) Actual parameters 49) #include<stdio.h> void main() { char *fun(); char *s; s=fun(); } b)Formal parameters

int a=5;

static int b=5; a++; b++; printf("%d ",a); printf("%d\n",b); } void main() { fun1(); fun1(); }

printf("%s",s);

char *fun() { }

o/p: 66 67

return("Hello");

o/p:Hello 50) The range of unsigned integers is _________ 51) prefix to infix

55)In what aspect linked list is efficient than array 1)Insertion 2)deletion

3)Traversal a)1 and 2 56) #include<stdio.h> void main() { int i; for(i=16/3;i<5;i++) b)3 only c)2 and 3 only

postfix to infix 52)Which is initialized as zero 1)global variable 2)static variable

3)register variable a)(1) and (2)

4)extern variable

b) (1) and (3)

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

printf("%d",i); } o/p: no output 57)

37

d) To read a line by line in a file fgets is used. Ans:(a),(b) and (d) 61)

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

#include<stdio.h> void main() { int *ptr; ptr+=3; ptr=one_d; printf("%d",*ptr); } o/p:134513856

itn one_d[]={1,2,3}; //int

a=9/4.5; }

printf("%d",a);

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

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;

else printf("False"); } o/p:True 59) #include<stdio.h> void main() { char str1[]="Hello"; char str2[]="Hello"; if(str1==str2) printf("True"); else }

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

printf("%d", *p);

}*/ o/p:22222222222

printf("False");

/* Which of the following is correct 1. signed char range is -128 to 127 2. unsigned char range is 0 to 255 3. int by default is short int

o/p:false 60)Which of the following is correct

a) 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.

4. short int by default is signed short int */ /*#include<stdio.h>

#include<string.h> void main() { int i,n; char *x = "OOAD"; n = strlen(x); *x = x[n]; for(i=0; i <n; ++i) {

38

void main() { int i=2; {

switch(i) case 2:

printf ("Case2");

case 1:

printf ("Case1"); break;

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

}*/ o/p:Case2Case1

//_________________________________________________ _____________________________

o/p:OOAD OAD AD D //_________________________________________________ _____________________________ /*#include<stdio.h> void main() {

/* When pointer is assign to null pointer what will be the output a. compile Error c. some output*/

b. runtime error while acessing the pointer

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

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

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

}*/ o/p:1 time

printf ("wipro");

}*/

//_________________________________________________ _____________________________ /*#include<stdio.h> aaa() { } printf("hi");

//_________________________________________________ _____________________________ /*#include<stdio.h>

39
bbb() { } ccc() { } printf("bye"); printf ("Hello"); i++; j++; k++; l++;

}*/ o/p:error// extern defined

printf ("%d %d %d", i, j,l);

//_________________________________________________ _____________________________ /*#include<stdio.h> void main() { const char a="b";

void main() { int (*ptr[3])(); ptr[0] = aaa; ptr[2] = ccc; }*/ o/p:bye ptr[2](); ptr[1] = bbb;

}*/ //_________________________________________________ _____________________________

//_________________________________________________ _____________________________ /*#include<stdio.h> #define wipro main wipro() { } printf ("main");

/*#include<stdio.h> void main() { int i=10; while(++i>10) { }

printf ("something");

}*/

void main() { wipro();

o/p: something will print infinitely //_________________________________________________ _____________________________ /*#include<stdio.h> define statement to

}*/

o/p: error

/*#include<stdio.h> void main() { auto int i=0;

define mul(a) (a) * (a); /*They will ask u what will be the get the output as hundred and the define statement have four opitons. This is correct option to get the output*/ /*void main() { int result;

static int j=0;

extern int k =0; register int l=0;

result = mul(10); printf ("%d", result);

40

int i=10; }*/

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

}*/

o/p:error

//_________________________________________________ _____________________________ /*#include<stdio.h> struct a { int no; int *no1; int *no2;

/*#include<stdio.h> void main() { static int arr[12];

printf("%d",sizeof(arr));

} */ o/p: 12* 4=48 // 12*2=24 /*#include<stdio.h> void main() {

} *a1;

void main() {

printf ("%d %d %d %d", sizeof(a1->no),sizeof(a1>no1), sizeof(*a1), sizeof(a1)); }*/ o/p: 4 4 12 4 // 2 2 6 2 //_________________________________________________ _____________________________ /*#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]); }*/

o/p:1.200000 3.400000 5.700000 12.300000 garbage garbage /*#include<stdio.h> void main() { int i=0; while()

static int a[5]; int i; for(i=0; i<5; i++) { } printf ("%d", a[i]);

{ switch(i) { case 3<2: printf("Hi"); break; case 3>2: break;

}*/

printf("Hello"); default:

o/p: 00000

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

printf("welcome"); } ++i; } }*/

o/p:error /*#include<stdio.h>

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

41

}*/

while(i<3) switch(i) case 1: printf("case1"); case 2:

o/p: no output

//_________________________________________________ _____________________________ /*#include<stdio.h> void main() { int i=5; printf ("%d", ~i);

printf("case2"); break; default: } }*/

printf("Default"); ++i; } }*/

o/p: -6

7.

o/p: Default case1case2case2 //_________________________________________________ _____________________________ 8.

The size of long double is a. 8 bytes b. 10 Bytes

Dependent d. There is no datatype called long double. Ans::b What is the output of the following: unsigned i=32768; void main() { } b. c. 32768 -32768 Error

c. Compiler

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

printf("%d",i);

d.

printf("\nNot equal"); }*/ o/p: Not equal

e. None of the above Ans::b 9. How many times Wipro Technologies printed in the following code: for(i=0;i<5;i++) {

//_________________________________________________ _____________________________ /*#include<stdio.h> void main() { int i;

for (j=0;j<5;j--) if (i==j) break;

for(i=2;i=0;i--)

} a. b.

printf(Wipro Technologies);

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

4 times Error

c.

d.

Infinite loop

42
a) hello world

Not predictable

10. What is the output of the following int i; { void main() static int i=3; printf("%d",i);

b) Compiler error c) Garbage Value d) None of the above

ans::c//if static char buffer is used it would have worked 12. main() {

} e. 3

int a=10,*p=&a,*q=p; printf(%d %d %d,a,*p,*q); a. b. c. d. 11 11 11 10 10 11 Error *q++;//valid

f. g.

h.

Multiple declaration (since I is static) 0 None of the above

Garbage value

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

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

Ans::c 13. #define c(a) a*a

Garbage value//actaually 10 10 garbage

#define c(b) b+b void main() { printf(%d,c(10)); } e. f. g. h. 100 20 400 Error

} void change(char *t) { char *ab="new test"; *t=*ab; new test test nest None of the above

} b. c. d. e.

Ans::f 14. void rec(int); void main() { rec(3);

Ans::d 6. main() {

} void rec(int n) { if (n<=0) return; rec(n-1); printf(%d,n); } rec(--n);

char *fun();

printf("%s",fun()); char * fun() char buffer[]=Hello World; return buffer;

a.

b. c.

1213121 0120 Infinite loop

Ans::a

d.

Error

43

char q[]={'h','e','l','l','o'};

15. int z, x=5,y=-10,a=4,b=2; What number will z in the sample code above contain? a. 5 b. 6 z=x++ - --y * b / a;

printf("%d %d",sizeof(p),sizeof(q)); a. c. 55 66 65 56

b. d.

c. 10 d. 11

ans::c 10. char* myFunc (char *ptr) { ptr += 3; }

Ans::c 13. What would be printed: #include<stdio.h> int i=0;

void main() { while(i) {

return (ptr);

switch(i) { Case 3<2:

int main()

printf("Hi"); break;

{ char *x, *y;

case 3>2:

x = "HELLO";

printf("Hello"); break;

y = myFunc (x); return 0;

printf ("y = %s \n", y); }

default: } }

printf("welcome");

What will print when the sample code above is executed? a. y = HELLO b. y = ELLO c. y = LLO d. y = LO Ans::d } b. c. d. e. Hi

++i;

Welcome No output Error

11. What would be the output? { printf("%s",7["wipro infotech"); } void main()

Ans::c 14. struct addr { char city[5];

a.

b. c.

char street[5]; }; struct emp {

d.

Garbage value fotech Error

Ans::b Garbage value //used aswipro infotech+7 12. Predict the output char p[]="hello";

char name[20]; int empno; struct addr *a; };

44
struct emp *pemp; How will you access city from the *pemp; a. c. b. pemp->a->city pemp->*a.city pemp->a.*city

(a)No Output Ans::d

(c)Bye

(b)Hi!

(d)Hi!Bye

18. void main() { printf("Hi!");

d. All the above. Ans::a //rest invalid int get();

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

(a)Compile-Time error Ans::a 19. void main() { printf("Hi!"); (c)Bye

if !(0) printf("Bye"); (b)Hi!

(d)Hi!Bye

printf("%d ",x);

if (-1+1+1+1-1-1-1+(-1)-(-1)) } printf("Bye");

{ return(60); }

(a)No Output (c)Bye Ans::d 20. void main() {

(b)Hi!

(d)Hi!Bye

a.

b. c.

60

Ans::a 16. What would be the out put of the following void main() {

d.

Garbage Error

None of the above

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

(a)0 Nas::

(c)3

(b)7

(d)No Output

int a=10,b=20,c=30; a++ || b-20 && ++c; printf("%d %d %d",a,b,c); } a. c. 11 20 31 11 0 30 Error 11 20 30

21. auto int a=5; void main() {

b. d.

(a)Compile-Time error (c)5

printf("%d",a); }

(b)Run-Time error

Ans::c 17. What will be the output of the following program : void main() {

Ans::a//auto cannot be declared outside any fuction 22. main() {

(d)Unpredictable

int a=1; if (a) printf("Test");

printf("Hi!");

if (-1) printf("Bye");

else; printf("Again");

(a)Again Ans::b 23.

45
(b)Test

int a = 4, b = 7,c; c = a = = b; printf("%i",c); a) 0 c) 1

(c)Compile-Time Error

(d)TestAgain

b) error d) garbage value

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

ans::error//= = would not work == will do

27. What will be the output of the following statements ? int a[2][2] = { 3,2,5,4 }; printf("%d",*(*(*(a)))); a) error b) 3 d) 2

(a)0.10.20.3 Ans::a

(c)Run-Time Error

(b)Compile-Time Error (d)No Output

24.Point out the error if any

c) garbage value Ans::a

#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; };//name sud be given. struct yy *q; }; }
a. b. c. Compile time error Run time error No error.

28. Which of the functions is most apt for reading a multiword ?

a) puts()

b) gets() c) scanf()

d) vsscanf() Ans::b

29. What will be the output of the following program ? #include<stdio.h>

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

d.

Compiler dependent ans::a

5. Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area Ans::4 4) all of the above 26. Predict the output

a) 300

b) 324

c) 32489 d) 89 Ans::324

30. #include<stdio.h> void main() { printf("%d"); } a) error

b) no output c) %d d) 0

46

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

Ans::d

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

int a = 36, b = 9; printf("%d",a>>a/b-2); }

b. c. e.

d. Ans::a

10 20 20 10 Error Garbage value

a) 9

b) 7 c) 5

34. main()

d) none of these Ans::a 32. #include<stdio.h> void main() {

int a,b; void small(int,int);

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

scanf("%d %d",&a,&b); } void small(int x,int y) { if (x<y)

printf("Enter 2 numbers\n");

a.

d. None of the above Ans::d//abnormal program termination 35. main( ) { char *q;

b. c.

ibj!gsjfoet

hbj!gsjfoet hbj!gsjfoet hbj!gsjfoet

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 A A is less than B Error No output

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

b. c. Ans::d { int *t; t=a; a=b; b=t; }

d.

If the input given are Wipro Technologies Chennai What will be the output a. WTChennai TChennai Chennai Chennai Chennai Chennai Wipro Technologies Chennai None of the above

33. swap(int *a,int *b)

b.

Ans::d

c. d.

36. main() { int i, n; char *x = OOAD;

n = strlen(x); *x = x[n]; { for(i=0; i<n; ++i) printf(%s\n,x); x++;

47

Ans::a

d.

None of the above

39. main() { char *p; int *q; p=0; q=0; r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); long *r;

} a.

OOAD OAD AD

b.

OAD AD D

} a.

Ans::b 37. #define FALSE -1

c. d.

No output None of the above

b. c.

0001 0002 0004

#define TRUE 1

#define NULL 0 main() {

40. # include<stdio.h> aaa() { printf("hi"); } bbb(){ } ccc(){

d. Error Ans::a//inc by their type value in p,q r set to zero

0000:0001 0000:0002 0000:0004 124

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

printf("hello");

main()

printf("bye"); }

a. b.

Ans::a

c. d.

TRUE FALSE

TRUE FALSE Error

{ int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; } a. c. (*ptr)();

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

} a.

b. d.

hi

hello bye Error

b. c.

-1

Error 0

Ans::hi

1) Which of the following is a compound assignment statement? a)a=b

48

int a;

b) a=b=c c) a+=b ans::c d) a=b;b=c;

char name[10]; }s1,*s2; int *p;

printf("%d%d",sizeof(s1),sizeof(*s2)); a) 18,18 b)18,4 c) 4,18 ans::a d) 4,4

2) given that the file is being read using fgetc command,as ch =fgetc(fp),then what is the condition to check for the end of the file a) ch!=EOF

b) ch!=NULL

ans::a

c) ch==NULL d) ch=='\0'

8) what would the statement strcmp("Astring","Astring"); return? a) 0 b) <1 c)>1 ans::a d) -1

3) which of the following accepts only the specified number of characters from a file a) fgets b) fread c) fputc d) fputs

ans::a

9) which statement is used to compare the two strings ? a) strcmp b)strcompare c) stringcompare ans::a { d) str_cmp

4) which of the following is the best for getting a string with space from the standard input a) gets b) getc

d) puts ans::fgets//gets

c) fgets

10) int fun(int x) int y=55;

5)how to represent a character pointer named 'message' pointing to the array"hello" a) char message="hello" b) char message[ ]="hello" c) char *message="hello" ans::c

main() { int a=20;

return((x-y)?y:x);

d) char *message[ ]="hello" }

6) which data structure is best for searching an element in the given list a) arrays

fun(a); printf("%d",y);

b) single linked list c) doubly linked list ans::d

ans::error

d) binary search trees

11) main() {

static int a[10]={1,2,3,4,5}; for(i=0;i<10;i++) int i;

7) assume that integer is 4 bytes,pointer as 4 byter and character as 1 byte,then predict the output struct student }

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

ans::1 2 3 4 5 0 0 0 0 0 12) main() { char *y; printf("%s",y); y=x();

49

made at the last

b) insertion is made at the beginning and deletion is c) insertion is made at the last and deletion is made d) both insertion and deltionis made at the back end

at the beginning ans::c

} char *x() {

17) main() { int i=10;

char result[ ]="Hello"; return result;

strcpy(result,"anything good"); }

ans::1

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

ans::buffer die after function get lost A)5,10,20

18) main() {

13) The post order is 5,20,10.what will be the inorder? b) 20,5,10 c) 20,10,5 ans::a }

char c='p';

printf("%c",c);

d) none of the above

ans::p 19) main() { int i=0; {

14) int fact(int x) { ??????

while(i<3) switch(i) { case 3>2:

main() { fact(5);

return(x*fact(x-1));

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

break; case 3<2:

printf("case1"):

defalut:

printf("case2"); break; printf("default"); break;

d) none of the above }

i++;

15) Allocating a 2 blocks of memory for 'n' intgers is by using a) malloc b) calloc c) both malloc and calloc ans::b d) none of the above

ans::case2case1 20) which is correct? a) unsigned char short c) short unsigned char ans::b 21) void fun(char *str) d)noneof the above

b) unsigned short char

16) In queue using linked list, which is correct?

a) both insertion and deltionis made at the front end

50
char *str1="hai"; str=str1;

how many times would wipro to be printed? ans::wipro will be printed only one times. 28) main() { FILE *fp;

} {

main() char *str="Hello"; fun(str); printf("%s",str);

ans::hello {

char data[100]; printf("Enter the file name"); gets(data);

22) struct city char *name[20]; int age;

????

} fp=fopen(data,"r");

fclose(fp);

}*s;

what would be replaced for ???? to open a file in a read mode

s->name[]=(char*)

how to allocatethe memory for the member 'name'?

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;

29) main() {

p=a[2]; }

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

25) what kind of error does the syntax error is? 26) float fun( f1) { return(f1*f1);

error 30) which of these isn an infinite loop i) for(;;); ii)for(i=1;;i++); iii) for(i=0;i<=5;i++) { --i;}

} main() {

a) i,ii only b) i only c)all the three ans::c

float f1=3.25; fun(f1); }

printf("%f",f1);

d) none of the above

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

ans::3.25//also f1 will take int value only

31)which of these is replaced by a switch block? a) while loop b) do while c) for loop d)else if

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

printf("wipro"); }

32) void disp(char *string) { printf("%d\n",string);

void main() { char string[ ]="Hello world"; printf("%d\n",string); disp(string);

printf("%s\n",string); //Hello World

51
37) all the local variables are stored in ----------------a) stack b) heap

c) queue ans::a d) none

38) Once you call a function,all the return addresses are stored in ---------------a) stack b) heap

33) char *gxxx() { static char x[1024]; printf("%s\n",x); return x;

c) queue ans::a d) none

} {

39) Which of the following is true about binary tree

i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and

void main() char *g="string";

strcpy(gxxx(),g); g=gxxx();

lesser than the right sub tree. a) i only

strcpy(g,"old string"); }

b)ii only c) both i and ii

printf("%s\n",gxxx());

ans::old string 34) main() { char s[ ]="\12345s\n"; printf("%d\n",sizeof(str));

ans::b 40) Which of the following is true about complete binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and

d) neither i nor ii

} ans::6

lesser than the right sub tree. a) i only

35) main() { night"}; char *k[ ]={" Good Morning","Good Evening","Good printf("%s\n",k[0]); 41) struct node {

b)ii only c) both i and ii

d) neither i nor ii

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; ans::c

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

int data;

suppose start and end are the pointers pointing to the beginning and ending node reapectively.then, what will be the output of the following snippet front=start; back=end; {

};

struct node *left,*right;

d) none of the above

while(back!=NULL) printf("%d",back->data);

back=back->left;

52

struct e { char *f;

reverse printing 42) struct node { int data;

}abc;

struct a *g;

printf("%d",sizeof(abc)); ans::4(2+2) 46) struct a { char *b;

suppose start and end are the pointers pointing to the the output of the following snippet front=start; back=end; {

struct node *left,*right; };

beginning and ending node reapectively.then,what will be

while((front!=back)&&(back->left!=front)) temp=front->data;

struct e { char *f; struct a g;

};

char *c; char *d;

front->data=back->data; back->data=temp;

reverse printing 43) the declaration of the pinter to an array of int having the name iptr is ------------------a) int *iptr b) int &iptr c) int *&iptr d)iptr *int ans::a

}abc; printf("%d",sizeof(abc)); ans::8(2+2+2+2)

47)#define wipro main wipro() {

} ans::main

printf("main");

44) int one_d={0,1,2}; main() {

48) void prod(int x,int y,int z) { int p; p=x*y*z; printf("%d",p);

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

} void main() {

ans::error 45) struct a { char *b; char *c; }; char *d;

prod(a,b,c);

int a=3,b=4,c=5;

} 49) int meq(); void main() {

printf("Hai");

meq(); printf("Hello");

} { }

53

meq() printf("Bye"); ans::HaiByeHello 49) void main() { char *p="welcome";

i=10/20; }

printf("%d",i); ans::0 56) The arguments in a function call is known as -------------------a) formal arguments b) actual arguments

char q[ ]={'w','e','l','c','o','m','e'}; }

printf("%d %d",sizeof(*p),sizeof(*q)); ans::11 50) The size of the doubly linked list is always greater than the single linked list a) true b) false

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

51) char *ptr="abcdefgh"; char *sptr; sptr=ptr+5; printf("%s",sptr); ans::fgh 52) If the integer occupies 2 bytes then short int will take how many bytes?

int i=20; { int i=30;

printf("%d",i); } printf("%d",i); } ans::3020

53) In C, syntax error is generated by --------------------a) compiler b) Interpreter C) linker d) none 54) char *ptr="Madam"; char *sptr=ptr+4; while(sptr>=ptr) {

59) void fun(); main() { fun();

} void fun() { } printf("good");

sptr--; }

printf("%c",*sptr);

ans::good 60) void main() { int i=10;j=20,k=30,l=40,m;

ans::madaM 55) void main() { int i;

int *a[4]; a[0]=&i;

a[1]=&j;

54

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) array b) stack

Note :

compilers.

All the programs are tested under Turbo C/C++ It is assumed that,

Programs run under DOS environment,

The underlying machine is an x86 system, compiler.

Program is compiled using Turbo C/C++ The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

c) queue d) linked list 62) to access the 4th element in the array 'num' we need -----------a) num[4] b) num[1]

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

c)num[3] d) none of the above

1. void main() { int const * p=5; printf("%d",++(*p)); } Answer:


value.

Compiler error: Cannot modify a constant

63) void main() { char *a[ ]={"Dharma","Hewlett packard","New city","ibm"}; char **ptr=a; printf("%s",++*p); printf("%s",*p++); } printf("%s",*p);

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

Explanation:

ans::harma..harma..Hewlett packard

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 s[i], *(i+s), *(s+i), i[s] are all different ways of

Explanation:

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]. C Questions

3. main() {

float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); Answer:

55
} Answer:

++p;

2222223465

Explanation:

Explanation:

I hate U For floating point numbers (float, double,

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.

Initially pointer c is assigned to both p and

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 (== , >, <, <=, >=,!= ) .

6. main() { extern int i; i=20; printf("%d",i); } Answer:

4. main() { static int var = 5; printf("%d ",var--); if(var) main(); } Answer: Explanation:
54321

Linker Error : Undefined symbol '_i' Explanation:

extern int i; specifies to the compiler that the memory for i is allocated in

extern storage class in the following declaration,

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 .

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.

When static storage class is given, it is

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

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


00131

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

Explanation :

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.

56

Explanation :

left shifted four times the least significant 4 bits are filled value be printed as a hexadecimal value.

-1 is internally represented as all 1's. When

8. main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); } Answer:


12

with 0's.The %x format specifier specifies that the integer

Explanation:

bytes taken by its operand. P is a character pointer, which

The sizeof() operator gives the number of

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.

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

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; } } Answer : Explanation :
three

Explanation :

encountered, the compiler doesn't know anything about the

In third line, when the function display is

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; printf("c=%d",c); } Answer: Explanation:


c=2;

inside the loop. It is executed only when all other cases doesn't match.

The default case can be placed anywhere

used twice. Same maths rules applies, ie. minus * minus= plus. Note:

Here unary minus (or negation) operator is

10. main() { printf("%x",-1<<4); } Answer:


fff0

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

However you cannot give like --2. Because

13. #define int char main()

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

Explanation:

sizeof(i)=1

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

14. main() { int i=10; i=!i>14; Printf ("i=%d",i); } Answer: Explanation:


i=0

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: Explanation:
SomeGarbageValue---1

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 of 3D array.

starting address of a. If you print *q, it will print first element

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() { 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: Explanation:
77

17. #include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); } Answer: Explanation:

Compiler Error

You should not initialize variables in declaration

character 'a' ++*p. "p is pointing to '\n' and that is

p is pointing to character '\n'. str1 is pointing to

incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 ASCII value of 'b' is 98.

is pointing to 'a' that is incremented by 1 and it becomes 'b'. Now performing (11 + 98 32), we get 77("M"); So we get the output 77 :: "M" (Ascii is 77).

18. #include<stdio.h> main() { struct xx { int x; struct yy { char s;

};

struct xx *p; }; struct yy *q;

58

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

Answer:

Explanation:

Compiler Error The structure yy is nested within structure

Explanation:

64

xx. Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to

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

the macro call square(4) will substituted by

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"); printf("\bsi"); printf("\rha"); } Answer: Explanation:


hai

22. main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); } Answer: Explanation:
ibj!gsjfoet

*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 Hence, in the while loop initial value pointed by p is h, which is changed to i by executing ++*p and pointer moves that is p++ will be executed

++*p++ will be parse in the given order

\n - newline \r - linefeed

\b - backspace

20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer: Explanation:


45545

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.

pushed into the stack from left to right. The evaluation is by

The arguments in a function call are

popping out from the stack. and the evaluation is from right to left, hence the result.

21. #define square(x) x*x main() { int i;

23. #include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); } Answer: Explanation:


50

redefined anywhere in the program. So the most recently assigned value will be taken.

The

preprocessor

directives

can

be

59

Explanation:

No output/error The first clrscr() occurs inside a function. clrscr(); is a function declaration (because it is not inside any function).

24. #define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); } Answer: Explanation:


100

So it becomes a function call. In the second

28)

enum colors {BLACK,BLUE,GREEN} main() {

printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1);

before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input program to compiler looks like this : main() {

Preprocessor executes as a seperate pass

Answer:

Explanation:

0..1..2 enum assigns numbers starting from 0, if

Note:

100; printf("%d\n",100);

not explicitly defined. 29) void main()

action. So it doesn't give any problem

100; is an executable statement but with no

{ char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

25. main() { printf("%p",main); } Answer: Explanation:

Answer:

Some address will be printed. Function names are just addresses (just like

Explanation:
far pointer 30) main() {

4..2 the second pointer is of char type and not a

array names are addresses). main() is also a function. So the address of function main will address. They are printed as hexadecimal numbers. 27) main() { }

be printed. %p in printf specifies that the argument is an

int i=400,j=300;

printf("%d..%d");

Answer:

clrscr(); clrscr();

Explanation:

400..300 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

Answer:

assignments given in the program,then printf will take garbage values. 31) main() char *p;

60

33)

main() static int i; char

names[5][20]={"pascal","ada","cobol","fortran","perl"}; char *t;

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

p="Hello";

t=names[3];

Answer:

names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) } printf("%s",names[i]);

Explanation:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. string "Hello". *p dereferences it and so its Here p points to the first character in the value is H. Again & references it to an address and * dereferences it to the value H.

Answer:
main

Compiler error: Lvalue required in function

Explanation:

cannot be modified. 34) void main() {

Array names are pointer constants. So it

32)

main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) i++; goto here;

int i=5;

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

Answer:

Explanation:
i 35)

Output Cannot be predicted exactly. Side effects are involved in the evaluation of

} {

fun() here:

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

printf("PP");

Answer:

Answer:

function main

Compiler error: Undefined label 'here' in

Explanation:

Compiler Error The expression i+++++i is parsed as i ++ ++ +

Explanation:

Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function main. 36)

i which is an illegal combination of operators. #include<stdio.h> main() { int i=1,j=2;

function fun() Hence it is not visible in

switch(i) { case 1: printf("GOOD"); case j: printf("BAD"); } break; break;

61

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

Answer:

Explanation:

before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the semicolon after the for loop).

Answer:

required in function main.

Compiler

Error:

Constant

expression

loop, and i is incremented (note the

Explanation:

The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).

40)

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

Note:

statements. 37) main() { int i;

Enumerated types can be used in case

printf("%d",scanf("%d",&i)); // value 10 is given as input here }

str1=s; printf("%d",++*p + ++*str1-32);

Answer:

Answer:

Explanation:

M //77 p is pointing to character '\n'.str1 is

Explanation:

pointing to character 'a' ++*p meAnswer:"p

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##g2 //concat main() {

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

int var12=100; }

printf("%d",f(var,12));

Answer:

100

struct xx {

39)

main() { int i=0;

int x=3;

struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x);

};

char name[]="hello";

printf("%s",s->name); }

62

44)

main() { } printf("%d", out); int out=100;

Answer:

Explanation:

Compiler Error Initialization should not be done for structure members inside the structure declaration

Answer:

function main.

Compiler error: undefined symbol out in

42)

#include<stdio.h> main() {

Explanation:

The rule is that a variable is available for

use from the point of declaration. Even available for main. Hence an error. 45) main() { extern out;

struct xx { int x; { struct yy char s; struct xx *p;

though a is a global variable, it is not

}; struct yy *q; } };

printf("%d", out); }

Answer:

int out=100; 100

Answer:

Explanation:
Compiler Error in the end of nested structure yy a member 46)

Explanation:

previous program. main()

This is the correct way of writing the

have to be declared. 43) main() {

{ show();

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

} void show() { printf("I'm the greatest"); }

Answer:

Answer:

Explanation:

Linker error: undefined symbol '_i'. extern declaration specifies that the

redeclaration of show.

Compier

error:

Type

mismatch

in

Explanation:

variable i is defined somewhere else. The compiler passes the external variable to be find an error. During linking the linker searches for the definition of i. Since it is not found the linker flags an error.

When the compiler sees the function show

resolved by the linker. So compiler doesn't

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(). before the use of show(). 47) main( ) { int a[2][3][2]

63

3. declare extern void show() }

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

Answer:
=

Compiler error: lvalue required.

{{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(%u %u %u %d \n,a,*a,**a,***a); }

Explanation:

printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1);

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

Answer:

Explanation:

100, 100, 100, 2 114, 104, 102, 3 The given array is a 3-D one. It can also be 49) main( ) {

lvalue. Simply array name is a nonmodifiable lvalue.

viewed as a 1-D array.

2 118 120 122

100 102 104 106 108

110 112 114 116

int 4 **ptr = p; ptr++;

static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4};

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

thus, for the first printf statement a, *a, **a give address of first element . since the first line of the output. indirection ***a gives the value. Hence, the for the second printf a+1 increases in the *a+1 increments in second dimension thus

third dimension thus points to value at 114, 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( ) {

printf(\n %d %d %d, ptr-p, *ptr-a, **ptr); }

++*ptr;

Answer:

Let us consider the array and the two pointers with some address

111 222 333 344 Explanation:

int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { 0 108 100 1 102 2 104 3 106 4

printf(%d ,*a); a++;

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

p = a;

p 100 102 104 106 108

1008

1000

1002 ptr

1004

1006

64

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 TRACK and VIRTUAL. Then for the first 100 then the input one is stored as M O U S E value by 1. Suppose the inputs are MOUSE, input suppose the pointer starts at location \0

1000 2000 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

When the second input is given the pointer

is incremented as j value becomes 1, so the input is filled in memory starting from 101. M T R A C K \0 The third input location 102 M T V starts filling from the I R T U

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 third printf are ptr p = 3, *ptr a = 3, **ptr = 3.

position q, q+1 and q+2 = M T V The second printf prints three strings starting from locations q, q+1, q+2 i.e MTVIRTUAL, TVIRTUAL and VIRTUAL.

This is the final value stored . The first printf prints the values at the

51)

main( ) { void *vp;

becomes1004. Hence, the outputs for the

After execution of ++*ptr value in ptr

char ch = g, *cp = goofy; int j = 20; vp = &ch; printf(%c, *(char *)vp); vp = &j; printf(%d,*(int *)vp); printf(%s,(char *)vp + 3); } vp = cp;

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;

Answer:

Explanation:

g20fy 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

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:

printf statement type casts it to print the fy. 52) main ( ) { static char *s[ ]

65

string from the 4th value hence the output is

(blank space) irl rl l

violet};

= {black, white, yellow,

Explanation:

Here a string (a pointer to char) is

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

initialized with a value girl. The strlen function returns the length of the string, assigns value at the nth location (\0) to

thus n has a value 4. The next statement the first location. Now the string becomes

printf(%s,*--*++p + 3);

Answer:

Explanation:

ck

\0irl . Now the printf statement prints the string after each iteration it increments it starting position. Loop starts from 0 to 4. nothing and pointer value is incremented. The first time x[0] = \0 hence it prints The second time it prints from x[1] i.e irl and the third time it prints rl and the last 54) int i,j; { j+=5; time it prints l and the loop terminates.

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

for(i=0;i<=10;i++)

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

assert(i<5); }

Answer:

Runtime termination. name>,<line number>

error: assert

Abnormal failed (i<5),

program <file

Explanation:

{ int i, n;

asserts are used during debugging to make sure that certain conditions are satisfied. If assertion fails, the program will terminate reporting the same. After debugging use, #undef NDEBUG

char *x = girl; n = strlen(x); *x = x[n];

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

the source code. Assertion

and this will disable all the assertions from is a good debugging tool to make use of.

printf(%s\n,x);

55)

main() { int i=-1;

Answer:

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

66
60) main() { } main();

Answer:

Explanation:

i = -1, +i = -1 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

Answer:

Explanation:

Runtime error : Stack overflow. 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

when a C file is executed?

Answer:

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

stdin,

stdout,

stderr

(standard

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;

Answer :

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

a: The SEEK_SET sets the file position

cptr=&c; vptr=&v;

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

Answer:

is Unknown.

Compiler error (at line number 4): size of v

Explanation:

char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?

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 an error. 62) main() {

vptr of type void * and v of type void hence

Answer:

First it checks for the leading white space and discards it.Then it matches with a quotation mark and then it character upto another quotation mark. reads all

char *str1="abcd"; printf("%d

char str2[]="abcd"; %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }

59) What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

%d

Answer:

Answer & Explanation:

fgets returns a pointer. So the correct end of file check is checking for != NULL.

Explanation:

255 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

67

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; }

Preprocessor doesn't replace the values

given inside the double quotes. The check by if condition is boolean value false so it true hence "TRUE" is printed. 65) main() goes to else. In second if -1 is boolean value

printf("%d",not);

printf("%d==1is""%s",k,k==1?"TRUE":"FALSE"); }

{ int k=1;

Answer:

Explanation:

Answer:

! is a logical operator. In C the value 0 is

Explanation:

1==1 is TRUE When two strings are placed together (or separated by white-space) is they concatenated (this called as

considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a nonzero value so TRUE. !TRUE is FALSE (0) so it prints 0. 64)

are

"stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE". 66) main() {

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

else if(FALSE) puts("TRUE"); else }

puts("NULL");

int y; scanf("%d",&y); // input given is 2000 printf("%d is a leap year"); else }

if( (y%4==0 && y%100 != 0) || y%100 == 0 )

puts("FALSE");

printf("%d is not a leap year");

Answer:

Answer:

Explanation:

TRUE The input program to the compiler after processing by the preprocessor is, main(){ if(0) 67)

Explanation:
or not.

2000 is a leap year An ordinary program to check if leap year

#define max 5 main() {

puts("NULL"); else if(-1) else } puts("TRUE");

#define int arr1[max]

typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name";

puts("FALSE");

printf("%d %s",list[0],name); }

Answer:

68
Compiler error (in the line arr1 list =

int *j; { int i=10; j=&i; } }

{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

printf("%d",*j);

the case of arr1. Hence an error. Rule of Thumb:

Answer:

#defines are used for textual replacement new types.

whereas typedefs are used for declaring

Explanation:

10

The variable i is a block level variable and

the visibility is inside that block only. But

68)

int i=10; main() {

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

extern int i; { int i=20;

{ const volatile unsigned i=30; printf("%d",i);

int i=-1; -i; }

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

} printf("%d",i);

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

Answer:

Explanation:

i = -1, -i = 1 -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.

Answer:

Explanation:

30,20,10 '{' introduces new block and thus new as,

scope. In the innermost block i is declared const volatile unsigned

71)

#include<stdio.h> main() {

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 it. After compilation is over the linker resolves it to global variable i (since it is the value as 10. 69) main() {

const int i=4; float j; j = ++i; printf("%d %f", i,++j);

extern, so no storage space is allocated for

Answer:

only variable visible there). So it prints i's

Explanation:
of constant 72)

Compiler error i is a constant. you cannot change the value

#include<stdio.h>

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

69

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;

Answer:

Explanation:

garbagevalue..1 p=&a[2][2][2] you declare only two 2D

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; printf("%d",x); }

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 *q meAnswer:it will print first element of 3D array. 73) #include<stdio.h> main() { register i=5; pointing to starting address of a.if you print

x=abc.next->next->prev->next->i;

Answer:

Explanation:
linked list;

above all statements form a double circular abc.next->next->prev->next->i this one points to "ghi" node the value of at

char j[]= "hello"; printf("%s %d",j,i);

particular node is 2. 77) struct point { int x; int y; };

Answer:

Explanation:

hello 5 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.

struct point origin,*pp; main() {

74)

main() { int i=5,j=6,z;

pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); }

printf("origin is (%d%d)\n",pp->x,pp->y);

Answer:

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

Answer:

Explanation:

11

origin is(0,0) origin is(0,0) pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.

the expression i+++j is treated as (i++ + j)

Explanation:

76)

struct aaa{

Note:

70
Since structure point is globally declared x

{ }

& y are initialized as zeroes 78) main() { int i=_l_abc(10);

return z-32;

Answer:

Explanation:
are wrong. 81)

Compiler error declaration of convert and format of getc()

printf("%d\n",--i); } int _l_abc(int i) { } return(i++);

main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]);

Answer:

Explanation:

sum(num1,num2) int num1,num2; { return num1+num2; }

return(i++) it will first return i and then increments. i.e. 10 will be returned.

79)

main() {

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

Answer:

Explanation:

Compiler error. argv[1] & argv[2] are strings. They are

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

passed to the function sum without converting it to integer values. # include <stdio.h> int one_d[]={1,2,3}; main() {

Answer:

Explanation:

0001...0002...0004 ++ operator when applied to pointers

int *ptr; ptr=one_d; ptr+=3;

increments address according to their corresponding data-types. 80) main() { char c=' ',x,convert(z); getc(c); x=convert(c); } convert(z)

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

Answer:

Explanation:

garbage value

if((c>='a') && (c<='z')) printf("%c",x);

ptr pointer is pointing to out of the array range of one_d. 83) # include<stdio.h> aaa() { printf("hi"); }

bbb(){ }

71

printf("hello");

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

ccc(){ }

Answer:

printf("bye");

Explanation:

0..0 The value of i is 0. Since this information is

main()

{ int (*ptr[3])(); ptr[0]=aaa; ptr[2]=ccc; ptr[1]=bbb; ptr[2](); } 87) main() { int i;

enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. get printed.

The values of i and j remain unchanged and

Answer:

Explanation:

bye

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

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]() points to ccc.

is in effect of writing ccc(), since ptr[2]

{ _AX = 1000; }

Answer:

85)

#include<stdio.h> main() { FILE *ptr;

Explanation:

1000 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.

char i; ptr=fopen("zzz.c","r");

while((i=fgetch(ptr))!=EOF) } printf("%c",i); 88) int i; main(){

Answer:
loop

contents of zzz.c followed by an infinite

int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) } printf("%d--",t--);

Explanation:

The condition is checked against EOF, it should be checked against NULL.

// If the inputs are 0,1,2,3 find the o/p

Answer:

86)

main() { int i =0;j=0;

4--0 3--1 2--2

if(i && j++) printf("%d..%d",i++,j);

Explanation:

Let us assume some x= scanf("%d",&i)-t the values during execution

will be, i 0 1 2

72
x

4 3 2 89) main(){

-4 -2 0

Answer:

Explanation:
a pointer.

*k = &a The argument of the function is a pointer to

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello");

92) What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */

Answer:

Explanation:

hello The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated

} ii. int abc(a,b) { }

int a; float b; /* some code*/

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;

Answer:

i. ANSI C notation ii. Kernighan & Ritche notation

93)

for(i=1;i>-2;i--) printf("c aptitude");

main() {

char *p; p="%d\n"; p++; p++; printf(p-2,300); }

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 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); 94)

Answer:

Explanation:

300 The pointer points to % since it is

such that the address of

incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed. main(){

char a[100];

a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a);

void fun(int **k) {

abc(char a[]){ a++; printf("%c",*a); a++;

int a =0; /* add a stmt here*/

printf("%c",*a);

73

if(--i){

Explanation:

main();

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.

printf("%d ",i);

Answer:

95)

func(a,b) int a,b; {

Explanation:

0000

memory for I will be allocated for only once, as it return( a= (a==b) );

The variable "I" is declared as static, hence

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.

} main() {

int process(),func(); ",process(func,3,6)); } printf("The value of process is %d !\n 97)

void main() { int k=ret(sizeof(float));

process(pf,val1,val2) int (*pf) (); int val1,val2; { return((*pf) (val1,val2));

} {

printf("\n here value is %d",++k);

int ret(int ret) ret += 2.5;

Answer:

Explanation:

The value if process is 0 ! The function 'process' has 3 parameters - 1,

return(ret);

Answer:

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

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

Explanation:

Here value is 7

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;

Answer:

here in 3 6

Explanation:

74

string, whose length will be counted from 0 till the

The char array 'a' will hold the initialized

indirection on type void*.

Compiler

Error.

We

cannot

apply

null character. Hence the 'I' will hold the value equal the 6 will be printed. 99) void main() {

Explanation:

to 5, after the pre-increment in the printf statement,

Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void pointers are normally used for, 1. Passing functions pointers. generic and returning pointers

such

to

unsigned giveit=-1; int gotit; printf("%u ",++giveit);

2. 3.

As a intermediate pointer type.

Used when the exact pointer type time.

printf("%u \n",gotit=--giveit); 102) void main() {

will be known at a later point of

Answer:

Explanation:
100) void main() {

0 65535

int i=i++,j=j++,k=k++; }

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

int i;

Answer:

char a[]="\0";

if(printf("%s\n",a)) printf("Ok here \n"); else } printf("Forget it\n");

Explanation: An identifier is available to use in program code from the point of its declaration.

Garbage values.

So expressions such as i = i++ are valid statements. The i, j and k are automatic value. Garbage in is garbage out (GIGO).

Answer:

variables and so they contain some garbage

Explanation:

Ok here Printf will return how many printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed. 103)

characters does it print. Hence

void main() { static int i=i++, j=j++, k=k++; printf(i = %d j = %d k = %d, i, j, k);

101)

void main() { void *v;

Answer:

Explanation:
by default. 104)

i=1j=1k=1 Since static variables are initialized to zero

int integer=2; int *i=&integer; v=i; } printf("%d",(int*)*v);

void main() { while(1){

Answer:

if(printf("%d",printf("%d"))) break;

else }

75
continue;

free code. 106)

Thumb Rule: Check all control paths to write bug

Answer:

main() { int a[10];

Explanation:

Garbage values 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

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

Answer:

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)

Explanation:

simple as 1 + 3 = 4 ! 107)

*a and -*a cancels out. The result is as

#define prod(a,b) a*b main() {

printf("%u ",i);

int x=3,y=4; printf("%d",prod(x+2,y-1));

Answer:

Answer:

Explanation:

10 9 8 7 6 5 4 3 2 1 0 65535 65534.. Since i is an unsigned integer it can never

Explanation:

10

The macro expands and evaluates to as: x+2*y-1 => x+(2*y)-1 => 10

become negative. So the expression i-- >=0

will always be true, leading to an infinite loop. 105) #include<conio.h> main() {

108)

main() { unsigned int i=65000; while(i++!=0); printf("%d",i);

int x,y=2,z,a;

Answer:

if(x=y%2) z=2; a=2; }

Explanation:

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

Note

statement. When the value of i becomes 0 it

the

semicolon

after

the

while

Answer:

comes out of while loop. Due to postincrement on i the value of i while printing is 1. 109) main() { int i=0;

Explanation:

Garbage-value 0 The value of y%2 is 0. This value is assigned other words if(0) and so z

to x. The condition reduces to if (x) or in uninitialized.

goes

while(+(+i--)!=0) i-=i++;

printf("%d",i);

76

Answer:

Explanation:

Compiler error: undeclared function write Pascal keyword doesnt mean that pascal

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 post-decrement operator. 113) main() { 111)

-1

code can be used. It means that the function follows functions.

Pascal argument passing mechanism in calling the

loop. The value 1 is printed due to the

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

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

} {

main() int i=10; f(i++,i++,i++);

printf("%lf\n",fmod(f,g));

Answer:

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

Line no 5: Error: Lvalue required Line no 6: Cannot apply leftshift to float Line no 7: Cannot apply mod to float

Explanation:

Answer:

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;

Enumeration constants cannot be modified,

10 11 12 13 12 11 10 13 Pascal argument passing mechanism forces

Explanation:

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

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

Answer:

Explanation

-128 Notice the semicolon at the end of the for loop. THe initial value of

Compiler error: unknown type integer

the i is set to 0. The inner loop

77

executes to increment the value from 0 to 127 (the positive range negative value of -128. of char) and then it rotates to the condition in the for loop fails and prints the current value of i that is -128. 113) main()

implementation dependent behavior. But behavior. 115) Is

You can write programs that have

dont write programs that depend on such

The

so comes out of the for loop. It

declaration/definition. Find what does it mean? int (*x)[10];

the

following

statement

Answer

Definition.

unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i);

integers.

x is a pointer to array of(size 10)

Answer

meaning of this definition.

Apply clock-wise rule to find the

infinite loop The difference between the previous question and this one is that the char is declared to be unsigned. So the i++ can never yield negative value and i>=0 never becomes false so that it can come out of the for loop. 114) main() { char i=0; for(;i>=0;i++) ;

Explanation

116). What is the output for the program given below typedef enum errorType{warning, error,

exception,}error;

main() {

error g1; g1=1;

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

Compiler declaration for error

Answer

printf("%d",g1);

error:

Multiple

Answer:
dependent.

Explanation

Behavior

is

implementation

The name error is used in the two meanings. One means that it is a

Explanation:

signed/unsigned implementation

The

detail

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:

dependent.

by

if

the

default If

char

the

is

is

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 error is used: the meaning of error to know in what sense error g1;

case?

// which error it refers in each When the compiler can distinguish between usages then it will not issue error

g1=error;

(in pure technical terms, names can only be overloaded in different namespaces). declaration, exception,}

78

Note: the extra comma in the


enum errorType{warning, error,

concept behind. In real programming dont use such

This code is given here to just explain the

overloading of names. It reduces the readability of the code. Possible doesnt mean that we should use it!

is not an error. An extra comma is valid and is provided convenience. just for

programmers

118)

#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing);

exception;}error;

117)

typedef struct error{int warning, error, main() error g1; g1.error =1; } printf("%d",g1.error);

Answer:
some

Compiler error : undefined symbol

Answer Explanation

Explanation:

This is a very simple example for

conditional compilation. The name

distinguishable by the compiler at any instance, so valid (they are in different namespaces). error, exception;}error; This error can be used only by preceding the error by struct kayword as in: struct error someError;

The three usages of name errors can be

something is not already known to the compiler making the declaration int some = 0; source code. 119) effectively

Typedef struct error{int warning,

removed

from

the

typedef struct error{int warning,

#if something == 0 int some=0; #endif main() { int thing = 0;

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

error, exception;}error;

typedef struct error{int warning,

printf("%d %d\n", some ,thing);

This can be used to define variables without using the preceding struct keyword as in: Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid. Note error g1;

Answer

Explanation

00 This 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.

79

121) void main() { if(~0 == (unsigned int)-1)

120). What is the output for the following program main() int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* }

printf(You can answer this if you know how values are represented in memory); Answer

arr2D == arr2D[0])) );

You can answer this if you know how values are represented in memory Explanation ~ (tilde operator or bit-wise negation operator) operates on 0 to produce all ones to fill the space for an integer. 1 is represented in unsigned value as all 1s and so both are equal. 122) int swap(int *a,int *b) {

Answer

Explanation

This is due to the close relation dimensional arrays are made up of (N-1) dimensional arrays. arr2D is made up of a 3 single

between the arrays and pointers. N

arrays that contains 3 integers each .

arr2D arr2D[1] arr2D[2] arr2D[3]


Answer

*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);

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

Explanation This is one way of swapping two values. Simple checking will help understand this. main()

x = 20 y = 10

123)

*(arr2D + 0), adding a zero doesnt

{ char *p = ayqm; }

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.

printf(%c,++*(p++)); Answer:

124)

main() { int i=5;

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

Answer:
function main

80
Compiler error: Lvalue required in

also get initialized with the addresses of the 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)

functions bbb and ccc. Since ptr[2] contains

Explanation:

to operate an lvalue is required. 125) main() {

++i yields an rvalue. For postfix ++

char *p = ayqm; char c; c = ++*p++;

main() {

int i=5; }

printf(%d,i=++i ==6);

printf(%c,c);

Answer:

Answer:

Explanation:

Explanation:

There is no difference between the expression ++*(p++) and ++*p++.

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.

Parenthesis just works as a visual clue for the reader to see which expression is first evaluated. 126) 128) main() {

int aaa() {printf(Hi);} int bbb(){printf(hello);} iny ccc(){printf(bye);} main()

char p[ ]="%d\n"; p[1] = 'c'; printf(p,65);

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

Answer:

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.

Answer:

Explanation:

bye

129)

void ( * abc( int, void ( *def) () ) ) (); Answer::

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

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.

81
130) main() { while (strcmp(some,some\0)) }

As

operators hand

we

know

hence it cannot appear on the left operation. 133) void main() { int *mptr, *cptr; side of an

return

that

rvalues

increment and

printf(Strings are not equal\n);

assignment

Answer:

Explanation:

No output Ending the string constant with \0

explicitly makes no difference. So some

mptr = (int*)malloc(sizeof(int)); printf(%d,*mptr); printf(%d,*cptr); int *cptr = (int*)calloc(sizeof(int),1); }

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};

Answer:

Explanation:

garbage-value 0 The memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros.

while (strcmp(str1,str2)) printf(Strings are not equal\n);

Answer:

134)

void main() { static int i;

Strings are not equal Strings are not equal . If a string constant is initialized explicitly with characters, \0 is not appended

Explanation:

while(i<=10) (i>2)?i++:i--; }

printf(%d, i);

automatically to the string. Since str1 doesnt 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;

Answer:

Explanation:

32767 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.

for (;i++=0;) printf(%d,i);

135)

main() {

Answer:

int i=10,j=20;

Explanation:

Compiler Error: Lvalue required.

j = i, j?(i,j)?i:j:j; }

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

Answer:

82
10 10 The Ternary operator ( ? : ) is equivalent for if(i,j) { 138) main() {

(j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.

Explanation:

if-then-else statement. So the question can be written as:

int i=4,j=7;

if(i,j) j = i; else } j = j;

j = j || i++ && printf("YOU CAN"); } printf("%d %d", i, j);

Answer:

else

j = j;

136)

1. const char *a;

Explanation: The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to
value is 1. Because it is followed by || and

41

2. char* const a; 3. char const *a;

zero itself means that the expressions truth

-Differentiate the above declarations.

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.

Answer:

1. 'const' applies to char * rather than 'a' ( pointer to a constant char ) *a='F' a="Hi" : illegal : legal

Similarly when && operator is involved in an expression, when any of the operands

become false, the whole expressions truth value becomes false and hence the

2. 'const' applies to 'a' rather than to the value of a (constant pointer to char ) *a='F' a="Hi" : legal : illegal

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

remaining expression will not be evaluated.

3. Same as 1. 137) main() {

int i=5,j=10;

i=i&=j&&10; }

Answer:

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

Answer:

Rule to Remember: & (address of ) operator cannot be applied on register variables.


140) main() { float i=1.5; switch(i)

Compier Error: '&' on register variable

Explanation:

1 10 The expression can be written as i=(i&=(j&&10)); The inner expression

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

char a[ ]="GOOD"; strlen(p) =

printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p)); sizeof(a), strlen(a)); } %d", sizeof(p),

sizeof(*p),

printf("\n sizeof(a) = %d, strlen(a) = %d",

Answer:
integral

Compiler Error: switch expression not

Answer:

Explanation: Switch statements can be applied only to integral types.


141) main() { extern i; printf("%d\n",i); { int i=20;

sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4 sizeof(a) = 5, strlen(a) = 4

Explanation:

sizeof(p) => sizeof(char*) => 2 sizeof(*p) => sizeof(char) => 1 Similarly,

sizeof(a) => size of the character array => 5

When sizeof operator is applied to an array it returns the sizeof the array and it is not
the same as the sizeof the pointer variable. Here the sizeof(a) where a is the character

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

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)

Answer:

Explanation:

Linker Error : Unresolved external symbol i The identifier i is available in the inner resolving it.

block and so using extern has no use in

#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(The dimension of the array is %d,

142)

main() {

int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5;

DIM(arr, int)); }

Answer:

printf("\n%d %d %d",a,*f1,*f2);

Explanation:

10

Answer:

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.

Explanation:

16 16 16 f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a. 145)

int DIM(int array[]) { } {

return sizeof(array)/sizeof(int ); main()

143)

main() { char *p="GOOD";

int arr[10];

DIM(arr)); }

printf(The dimension of the array is %d,

84
} { }

printf("x=%d y=%d",x,y);

Answer:

void swap(int *a, int *b) *a ^= *b, *b ^= *a, *a ^= *b;

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

Answer:

Explanation:

x=10 y=8 Using ^ like this is a way to swap two variables variable and that too in a single statement. without using a

temporary

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 doesnt issue a compiler

error by the call swap(&x,&y); that has two

arguments. This convention is historically due to preANSI 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()

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

int *a, int *b {

Answer:

1 2 3 4 5 6 7 8 9

1 4 7 2 5 8 3 6 9

1 2 3 4 5 6 7 8 9

1 4 7 2 5 8 3 6 9 *((char*)iPtr+1) ); } 148) main() {

} 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.

*a ^= *b, *b ^= *a, *a ^= *b;

int i = 257; printf("%d

int *iPtr = &i;

Explanation:

%d",

*((char*)iPtr),

*(*(p+i)+j) is equivalent to p[i][j].

147)

main() { void swap();

Answer:

Explanation:

11

int x=10,y=8; swap(&x,&y);

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; printf("%d

85

char * ptr = str; while (*ptr++)

char least = 127; least = (*ptr<least ) ?*ptr :least;

int *iPtr = &i; *((char*)iPtr+1) ); }

} %d", *((char*)iPtr),

printf("%d",least);

Answer:

Explanation:

Answer:

After ptr reaches the end of the string the str is less than that of least. So the value of least finally is 0.

Explanation:
in

21

value pointed by str is \0. So the value of

The integer value 257 can be represented binary as, 00000001

Remember that the INTEL machines are

00000001.

152)

Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

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
small-endian machines. in memory as: 00000001 00000010. 150) main() { int i=300;

Answer:

(char*(*)( )) (*ptr[N])( );

153)

main() { struct student {

char *ptr = &i; *++ptr=2; printf("%d",i);

}stud;

char name[30]; struct date dob;

struct date {

Answer:

Explanation:

556 The integer value 300 in binary notation is: 00000001 00101100. It is memory (small-endian) as:

scanf("%s%d%d%d", &student.dob.day, &student.dob.year);

int day,month,year; };

stud.rollno,

&student.dob.month,

00000001. Result of the expression *++ptr = 2 makes the memory representation as: 00101100 00000010. So the integer corresponding to it 00101100 => 556. 151) #include <stdio.h> main() { is 00000010

stored in 00101100

Answer:

Explanation:

Compiler Error: Undefined structure date Inside the struct definition of student the member of type struct date is given. The compiler doesnt have the definition of date in C in this case) so it issues an error.

structure (forward reference is not allowed

char * str = "hello";

154)

main() {

struct date; {

86

struct student char name[30]; struct date dob; struct date { int day,month,year; stud.rollno, 156)

feof(fp)

comes out of the while loop.

becomes

false,

hence

Is there any difference between the two declarations, 1. 2. int foo(int *arr[]) and int foo(int *arr[2]) No

}stud;

Answer:

scanf("%s%d%d%d", &student.dob.day, } &student.dob.year);

};

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.

&student.dob.month,

Answer:

Explanation:

Compiler Error: Undefined structure date Only declaration of struct date is available inside the structure definition of student

157)

What is the subtle error in the following code void fun(int n, int arr[]) { int *p=0; int i=0;

segment?

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

while(i++<n)

p = &arr[i]; *p = 0;

Answer & Explanation:

struct student {

If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0

char name[30], rollno[6]; }stud; while(!feof(fp)) {

FILE *fp = fopen(somefile.dat,r);

may result in problem (may rise to runtime error NULL pointer program). 158) What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); } return s;

assignment and terminate the

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

Answer & Explanation:

reading EOF (and returning EOF).

assert macro should be used for debugging and finding out bugs. The check s != NULL is for error/exception handling and for that assert shouldnt be used. A plain if and the

So it prints the last record again. After this only the condition

corresponding remedy statement has to be given. 159)

87
macro");

printf("This statement becomes else for if in assert }

statement?

What is the hidden bug with the following assert(val++ != 0); 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.

Answer:

Answer & Explanation:

Explanation:

No output

The else part in which the printf is there becomes the else for if in the assert macro. Hence nothing is printed. if statement, The solution is to use conditional operator instead of

#define assert(cond) ((cond)?(0): (fprintf (stderr,

Rule to Remember: Dont use expressions that have side-effects in assert statements.
160) void main() {

"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)) \

pointed by i; }

int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location

Answer:

Explanation:

Undefined behavior The second statement results in undefined

(fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) \ }

behavior because it points to some location whose value may not be available for modification. This type of pointer in which

162)

Is the following code legal? struct a { int x;

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 __FILE__,__LINE__), abort())

struct a b;

} Answer:

\n",#cond,\

Explanation:

No

member that is of the same

Is it not legal for a structure to contain a type as in this case. Because this will cause

void main() { int i = 10; if(i==0) else 163)

the structure declaration to be recursive without end. Is the following code legal? struct a {

assert(i < 100);

int x;

Answer:

struct a *b;

88
{

struct a int x;

Explanation:

Yes. *b is a pointer to type struct a and so is pointer to a structure even before the size of the structure

}; }

aType *b;

legal. The compiler knows, the size of the

Answer:

is determined(as you know the pointer to

Explanation:

No

any type is of same size). This type of structures is known as self-referencing structure. 164)

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 *));

Is the following code legal? typedef struct a {

Answer:

}aType

int x; aType *b;

Explanation:

No

printf(sizeof(struct sizeof(struct unknown *)); }

printf(sizeof (int *) = %d \n, sizeof(int *)); printf(sizeof (double *) = %d \n, sizeof(double *)); unknown *) = %d

\n,

The typename aType is not known at the

Answer :

point of declaring the structure (forward references are not made for typedefs). 165) Is the following code legal? typedef struct a aType; struct a { 168)

sizeof (void *) = 2

sizeof (int *) = 2 sizeof (double *) = 2

Explanation:

sizeof(struct unknown *) = 2 The pointer to any type is of same size.

int x; aType *b;

char inputString[100] = {0};

To get string input from the keyboard which one of

};

Answer:

the following is better? 1) gets(inputString)

Explanation:

Yes

Answer & Explanation:


The second

2) fgets(inputString, sizeof(inputString), fp) one is better because

The typename aType is known at the point already typedefined.

of declaring the structure, because it is

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 operation as gets but is safe. 169)

166)

Is the following code legal? void main() {

fgets is used with stdin performs the same

typedef struct a aType; aType someVariable;

Which version do you prefer of the following two,

curt one

1) printf(%s,str); 2) printf(str);

// or the more

89

The char type may be signed or unsigned

by default. If it is signed then ch++ is executed after ch reaches 127 and rotates than 127. 172) Is this code legal? back to -128. Thus ch is always smaller

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 *ptr; ptr = (int *) 0x400;

Answer:

int *ip= &i, *jp = &j; int k = *ip/*jp; printf(%d,k);

Explanation:

Yes

The pointer ptr will point at the integer in the memory location 0x400. 173) main() { char a[4]="HELLO"; printf("%s",a);

Answer:

comment started in line 5.

Compiler Error: Unexpected end of file in

Explanation:

The programmer intended to divide two integers, but by the maximum compiler treats the operator sequence / and * as /* which happens to be the starting of comment. To force what is intended by the programmer, munch rule, the

Answer:

Explanation:

Compiler error: Too many initializers The array a is of size 4 but the string constant requires 6 bytes to get stored.

separating / and * //or

int k = *ip/ *jp; // give space explicity

174)

main() { char a[4]="HELL"; printf("%s",a);

int k = *ip/(*jp);

// put braces to force the intention will solve the problem. 171) void main() { char ch;

Answer:

Explanation:

HELL%@!~@!@???@~~! 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 garbage values till it accidentally comes across a NULL character. HELL correctly and continues to print

for(ch=0;ch<=127;ch++) printf(%c %d \n, ch, ch); }

Answer:

Explanation:

Implementaion dependent

175)

main() { int a=10,*j; void *k;

j=k=&a; j++; k++; }

90

output correctly because the character constants are stored in to dangling pointers. 179)

The program suffers no problem and gives the

printf("\n %u %u ",j,k);

code/data area and not allocated in stack, so this doesnt lead

Answer:
pointer

Compiler error: Cannot increment a void

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());

Explanation:

Void pointers are generic pointers and they can be used only when the type is not known and as an intermediate address

storage type. 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; Answer:

printf("%d",i);

const

volatile

unsigned

i=30;

} } }

Explanation:

Garbage values. Both the functions suffer from the problem of

printf("%d",i);

printf("%d",i);

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

int i; 177) list.

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.

Printf can be implemented by using __________

Answer:

178) char *someFun() { return temp; } int main() { }

Variable length argument lists

char *temp = string constant";

puts(someFun()); Answer:

Explanation:

string constant

C++ Aptitude and OOPS


C++ Aptitude and OOPS

91
Explanation:

Note :

and Microsoft VC++ 6.0 compilers. It is assumed that, Programs

All the programs are tested under Turbo C++ 3.0, 4.5

destructor of the object is called when the control returns ptr that has been freed.The solution is to pass the Sample object by reference to SomeFunc:

As the object is passed by value to SomeFunc the

from the function. So when PrintVal is called it meets up with

environment, The underlying machine is an x86 based Program is compiled using Turbo C/C++ system,

run

under

Windows

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

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

compiler.

1) class Sample

{ public:

Answer:

member function when it is called? this pointer

int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr;

3) class base { public: int bval;

base(){ bval=0;} }; class deri:public base { public: int dval;

} void PrintVal()

{ cout << "The value is " << *ptr; } }; void SomeFunc(Sample x)

deri(){ dval=1;} }; void SomeFunc(base *arr,int size) { for(int i=0; i<size; i++,arr++) cout<<endl; } cout<<arr->bval;

{ cout << "Say i am in someFunc " << endl; } { int main() Sample s1= 10; SomeFunc(s1); s1.PrintVal(); }

int main() { base BaseArr[5];

Answer:

Say i am in someFunc Null pointer assignment(Run-time error)

SomeFunc(BaseArr,5); deri DeriArr[5]; SomeFunc(DeriArr,5);

92

Explanation:

Answer:

00000 01010

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: };

As we have seen in the previous case, SomeFunc

Explanation:

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

The function SomeFunc expects two arguments.The

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 nothing about this and just treats the pointer as an array of

virtual void baseFun(){ cout<<"from base"<<endl;}

class deri:public base { public: };

the address is sent to the function. SomeFunc() knows 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 {

void baseFun(){ cout<< "from derived"<<endl;}

void SomeFunc(base *baseObj) { } baseObj->baseFun();

int main()

public: void baseFun(){ cout<<"from base"<<endl;} };

{ base baseObject;

SomeFunc(&baseObject); deri deriObject; SomeFunc(&deriObject); }

class deri:public base {

public: void baseFun(){ cout<< "from derived"<<endl;} };

Answer:

void SomeFunc(base *baseObj) { } { baseObj->baseFun();

Explanation:

from base from derived

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.

int main() base baseObject;

void main() { int a, *pa, &ra; pa = &a; ra = a; } cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;

SomeFunc(&baseObject); deri deriObject; SomeFunc(&deriObject); }

Answer:

from base from base

/* Answer :

Explanation : main

Compiler Error: 'ra',reference must be initialized Pointers are different from references. One of the

93

{ }

cout<<"some's destructor"<<endl;

differences is that the pointers can be both initialized and assigned, an error. */ whereas references can only be initialized. So this code issues

};

void main() { some s; s.~some();

const int size = 5; { }

void print(int *ptr) cout<<ptr[0];

/*

Answer:

Explanation:

some's destructor some's destructor Destructors can be called explicitly. Here 's.~some()'

void print(int ptr[size]) { } cout<<ptr[0];

explicitly calls the

destructor of 's'. When main() returns, destructor of s is called again, hence the result. */

void main() { int a[size] = {1,2,3,4,5}; int *b = new int(size); print(a); } /* print(b);

#include <iostream.h> class fig2d {

int dim1; int dim2;

Answer:

has a body

Compiler Error : function 'void print(int *)' already

public:

fig2d() { dim1=5; dim2=6;} virtual void operator<<(ostream & rhs);

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

};

void fig2d::operator<<(ostream &rhs) { } rhs <<this->dim1<<" "<<this->dim2<<" ";

as function arguments. In other words, both the functoins have the same signature and so cannot be overloaded. */

/*class fig3d : public fig2d { int dim3; fig3d() { dim3=7;} virtual void operator<<(ostream &rhs);

class some{ public: ~some()

public:

}; {

94
}

void fig3d::operator<<(ostream &rhs) fig2d::operator <<(rhs); rhs<<this->dim3;

return false;

void main(){

*/ void main() { fig2d obj1; fig3d obj2; obj1 << cout; obj2 << cout;

opOverload a1, a2; a1= =a2;

} Answer :

//

Explanation :

Runtime Error: Stack Overflow

// } /*

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.

Answer :

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

56

class complex{

public:

double re; double im; complex() : re(1),im(0.5) {} bool operator==(complex &rhs); operator int(){}

};

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 complex::operator == (complex &rhs){ if((this->re == rhs.re) && (this->im == rhs.im)) else } int main(){ complex c1; } cout<< c1; return true;

return false;

bool operator==(opOverload temp);

bool opOverload::operator==(opOverload temp){ if(*this == temp ){ return true;

Answer : Garbage value Explanation:

cout<<"The both are same objects\n";

else{

using output

The programmer wishes to print the complex object

cout<<"The both are different\n";

re-direction operator,which he has not defined for his conversion function prints

95
main

lass.But the compiler instead of giving an error sees the and converts the user defined object to standard object and some garbage value.

Pointers are different from references. One of the

differences is that the pointers can be both initialized and assigned, an error. whereas references can only be initialized. So this code issues

class complex{

double re;

[Q001]. Determine which of the following are VALID identifiers. If invalid, state the reason. (a) sample1 (d) return (f) variable Ans. (b) 5sample (e) #fine

public:

double im; complex() : re(0),im(0) {} complex(double n) { re=n,im=n;};

(c) data_7

complex(int m,int n) { re=m,im=n;} }; void main(){

(i) _val (j) name_and_age (a) VALID

(g) 91-080-100 (h) name & age

void print() { cout<<re; cout<<im;}

letter or an underscore (c) VALID

(b) Invalid, since an identifier must begin with a

complex c3; double i=5; c3 = i; c3.print();

letter or an underscore (f) VALID

(d) Invalid, since return is a reserved word (e) Invalid, since an identifier must begin with a

} Answer:

letter or an underscore (h) Invalid, since blank spaces are not allowed (i) VALID (j) VALID

(g) Invalid, since an identifier must begin with a

Explanation: Though no operator= function taking complex,

5,5

__________________________________________________ _______________________________________________ [Q002]. Determine which of the following are VALID character constants. If invalid, state the reason. (a) 'y' (b) '\r' (c) 'Y' (e) '/r' (f) 'word' Ans.

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.

(d) '@'

void main() {

int a, *pa, &ra; pa = &a; ra = a;

(j) '\'' (k) ' ' (a) VALID (b) VALID (c) VALID

(g) '\0' (h) '\?' (i) '\065'

} Answer :

cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;

(e) Invalid, since escape sequences must be written with a backward slash (i.e. \) of multiple characters

(d) VALID

(f) Invalid, since a character constant cannot consist (g) VALID (null-character escape sequence) (h) VALID (i) VALID (Octal escape sequence)

Explanation :

Compiler Error: 'ra',reference must be initialized

(j) VALID

96

__________________________________________________ _______________________________________________

(k) VALID

(i) VALID

intended as an octal constant. (k) VALID (l) VALID

(j) Invalid, since illegal characters (9, C, F), if

[Q003]. Determine which of the following are VALID string constants. If invalid, state the reason. (a) 'Hi Friends' (c) "Qualification (d) "4325.76e-8" (g) "" Ans. (b) "abc,def,ghi" (e) "Don\'t sleep" (h) " "

__________________________________________________ _______________________________________________ [Q005]. Determine which of the following floating-point constants are VALID for the quantity (5 * 100000). (a) 500000 (d) 5e5 (f) 500E3 (j) 5.0E+5 Ans. (k) (b) 0.5e6 (e) 5e+5 (c) 5E5

(f) "He said, "You\'re great"

in double quotation marks (b) VALID

(i) "Rs.100/-" (a) Invalid, since a string constant must be enclosed

(g) .5E6 (h) 50e4 (i) 50.E+4 (l) None of these

(k) All of the above

(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 sequences. (g) VALID

cannot be expressed without the escape

[Q006]. What will be the output of the following program : void main() printf("%f",123.); } (c)123.00 {

__________________________________________________ _______________________________________________

(h) VALID (i) VALID

(a)123

Ans. (d)

(b)Compile-Time Error (d)123.000000

[Q004]. Determine which of the following numerical values are valid constants. If a constant is valid, specify whether it is integer or real. Also, specify the base for each valid integer constant. (a) 10,500 (b) 080 (d) 5.6e7 (f) 0.2e-0.3 (c) 0.007 (h) 0xaf9s82

__________________________________________________ _______________________________________________ [Q007]. What will be the output of the following program : void main() { printf("%d",sizeof(integer)); (a)2 } (b)Compile-Time Error

(i) 0XABCDEFL Ans. (k) 87654321l (b) VALID (c) VALID (e) VALID (f) VALID

(e) 5.6e-7 (g) 0.2e 0.3 (j) 0369CF (l) 87654321

(a) Invalid, since illegal character(,)

Ans. (b) since there is no such data type called 'integer'.

(c)4

(d)None of these

__________________________________________________ _______________________________________________

(d) VALID

[Q008]. What will be the output of the following program : void main() {

(g) Invalid, since illegal character(blank space) (h) Invalid, since illegal character(s)

char str[]="C For Swimmers"; printf("%d",sizeof str);

(a)14

} (c)15

97
(b)Compile-Time Error

z/=y/z==3?y/z:x*y; } printf("%d",z);

Ans. (a)--c

(d)None of these

__________________________________________________ _______________________________________________

(a)Compile-Time Error Ans. (c) (c)0

(b)2

(d)1

[Q009]. What will be the output of the following program : void main() char str[]="C For Swimmers"; } {

__________________________________________________ _______________________________________________

[Q013]. What will be the output of the following program : void main() {

printf("%d",++(sizeof(str))); (b)Compile-Time Error

(a)14 Ans. (b)

(c)15

(d)None of these

(a)5 10 22 Ans. (c)

printf("%d %d %d",5,!5,25 - !25); } (c)5 0 25 (b)5 5 25 (d)5 1 24

__________________________________________________ _______________________________________________

[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 (d)-14 {

__________________________________________________ _______________________________________________ [Q014]. What will be the output of the following program : int main() { int a=500,b=100,c=30,d=40,e=19;

Ans. (c) __________________________________________________ _______________________________________________

(c)-15

(a)500 100 30 40 4 (b)Run-Time Error 200 300 10 4 (d)300 -200 300 10 4

a+=b-=c*=d/=e%=5; printf("%d %d %d %d %d",a,b,c,d,e); (c)700

[Q011]. What will be the output of the following program : void main() {

Ans. (d) __________________________________________________ _______________________________________________

(a)100

printf("%d",!(100==100)+1); } (c)1 (b)0 (d)2

[Q015]. What will be the output of the following program : void main() {

int a=500,b=100,c=30,d=40,e=19; b) : (c == d)))

Ans. (c)

if ((((a > b) ? c : d) >= e) && !((e <= d) ? ((a / 5) == printf("Success"); printf("Failure"); (b)VALID : Failure

__________________________________________________ _______________________________________________ [Q012]. What will be the output of the following program : { int x=5,y=6,z=2; void main()

else }

(a)VALID : Success Ans. (b)

(c)INVALID

(d)None of these

__________________________________________________ _______________________________________________

98

+12345 -13579 -24680 -2222 5555

+123456789

[Q016]. What will be the output of the following program : void main() {

00012345 -0013579 -0002222 00005555

int a=1,b=2,c=3,d=4;

-0024680 000000123456789 __________________________________________________ _______________________________________________ [Q018]. What will be the output of the following program : { 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); void main()

(a)1 Ans. (a)

printf("%d",!a?b?!c:!d:a); } (d)4 (b)2

(c)3

__________________________________________________ _______________________________________________ [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;

%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%d %d %d %ld %d %u",i,j,k,ix,sx,ux); printf("\n\n%3d %3d %3d\n%3ld %3d

Ans. 12345 abcd9 77777

printf("\n%08d %#8x %#8o",i,j,k); }

12345 abcd9 77777 12345 abcd9 77777

12345 abcd9 77777 +12345 abcd9 77777

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); %08u",i,j,k,ix,sx,ux); }

__________________________________________________ _______________________________________________ [Q019]. What will be the output of the following program : void main() { char c1='A', c2='B', c3='C';

00012345 0xabcd9 077777

printf("\n\n%08d %08d\n%08d %015ld\n%08d

Ans. 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680

printf("%c %c %c",c1,c2,c3); printf("\n%c%c%c",c1,c2,c3);

123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -2222 5555

printf("\n%3c %3c %3c",c1,c2,c3); printf("\n%3c%3c%3c",c1,c2,c3); } Ans. A B C ABC printf("\nc1=%c c2=%c c3=%c",c1,c2,c3);

-24680 123456789

A B C A B C

c1=A c2=B c3=C

__________________________________________________ _______________________________________________

99

char str[]="C For Swimmers"; printf("%s",str); printf("\n%.5s",str);

[Q020]. What will be the output of the following program : void main() {

printf("\n%8.*s",5,str); }

printf("\n%-10s %.1s",str+6,str);

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

Ans. C For Swimmers C For C For

printf("\n%8.4f %8.4f %8.4f",a,b,c); printf("\n%e %e %e",a,b,c); printf("\n%3e %3e %3e",a,b,c);

printf("\n%8.3f %8.3f %8.3f",a,b,c);

__________________________________________________ _______________________________________________

Swimmers C

printf("\n%12e %12e %12e",a,b,c); printf("\n%-8f %-8f %-8f",a,b,c);

[Q022]. What will be the output of the following program : void main() {

printf("\n%8.2e %8.2e %8.2e",a,b,c); printf("\n%+8f %+8f %+8f",a,b,c); printf("\n%08f %08f %08f",a,b,c);

int a=1,b=2,c=3;

printf("\n%#8f %#8f %#8f",a,b,c); printf("\n%g %g %g",a,b,c); } printf("\n%#g %#g %#g"a,b,c);

} [NOTE : 3 values entered by the user are:100 200 300] (a)1 2 3 200 3 Ans. (d) (b)100 200 300 (d)100 300 3

scanf("%d %*d %d",&a,&b,&c); printf("a=%d b=%d c=%d",a,b,c);

(c)100

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

__________________________________________________ _______________________________________________ [Q023]. 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); }

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 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.500000 0.000500 3000.000000 __________________________________________________ _______________________________________________ 2.5 0.0005 3000

[NOTE : THE USER INPUT IS:Dear Friends, What is the output?] (a)Compile-Time Error Ans. (b) (c)What is the output? (b)Dear Friends (d)None of these

__________________________________________________ _______________________________________________ [Q024]. What will be the output of the following program : void main() { char a,b,c;

[Q021]. What will be the output of the following program : void main() {

scanf("%c%c%c",&a,&b,&c); }

100

printf("a=%c b=%c c=%c",a,b,c);

[NOTE : THE USER INPUT IS:CMeansSea Ocean Vast] (a)C O V (b)C Means Sea Ocean Vas Ans. (b) (d)None of these

(c)C

[NOTE : THE USER INPUT IS :A B C] (a)a=A b=B c=C Ans. (b) (c)a=A b= c=C

(b)a=A b= c=B

(d)None of these

__________________________________________________ _______________________________________________

__________________________________________________ _______________________________________________ [Q025]. What will be the output of the following program : void main() { int i=1;

[Q028]. What will be the output of the following program : void main() { int a,b,c;

float f=2.25;

printf("Sum=%d",a+b+c); } 544] (a)Sum=480 Ans. (a)

scanf("%1d %2d %3d",&a,&b,&c);

scanf("%d a %f",&i,&f); } [NOTE : THE USER INPUT IS:5 5.75] (a)1 2.25 (c)5 2.25 Ans. (c) printf("%d %.2f",i,f);

[NOTE : THE USER INPUT IS :123456 44 (b)Sum=594

(c)Sum=589

(d)None of these

(b)5 5.75 (d)None of these

__________________________________________________ _______________________________________________ [Q029]. What happens when the following program is executed : void main() {

__________________________________________________ _______________________________________________ [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);

(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 these Ans. (c)

scanf("%[^1234567890\n]",line); }

char line[80];

[NOTE : THE USER INPUT IS :ABC DEF GHI] (a)a=ABC b=DEF c=GHI (b)a=A b=B c=C Ans. (b) (c)a=A b=D c=G

(d)None of these

__________________________________________________ _______________________________________________

__________________________________________________ _______________________________________________ [Q030]. What happens when the following program is executed : void main() {

[Q027]. What will be the output of the following program : void main() { char a[80],b[80],c[80];

printf("%s %s %s",a,b,c); }

scanf("%1s %5s %3s",a,b,c);

scanf("%[^*]",line); }

char line[80];

(a)Accepts the string that contains DIGITS & ALPHABETS only. only. (b)Accepts the string that contains * or asterisk characters (c)Accepts the string that contains anything other than the * or asterisk character. (d)None of these

101

__________________________________________________ ________

[Q004]. What will be the output of the following program : { void main()

Ans. (c) __________________________________________________ _______________________________________________

printf("//",5); } (b)Compile-Time Error (d)//

(a)5

[Q001]. What will be the output of the following program : void main() { }

Ans. (d) Since // is taken as string ___________

(c)/

__________________________________________________

printf();

[Q005]. What will be the output of the following program : void main() { (b)Compile-Time Error

(a)Run-Time Error

(c)No Output (d)None of these Ans. (b) Since there must be enough arguments for the

format. __________________________________________________ ___

(a)8

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

Ans. (c) Since excess arguments (more than required by the

(b)Compile-Time Error (d)None of these

[Q002]. What will be the output of the following program : void main() {

format) are merely ignored. __________________________________________________ ________

} (a)Run-Time Error

printf(NULL);

[Q006]. What will be the output of the following program : (b)Compile-Time Error void main() {

(c)No Output (d)None of these Ans. (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() { }

(a)123

printf("%d"+0,123); }

(b)Compile-Time Error

(c)No Output (d)None of these Ans. (a) since"%d"+0 has no effect on the output operation.

__________________________________________________ ________________ [Q007]. What will be the output of the following program : { printf("%d"+1,123); } void main()-----------------doubt

printf("%%",7); (a)7 (b)Compile-Time Error (d)%%

Ans. (c) Since % is a format specifier & excess arguments (more than required by the format) are merely ignored.

(c)%

(a)123

(c)d

(d)No Output

(b)Compile-Time Error

Ans. (c) since "%d"+1 (i.e 1 or > 0) affects the program output by considering "%d" as string and ignores 123 string "%d". Where 1 refers to the index i.e. 2nd character in the array or __________________________________________________ _____________

102

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

[Q008]. What will be the output of the following program : void main() printf("%d",printf("Hi!")+printf("Bye")); (a)ByeHi!6 (b)Hi!Bye6 Error (d)None of these 'Bye' is 3+3=6 __________ } (c)Compile-Time {

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 : void main() { }

Ans. (b) Since L->R priority & the length of the strings 'Hi!' & __________________________________________________

printf("C For ") + printf("Swimmers"); (a)Compile-Time Error (b)C For Swimmers (c)Run-

[Q009]. What will be the output of the following program : void main() printf("%d",printf("Hi!")*printf("Bye")); } (b)Hi!Bye9 (d)None of these {

Time Error (d)None of these Ans. (b) It is a VALID C statement.

__________________________________________________ __________ [Q013]. What will be the output of the following program : void main() { printf("\/\*\-*\/"); }

(a)ByeHi!6 (c)Hi!Bye

Ans. (b) Since L->R priority & the length of the strings 'Hi!' &

'Bye' is 3*3=9 __________________________________________________ ______

(a)Run-Time Error (b)\/*-*\/ (d)None of these

(c)/*-*/

[Q010]. What will be the output of the following program : void main() {

Ans. (c) Since \ is an escape sequence character. Be careful while analyzing such statements. _____________

__________________________________________________

(a)0

printf("%d",printf("")+printf("")); } (d)None of these (b)No Output

Error

(c)Compile-Time

[Q014]. What will be the output of the following program : int main() { int main=7; {

Ans. (a) Since L->R priority & the length of the 2 empty

strings are : 0+0=0 __________________________________________________ __________

printf("%d",main); return main; printf("Bye"); (a)Compile-Time Error (d)7 } (b)Run-Time Error (c)7Bye }

[Q011]. What will be the output of the following program : void main() {

103
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. ______ [Q018]. What will be the output of the following program : void main() {

__________________________________________________

int val=75; }

printf("%d",val,.,.); (b)Unpredictable (c)75 (d)None

[Q015]. What will be the output of the following program : void main() main(); (a)Compile-Time Error (b)Run-Time Error (c)Infinite Loop (d)None of these } {

(a)Compile-Time Error of these

Ans. (b) Output is Unpredictable B'coz there are not enough arguments for the format. But it is a VALID C statement. __ __________________________________________________

Ans. (c) It is a VALID C statement. It is like a recursive times. (All compilers will not support)

function & the statements get executed infinite number of __________________________________________________ ___________ [Q016]. What will be the output of the following program : { printf("Work" "Hard"); void main()

[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

} (a)Work (b)Hard (c)No Output Ans. (d) Since L->R priority. First it prints the word 'Work' & then 'Hard'. (d)WorkHard

Ans. (a) Since R->L priority. The second format specifier %d is an excess argument and it is ignored.

(d)10 9

__________________________________________________ ____________ [Q020]. What will be the output of the following program : void main() { int val=5;

__________________________________________________ ____________ [Q017]. What will be the output of the following program : void main() { char str[]="%d"; int val=25; }

printf("%d %d %d %d",val,--val,++val,val--); (b)5 5 6 5 (c)4 4 5 5

} (a)3 4 6 5

(d)None of these Ans. (c) Since R->L priority. _________

printf(str,val); (c)25

__________________________________________________

(a)Compile-Time Error (b)Run-Time Error (d)None of these

Ans. (c) It is a VALID C statement. First parameter contains the format specifier & the Second parameter contains the actual value 25.

__________________________________________________ ______

104

(a)Run-Time Error

Ans. (b) Since comments /*...*/ are ignored by the compiler. _______________________________________________ [Q021]. What will be the output of the following program : void main() {

(c)Compile-Time Error

(b)10 20 200

(d)None of these

__________________________________________________

[Q024]. What will be the output of the following program : void main() {

int val=5,num; }

printf("%d",scanf("%d %d",&val,&num));

int m=10,n=20; }

/* printf("%d",m*n);

[NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively.] (a)1 (b)2 (d)None of these (c)5

(a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error (d)None of these is missing in the above program.

Ans. (c) Since COMMENT statement not ended properly i.e */ __________________________________________________ _______________________________________________

Ans. (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,(} {

[Q025]. What will be the output of the following program : void main() int val=97; "Printing..."+printf("%c",val); (b)97 (d)a (c)Compile-Time {

} (a)Printing...97 Error

y+z))); (a)40

Ans. (d) Since alphabet 'a' is the ASCII equivalent of 97. __________________________________________________ _______________________________________________

(b)30

[Q026]. What will be the output of the following program : void main() {

(c)Compile-Time Error (d)None of these Ans. (b) Since it is macro function. NOTE : Be careful while

doing such type of calculations. __________________________________________________ _______________________________________________

int val=5; val=printf("C") + printf("Skills"); printf("%d",val); (a)Skills5 }

[Q023]. What will be the output of the following program : void main() {

int m=10,n=20;

(c)Compile-Time Error (d)CSkills7 Ans. (d) VALID Since 'printf' function return the no. of bytes output. __________________________________________________ _______________________________________________

(b)C1

*/n,m*/* Compute m*n */n); }

printf("%d %d %d",m/* m-value */,/* n-value

[Q027]. What will be the output of the following program :

void main() char str[]="Test"; {

105

int val=5; {

printf("%d",5+val++); (b)5 (c)10

printf("Success"); else

if ((printf("%s",str)) == 4)

(a)Compile-Time Error

} (a)TestFailure

printf("Failure"); (b)TestSuccess

Ans. (a) Since incorrect usage of pair of braces } and {. Correct usage : Each compound statement should be enclosed within a pair of braces, i.e { and }. __________________________________________________ _______________________________________________

(d)11

Ans. (b) VALID Since 'printf' function return the no. of bytes output. __________________________________________________ _______________________________________________ [Q028]. What will be the output of the following program : { int val=5; void main()

(c)Compile-Time Error

(d)Test

Topic : Decision-making, Branching, Looping & Bit-wise operations [Q001]. What will be the output of the following program : void main() { printf("Hi!");

(a)

Error (d)None of these Ans. (a) VALID Since '*' specifies the precision (i.e. the next argument in the precision). If no precision is specified then the value itself will be the precision value. Thus it prints 5 BLANK

printf("%*d",val); } (b)5

(c)Compile-Time

(a)No Output (c)Bye

if (-1) printf("Bye"); (b)Hi!

Ans. (d) __________________________________________________ _______________________________________________

(d)Hi!Bye

SPACES & then the value 5. __________________________________________________ _______________________________________________

[Q002]. What will be the output of the following program : void main() {

[Q029]. What will be the output of the following program : void main()--------------------------doubt {

printf("Hi!"); if (0 || -1) printf("Bye"); (b)Hi!

int val=5; printf("%d5",val); (a)Compile-Time Error }

} (a)No Output Ans. (d)

(b)5 (d)

Ans. (c) __________________________________________________ _______________________________________________

(c)55

(c)Bye

(d)Hi!Bye

__________________________________________________ _______________________________________________

[Q003]. What will be the output of the following program : void main() {

[Q030]. What will be the output of the following program : void main() }

printf("Hi!"); if (!1)

(a)Compile-Time error Ans. (b) (c)Bye

printf("Bye"); (b)Hi!

106

__________________________________________________ _______________________________________________

(d)Hi!Bye

[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);

[Q004]. What will be the output of the following program : void main() { (a)0

printf("Hi!");

(a)Compile-Time error (c)Bye

if !(0) printf("Bye"); (b)Hi! (d)Hi!Bye

Ans. (b) __________________________________________________ _______________________________________________

(c)3

(b)7

(d)No Output

Ans. (a) __________________________________________________ _______________________________________________

[Q008]. What will be the output of the following program : void main() {

[Q005]. What will be the output of the following program : void main() {

unsigned val=0xffff; if (~val) printf("%d",val);

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

(a)Compile-Time error (c)0 Ans. (c)

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

(b)-1

(d)-1 0

} (a)No Output Ans. (d)

(c)Bye

(d)Hi!Bye

__________________________________________________ _______________________________________________ [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);

__________________________________________________ _______________________________________________ [Q006]. What will be the output of the following program : void main() { if (sizeof(int) && sizeof(float) && sizeof(float)/2printf("Testing"); printf("OK"); (b)OK

sizeof(int))

(a)No Output Ans. (c)

(c)0xefff

(b)0xe75f

.(d)None of these

(a)No Output Ans. (b)

__________________________________________________ (d)TestingOK _______________________________________________

(c)Testing

[Q010]. What will be the output of the following program : void main()

107

unsigned val=0xabcd; {

if (val>>16 | val<<16) printf("Success"); return;

(a)Compile-Time error Ans. (a) (c)5

(b)Run-Time error

(d)Unpredictable

__________________________________________________ _______________________________________________

(a)No Output Ans.(b)

printf("Failure"); } (c)Failure

(b)Success

[Q014]. What will be the output of the following program : void main() { auto int a=5;

(d)SuccessFailure

__________________________________________________ _______________________________________________ [Q011]. What will be the output of the following program : void main() { unsigned x=0xf880,y=5,z;

} (a)Compile-Time error Ans. (c) (c)5

printf("%d",a); (b)Run-Time error

(d)Unpredictable

__________________________________________________ _______________________________________________

(a)1000 f87 (c)1000 f88

z=x<<y; printf("%#x %#x",z,x>>y-1); (b)8800 0xf88 (d)0x1000 0xf88

[Q015]. What will be the output of the following program : void main() { int a=1,b=2,c=3,d=4; if (d > c)

Ans. (d) __________________________________________________ _______________________________________________

if (c > b) printf("%d %d",d,c); else if (c > a)

[Q012]. What will be the output of the following program : void main() {

printf("%d %d",c,d); if (c > a)

register int a=5; int *b=&a; printf("%d %d",a,*b); (b)Run-Time error

if (b < a) printf("%d %d",c,a); else if (b < c) printf("%d %d",b,c);

} (a)Compile-Time error Ans. (a) (c)5 5

(d)Unpredictable

} (a)4 3 3 4 Ans. (c)

(c)4 32 3

(b)4 3 3 2

(d)4 33 1

__________________________________________________ _______________________________________________

__________________________________________________ _______________________________________________

[Q013]. What will be the output of the following program : auto int a=5; void main()

[Q016]. What will be the output of the following program : void main() {

{ printf("%d",a);

int a=1,b=2,c=3,d=4; if (d > c)

if (c > b) if (c > a) if (c > a)

108

printf("%d %d",d,c); printf("%d %d",c,d); if (b < a)

void main() { int i=1;

for (; i<4; i++); }

printf("%d\n",i); (b)1 2 3

if (b < c) printf("%d %d",b,c); } (c)4 3 3 4 2 3

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

(a)No Output (c)4

(d)None of these

(a)4 32 3 Ans. (b)

(b)4 33 42 3

Ans. (c)

(d)None of these

__________________________________________________ _______________________________________________

__________________________________________________ _______________________________________________

[Q020]. What will be the output of the following program : void main() {

[Q017]. What will be the output of the following program : void main() { int a=1;

int a,b; for (a=0; a<10; a++);

if (a == 2);

(a)No Output (b)C Program (c)Compile-Time Error Ans. (b) __________________________________________________ _______________________________________________ [Q018]. What will be the output of the following program : void main() { int a=1;

printf("C Program");

(a)Compile-Time error (c)10 7

for (b=25; b>9; b-=3); printf("%d %d",a,b); (b)10 9

Ans. (c) __________________________________________________ _______________________________________________

(d)None of these

[Q021]. What will be the output of the following program : void main() { float i;

if (a) printf("Test"); else; printf("Again");

} (a)0.10.20.3 Ans. (a)

for (i=0.1; i<0.4; i+=0.1) printf("%.1f",i); (b)Compile-Time Error (d)No Output

(c)Run-Time Error

(a)Again Ans. (d)

(b)Test (c)Compile-Time Error

__________________________________________________ (d)TestAgain _______________________________________________

__________________________________________________ _______________________________________________

[Q022]. What will be the output of the following program : void main() {

[Q019]. What will be the output of the following program :

int i; for (i=-10; !i; i++);

(a)0 Ans. (c)

} (c)10

printf("%d",-i); (b)Compile-Time Error (d)No Output

109

__________________________________________________ _______________________________________________

[Q026]. What will be the output of the following program : void main() { int i;

__________________________________________________ _______________________________________________

[Q023]. What will be the output of the following program : void main() { int i=5;

(a)No Output

for (i=5; --i;) printf("%d",i); (b)54321

do; printf("%d",i--); } (a)5 Ans. (c) while (i>0);

Ans. (c) __________________________________________________ _______________________________________________

(c)4321

(d)None of these

(c)Compile-Time Error

(b)54321

(d)None of these

[Q027]. What will be the output of the following program : void main() {

__________________________________________________ _______________________________________________ [Q024]. What will be the output of the following program : void main() { int i;

int choice=3; switch(choice) { default: printf("Default"); case 1:

(a)Compile-Time error (c)468 Ans. (c)

printf("%d",i); }

for (i=2,i+=2; i<=9; i+=2)

printf("Choice1"); break;

(b)2468

(d)None of these } }

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

__________________________________________________ _______________________________________________ [Q025]. What will be the output of the following program : void main() { int i=3;

(a)No Output (b)Default (c)DefaultChoice1 (d)None of these Ans. (c) __________________________________________________ _______________________________________________

(a)No Output Ans. (d)

for (i--; i<7; i=7) printf("%d",i++); (b)3456

[Q028]. What will be the output of the following program : void main() {

(c)23456

(d)None of these

static int choice;

switch(--choice,choice-1,choice-1,choice+=2) {

case 1:

110

printf("Choice1"); break; (a)024 Ans.

for (j<5; j<5; j+=j<5) } printf("%d",j++);

case 2:

printf("Choice2"); break;

(c)01234

(b)Compile-Time Error (d)No Output

__________________________________________________ _______________________________________________

default: }

printf("Default");

[Q032]. What will be the output of the following program : void main() {

(a)Choice1 (c)Default Ans. (a)

(b)Choice2 (d)None of these

int i=9; for (i--; i--; i--)

__________________________________________________ _______________________________________________ [Q029]. What will be the output of the following program : void main() { (a)9 6 3 1 Ans.

printf("%d ",i); (b)Compile-Time Error (d)Infinite Loop (c)7 5 3

} (a)Compile-Time error Ans. (b)

for (;printf("");); (b)Executes ONLY once

__________________________________________________ _______________________________________________ [Q033]. What will be the output of the following program : void main() { int i;

(c)Executes INFINITELY

(d)None of these

__________________________________________________ _______________________________________________

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

[Q030]. What will be the output of the following program : void main() { int i; for (;(i=4)?(i-4):i++;) } printf("%d",i);

(a)6 4 2 Ans.

(b)Compile-Time Error (d)Infinite Loop

(c)6 3 1

__________________________________________________ _______________________________________________ [Q034]. Which of the following code causes INFINITE Loop : (a)do while(1); (c)do; (b)do;while(1); (d)do{}while(1);

(a)Compile-Time error Ans. (d)

(c)Infinite Loop (d)No Output

(b)4

__________________________________________________ _______________________________________________ [Q031]. What will be the output of the following program : void main() { static int j;

while(1); (i)Only (a) (ii)Only (b), (c) & (d)

(iii)None of these (iv)All of these

Ans.

__________________________________________________ _______________________________________________

111

Output: (c) Explanation: As we know size of int data type is two byte while char pointer can pointer one byte at time.

[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; Loop(i)

Memory representation of int i=320 So char pointer ptr is pointing to only first byte as shown above figure.

for (i=0; i<=3; i++) printf("%d",sum);

*ptr i.e. content of first byte is 01000000 and its decimal value is 64.

(a)Run-Time Error (c)18

(b)Compile-Time Error (d)0

Ans. __________________________________________________ _______________________________________________

How to represent char, int and float data in memory? Data type tutorial.

(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); } #define x 5+2 void main(){ int i; (a)320 (b)1 (c)64 (d)Compiler error (e)None of above i=x*x*x; printf("%d",i); } (a)343 (b)27 (c)133 (2) What will be output if you will compile and execute the following c code?

112
(d)Compiler error (e)None of above Output: (b) 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:

What is intermediate file and how to see intermediate file? Preprocessor tutorial.

(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

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,

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 125+3=-128

i=5+2*5+2*5+2 =5+10+10+2 =27

125+4=-127 125+5=-126 125+6=-125 125+7=-124 125+8=-123 125+9=-122 125+10=-121

113

(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

What is cyclic nature of data type?

11001100 11001101 Content of variable a will store in the memory as:

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 printf("Greater than"); }

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 data type.

likes 4.5, 3.25, 5.0 will store same values in float and double

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 (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;

(a)Equal (b)Less than

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.

114

(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

Step 1: Increment the variable I up to break point. Step 2: Start assigning final value 7 to all variable i in the expression.

(e)Compiler error Output: (e) Explanation: Keyword break is not part of if-else statement. Hence it will show compiler error: Misplaced break

So, i=7+7+7=21

What is break point?

Where we can use break keyword? Control statement tutorial

Operator 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); }

115

(a)12 11 11 (b)12 10 10 (c)11 11 12 (d)10 10 12 (e)Compiler error Output: (a) Explanation: In c printf function follows cdecl parameter passing scheme. 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.

(a) 11Hello world (b) 10Hello world (c) Hello world10 (d) Hello world11 (e) Compiler error Output: (d) Explanation: Return type of printf function is integer and value of this

integer is exactly equal to number of character including white space printf function prints. So, printf(Hello world) will return 13.

What is prototype of printf function?

What is cedecl and pascal parameter passing convention? Function tutorial. Formatted I/O 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));

(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); }

116
#include "string.h" void main(){ int i=0; for(;i<=2;) printf(" %d",++i); } (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.

(a)cquestionbank (b)cquestionbank\0 (c)(null) (d)It will print nothing (e)Compiler error Output: (c) Explanation: We cannot copy any thing using strcpy function to the character pointer pointing to NULL. String tutorial.

Complete tutorial of looping in C.

More questions of string.

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

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

void main(){ int x; for(x=1;x<=5;x++);

#include "stdio.h"

printf("%d",x); }

117
(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.

(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.

Detail explanation of all types of constant in C.

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

#include "stdio.h" #include "string.h"

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

void main(){ char c='\08'; printf("%d",c); }

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

(a)8 (b)8 (c)9 (d)null

(a)2 (b)4 (c)8

(e)Compiler error Output: (e) Explanation: In c any character is starting with character \ represents

118

Explanation: ## is concatenation c preprocessor operator. It only concatenates the operands i.e.

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.

a##b=ab

If you will see intermediate file then you will find code has converted into following intermediate code before the start of actual compilation. Intermediate file:

Octal character constantan.

Hexadecimal character constant. test.c 1: (14) What will be output if you will compile and execute the following c code? 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:

#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

It is clear call(x, y) has replaced by xy.

What is macro call? Preprocessor tutorial.

Output: (d)

(15) What will be output if you will compile and execute the following c code? int * call();

119
void main(){ int *ptr; ptr=call(); clrscr(); printf("%d",*ptr); } int * call(){ int a=25; a++; return &a; } (a)25 (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. struct outer{ int a; struct inner{ char c; }; };

(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.

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:

Complete pointer tutorial.

struct outer{ int a;

(16) What is error in following declaration?

struct inner{

120
char c; }name; }; Array tutorial. Structure tutorial. Array of pointer. Union tutorial. How to read complex pointers. (17) What will be output if you will compile and execute the following c code? In c, array[2]=*(array+2)=*(2+array)=2[array]=30

(18) 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]); } void main(){ int i=10; static int x=i; if(x==i) (a)-60 (b)-30 (c)60 (d)Garbage value (e)Compiler error printf("Equal"); else if(x>i) printf("Greater than"); else printf("Less than"); } (a)Equal (b)Greater than

Output: (b) Explanation:

(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.

121
(d)9 (e)Compiler error

Output: (d) Explanation: || is logical OR operator. In C logical OR operator doesnt 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

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

Properties of && operator.

Operator tutorial with examples.

(a)7 (b)11 (c)8

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

122

test.c 6: } test.c 7:

#define max 5; void main(){ int i=0; i=max++; printf("%d",i++); }

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?

(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

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

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

(a)12 (b)8 (c)4

123
(d)1 (e)Compiler error (a)2 6 (b)4 6 (c)2 5 (d)4 5 (e)Compiler error Output: (d) What is near pointer? Explanation: ++a +b =6 + Garbage floating point number =Garbage floating point number //From the rule of automatic type conversion Hence sizeof operator will return 4 because size of float data type in c is 4 byte. }

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

What is huge pointer?

Complete pointer tutorial.

Value of any variable doesnt modify inside sizeof operator. (21) What will be output if you will compile and execute the following c code? Hence value of variable a will remain 5.

void main(){ int a=5; float b; printf("%d",sizeof(++a+b)); printf(" %d",a);

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"); }

124
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

(a)Equal (b)Greater than (c)Less than (d)Compiler error (e)None of above

Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 =0XC2550 + 0X1341 =0XC3891

Output: (a) Explanation: As we know huge pointers compare its physical address. Physical address of huge pointer p

Since both huge pointers p and q are pointing same physical address so if condition will true.

Huge address: 0XC0563331 Offset address: 0x3331

What is huge pointer? What is normalization?

125
Pointer tutorial. String tutorial.

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

void main(){ 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 (a)5 (b)10 (c)15 (d)Compiler error (e)None of above Output: (d) Explanation: Array element cannot be address of auto variable. It can be address of static or extern variables. int a=5,b=10,c=15; int *arr[]={&a,&b,&c}; printf("%d",*arr[1]); }

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

General meaning of %[^ p]

What is auto variable?

What is extern variable?

126

of declaration is static. Default initial value of static integer is zero.

What is static variable?

Properties of static storage class.

Array tutorial.

How to read complex array.

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

(26) 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]); }

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

(a)4 (b)5 (c)6 (d)7 (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.

(a)5 garbage garbage (b)5 0 0 (c)5 null null (d)Compiler error (e)None of above output: (b) Explanation: Storage class of an array which initializes the element of the array at the time

127

=2[a [1]] =2[1[a]] Now, a [1] [2] means 1*(4) +2=6th element of an array

Questions on two dimension array.

Complete tutorial of array.

staring from zero i.e. 21.

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

Concept of complex array.

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]]); }

Concept of complex pointer.

Concept of complex function.

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

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

Explanation: In c, a [1][2] =*(a [1] +2) =*(*(a+1) +2)

(d)10 11 12 (e)Compiler error Output: (b)

128

(d)Compiler error (e)Run time error Output: (c) Explanation: Auto variables are stored in stack as shown in following figure.

Explanation: Default parameter passing scheme of c is cdecl i.e. argument of function will pass from right to left direction. First ++a will pass and a=11 Then a++ will pass and a=11 Then a will pass and a=12 What is pascal and cedecl parameter passing scheme?

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

Memory map tutorial. Concept of variable numbers of argument. More questions based on memory map. (29) What will be output if you will compile and execute the following c code? (30) 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"); } void main(){ register int i,x; scanf("%d",&i); x=++i + ++i + ++i; (a)Garbage Garbage Garbage (b)5 10 15 (c)15 10 5 printf("%d",x); } (a)17

(b)18 (c)21 (d)22 (e)Compiler error Output: (e) Explanation: In c register variable stores in CPU it doesnt store in RAM. So register variable have not any memory address. So it is illegal to write &a.

129
(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 local variable a became dead.

inside that block. When control comes out of the inner block

Complete tutorial of storage class with examples.

Complete tutorial of storage class with examples.

Properties of register storage class.

What is auto 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++; } }

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

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

printf("%d %d",a,b); (a)5 10 (b)6 11 (c)5 11 (d)6 10

(a)3.4e39 (b)3.40000

130
(c)+INF (d)Compiler error (e)Run time error Output: (c) Explanation: If you will assign value beyond the range of float data type to the float variable it will not show any compiler error. It will store infinity.

(a)-22 (b)-18 (c)1 (d)Compiler error (e)None of above

Output: (b) Explanation: Default value of enum constant = value of previous enum

Data type tutorial with examples.

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.

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

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

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

131

a,b,c=32767,d,e }; printf("%d",b); }

(a)0 (b)1 (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 enum constant.

Output: (a) 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.

of d will be 32767+1=32768 which is beyond the range of

How to write assembly language program by c? Tutorial of data type with examples. Advance c tutorial. (36) What will be output if you will compile and execute the (35) What will be output if you will compile and execute the following c code? following c code?

void main(){ void main(){ enum xxx{ signed int a=-1; unsigned int b=-1;

if(a==b) printf("%d %d",a,b); else printf("Not equal"); }

132
}

(a)1.500000 (b)1.000000 (c)5.500000 (d)Compiler error (e)None of above Output: (d)

(a)-1 -1 (b)-1 32767 (c)-1 -32768 (d)Not equal (e)Compiler error Output: (a) Explanation:

Explanation: Modular division is not allowed with floating number.

Properties of modular division.

Operators tutorial with examples. What is automatic type conversion? (38) What will be output if you will compile and execute the following c code? (37) What will be output if you will compile and execute the following c code? void main(){ void main(){ float f=5.5f; float x; x=f%2; printf("%f",x); int a=-20; int b=-3; printf("%d",a%b); }

133
(a)2 (b)-2 (c)18 (d)-18 (e)Compiler error Output: (b) Explanation: Sign of resultant of modular division depends upon only the sign of first operand.

(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? (40) What will be output if you will compile and execute the following c code? void main(){

char *url="c:\tc\bin\rw.c"; Properties of modular division. Operators tutorial with examples. printf("%s",url); }

(a)c:\tc\bin\rw.c (b)c:/tc/bin/rw.c (c)c: c inw.c (d)c:cinw.c

(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')); }

(e)w.c in

Output: (e) (a)1 1 (b)2 2 Explanation: 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.

134
(e)Compiler error Output: (e) Explanation: Label of goto cannot be in other function because control cannot move from one compiler error:

3. \r is carriage return character which moves the cursor beginning of the line.

Complete string tutorial with examples.

function to another function directly otherwise it will show Properties of escape characters. unreachable label

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

What is goto keyword.

void main(){ clrscr(); goto abc; printf("main"); getch(); } void dispaly(){ abc :

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"); }

printf("display"); }

(a)main (b)display (c)maindisplay (d)displaymain

(a)1

(b)48 (c)24 (d)Not equal (e)Compiler error 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*

135

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 Output: (a) Explanation: Expression x+y<=5 => 2+3 <=5

What is associative?

=> 5<=5 is true because 5 is either greater than 5 or equal to 5.

What is precedence? Operator tutorial with examples. Tutorial of bitwise operators. (44) What will be output if you will compile and execute the (43) What will be output if you will compile and execute the following c code? following c code?

136
void main(){ const int i=5; i++; printf("%d",i); } void main(){ const int x=25; int * const p=&x; *p=2*x; printf("%d",x); (a)5 (b)6 (c)0 (d)Compiler error (e)None of above Output: (d) Explanation: We cannot modify the const variable by using increment operator. (a)25 (b)50 (c)0 (d)Compiler error (e)None of above Output: (b) Explanation: const keyword in c doesnt make any variable as constant but Properties of const keyword. 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: }

Properties of volatile keyword.

Data type tutorial with examples.

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.

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

137
Properties of const keyword.

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.

What is constant pointer?

Data type tutorial with examples.

Note: We have assumed arbitrary memory address.

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

To make pointer p as constant pointer write: int const * const p=&i;

void main(){ int i=11; int const * p=&i; p++; printf("%d",*p); } (47) What will be output if you will compile and execute the following c code? (a)11 (b) 12 (c)Garbage value (d)Compiler error (e)None of above Output: (c) Explanation: Properties of volatile keyword. Properties of const keyword.

void main(){ int a=15,b=10,c=5; if(a>b>c ) printf("Trre"); else printf("False");

138
}

What is precedence?

(a)True (b)False (c)Run time error (d)Compiler error (e)None of above

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

void main(){ float f; f=3/2;

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:

printf("%f",f); }

(a)1.5 (b)1.500000 (c)1.000000 (d)Compiler error (e)None of above Output: (c) Explanation:

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.

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.

What is associative?

Properties of floating type numbers.

139

What is global identifier?

(49) What will be output if you will compile and execute the following c code? void main(){ int a=sizeof(a); a=modify(a); printf("%d",a); } int modify(int x){ int y=3; _AX=x+y; return; } (a)2

(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 Output: (d)

(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.

Explanation:

First see intermediate file: What is register pseudo variable? 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:

140

(51) What will be output if you will compile and execute the following c code? struct marks{ int p:3; int c:3; int m:2; }; void main(){ struct marks s={2,-6,5}; printf("%d %d %d",s.p,s.c,s.m); }

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

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

More questions on preprocessors.

Preprocessor tutorial with examples.

Links to this post 2 comments

C questions and answer

141
(d) Compiler error (e) None of these

Complete memory representation: Structure tutorial

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]);

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:

} Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.

(a) math (b) phy (c) che

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

142
printf("%d",(**ptr)()); (*(*ptr+1))(); } int display(){ int x=5; return x++; }

How to read complex pointer?

(a)5 (b)6 (c)0 (d)Compiler error (e)None of these

Pointer tutorial.

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

#include"conio.h" int display(); int(*array[3])(); int(*(*ptr)[3])(); void main(){ array[0]=display; array[1]=getch; ptr=&array; 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.

143

char far *ptr=(char *)0XB8000000; *ptr='A'; *(ptr+1)=1; *(ptr+2)='B'; *(ptr+3)=2; *(ptr+4)='C'; *(ptr+5)=4; }

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] =getch () //array[1]=getch

How to read complex array?

Answer: It output will be A, B and C in blue, green and red color respectively. As shown in following figure:

Array tutorial.

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

void main(){ int i;

What is far pointer?

Advance c tutorial?

144

Working with text video memory.

Answer: One red color line in the graphics console as shown in the following figure

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

#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; }

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;

145
*p=200; printf("%d",*q); } Physical address= Segment address * 0X10 + Offset address =0XC056 * 0X10 +0X3331 =0XC0560 + 0X3331 (a)0 (b)Garbage value (c)null (d) 200 (e)Compiler error Huge address: 0XC2551341 Offset address: 0x1341 Segment address: 0XC255 Physical address of huge pointer q =0XC3891

Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 =0XC2550 + 0X1341 Answer: (d) Explanation: Since both huge pointers p and q are pointing same physical Physical address of huge pointer p address so content of q will also same as content of q. =0XC3891

Huge address: 0XC0563331 Offset address: 0x3331 Segment address: 0XC056

What is huge pointer?

Pointer tutorial.

146

clrscr(); printf("(%d , %d)",x,y); delay(250); int86(0x33,&i,&o); } getch(); }

(57) Write c program which display mouse pointer and position of pointer.(In x coordinate, y coordinate)?

Answer:

#includedos.h #includestdio.h void main() { union REGS i,o; int x,y,k; //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;

What is int86? Advance c tutorial.

(58) Write a c program to create dos command: dir. 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); } } else { printf("File not found"); } }

147

Click on new button (Button inside the red box)

Step 7: Write following: 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.

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.

(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");

Step 5: Select Advanced -> Environment Variables Step 6: You will find following window:

148
else if(x>i) printf("Greater than"); else printf("Less than");

Properties of static variables.

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) Equal (b) Greater than (c) Less than (d) Compiler error (e) None of above

(a)0 0 0 0 (b)Garbage Garbage Garbage Garbage (c)102 56 -80 32 (d)102 102 -90 64 (e)Compiler error

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.

149
Content of first byte: Binary value=01000000 Decimal value=64 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. Note: Character pointer treats MSB bit of each byte i.e. left most bit of above figure as sign bit.

Memory representation of float a=5.2

How to represent float data type in memory?

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

ptr pointer will point first fourth byte then third byte then second byte then first byte.

void main(){ int i; double a=5.2; char *ptr; ptr=(char *)&a; for(i=0;i<=7;i++) printf("%d ",*ptr++); }

Content of fourth byte: Binary value=01100110 Decimal value= 64+32+4+2=102 Content of third byte: Binary value=01100110 Decimal value=64+32+4+2=102 Content of second byte: Binary value=10100110 Decimal value=-128+32+4+2=-90

(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

150
Content of sixth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of fifth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of fourth byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of third byte: Binary value=11001100 Decimal value= -128+64+8+4=-52 Content of second byte:

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

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.

Binary value=000010100 Decimal value=16+4=20 Content of first byte: Binary value=01000000

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

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?

151
(62) What will be output if you will compile and execute the following c code? void main(){ printf("%s","c" "question" "bank"); }

(a) Current system date (b) Current system date with time (c) null (d) Compiler error (e) None of these Answer: (a)

(a) c question bank (b) c (c) bank (d) cquestionbank (e) Compiler error Answer: (d)

Explanation: __DATE__ is global identifier which returns current system date.

What is global identifier?

Explanation: In c string constant xy is same as x y

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

String tutorial.

void main(){ char *str="c-pointer"; printf("%*.*s",10,7,str); }

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

void main(){ printf("%s",__DATE__); }

(a) c-pointer (b) c-pointer (c) c-point (d) cpointer null null

(e) c-point

152
printf("\nstart function: %d",++i); } void end(){ printf("\nend function: %d",++i); getch(); }

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 string. and second * indicates how many characters will print of any

(a) Following figure illustrates output of above code: Properties of printf function. main function: 2 start function: 1 end function:3

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

(b) void start(); void end(); #pragma startup start #pragma exit end int static i; void main(){ printf("\nmain function: %d",++i); } void start(){ clrscr(); (d) Compiler error (c) main function: 2 end function:3 start function: 1 start function: 1 main function: 2 end function:3

153
(e) None of these

(d) -96 (e) Compiler error Answer :( c) Explanation:

Answer: (b) Explanation: Every c program start with main function and terminate with null statement. But and #pragma exit #pragma startup can call function just before main function

Binary value of 12 is: 00000000 00001100 Binary value of -12 wills 2s complement of 12 i.e. So binary value of -12 is: 11111111 11110100 Right shifting rule: Rule 1: If number is positive the fill vacant spaces in the left side by 0.

What is pragma directive?

Preprocessor tutorial.

Rule 2: If number is negative the fill vacant spaces in the left (66) What will be output if you will compile and execute the following c code? 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: void main(){ int a=-12; a=a>>3; printf("%d",a); }

Since it is negative number so output will also a negative number but its 2s complement. Hence final out put will be: And its decimal value is: 2 Hence output will be:-2

(a) -4 (b) -3 (c) -2

More questions on shifting operator.

154
Operator tutorial.

Library functions of string.

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

(68) 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(); }

void main(){ static main; int x; x=call(main); clrscr(); printf("%d ",x); getch(); } int call(int address){ address++; return address; }

(a) 6 6 (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

(a) 0 (b) 1

(c) Garbage value (e) None of these

(d) Compiler error

character while strlen function returns length of a string excluding null character.

Answer: (b) Explanation:

String tutorial.

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.

155

In c comma behaves as separator as well as operator. a=1, 3, 15; b= (2, 4, 6);

What is main function in c?

In the above two statements comma is working as operator. Comma enjoys least precedence and associative is left to right.

(69) What will be output if you will compile and execute the following c code? Assigning the priority of each operator in the first statement:

void main(){ int a,b; a=1,3,15; b=(2,4,6); clrscr(); printf("%d ",a+b); getch(); } (70) What will be output if you will compile and execute the following c code? Hence 1 will assign to a. Assigning the priority of each operator in the second statement:

Operator tutorial.

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();

(a) 3 (b) 21 (c) 17 (d) 7 (e) Compiler error Answer: (d)

Explanation:

} int dynamic(int s,...){ void *ptr; ptr=...; (int *)ptr+=2; s=*(int *)ptr; return s;

156

(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) 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 which is pointing

(a) 0 (b) 2 (c) 23 (d) Compiler error (e) None of these Answer: (c) Explanation: extern variables can search the declaration of variable any where in the program.

arguments of function. In this example ptr is generic pointer to first element of variable number of argument. After incrementing it will point third element.

Properties of extern storage class. What is variable number of argument?

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

157
Explanation:

void main(){ int i=0; if(i==0){ i=((5,(i=3)),i=1); printf("%d",i); } else printf("equal"); }

Comma operator.

Operator tutorial.

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

void main(){ int a=25; clrscr(); printf("%o %x",a,a); getch(); }

(a) 5 (b) 3 (c) 1 (d) equal (e) None of above

(a) 25 25 (b) 025 0x25 (c) 12 42 (d) 31 19 (e) None of these

Answer: (c)

158
printf("%s",message); getch(); }

Answer: (d) Explanation: %o is used to print the number in octal number format. %x is used to print the number in hexadecimal number format.

(a) union is power of c (b) union ispower of c (c) union is Power of c (d) Compiler error

Note: In c octal number starts with 0 and hexadecimal number starts with 0x.

(e) None of these Answer: (b) Explanation: If you want to write macro constant in new line the end with the character \.

What is octal number?

What is hexadecimal number? Preprocessor tutorial. (74) What will be output if you will compile and execute the following c code?

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

#define message "union is\ power of c" void main(){ clrscr(); #define call(x) #x void main(){ printf("%s",call(c/c++));

159
}

Preprocessor tutorial?

(a)c (b)c++ (c)#c/c++ (d)c/c++ (e)Compiler error Answer: (d) Explanation: # is string operator. It converts the macro function call argument in the string. First see the intermediate file:

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

void main(){ if(printf("cquestionbank")) printf("I know c"); else printf("I know c++"); }

(a) I know c test.c 1: test.c 2: void main(){ test.c 3: printf("%s","c/c++"); test.c 4: } test.c 5: (b) I know c++ (c) cquestionbankI know c (d) cquestionbankI know c++ (e) Compiler error

It is clear macro call is replaced by its argument in the string format.

What is # and ##?

Answer: (c) Explanation:

160
Return type of printf function is integer which returns number of character it condition will prints including blank spaces. So printf function inside if return 13. In if condition any non- zero number means true so else part will not execute.

3) stat

4) auto

6) A program can be terminated at any time by calling the function

1) fflush() 3) exit()

4) clearerr()

2) ferror()

7) Heap Prototype of printf function. 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above 8) A function can 1) perform a task 2) return a value

1. Which of the following does not have an unary operator? 1) -7 2) ++i

3) change value of actual arguments in call by reference 4) all of the above

3) j above

4) all of the

9) Function definition void check(int i ,char*j) is 1) call by value 2)call by reference 3) both (1) and (2) definition 4)in valid function

2. In printf(),the appearance of the output of the output can be affected by 1) field with character 3) flag above 2) conversion 4) all of the

10) A union consists of a number of elements that 1) all occupy the same space in memory 2) must be structure 3) are grouped next to each other in memory 4) all have the same type

3. Any of the following programs in c has access to three standard files:

1) standard input file, standard output file, standard error file 2) stdin,stdout, stderr 3) keyboard,screen,screen 4) all the above

11) Which of the following array is defined in the statements Char name[30]?

1) name is one dimensiona,30-element integer array array

2) name is one dimensional,30-element floating point 3) name is one dimensional ,30-element character

5) A variable can be declared static using the keyword. 1) extern 2) static

array 4) name is one dimensional,30-elements string array

161

1) -23677 to 23678 2) -32768 to 32767 3) -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 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 characters 2) the characters themselves

12) c program contains the following declaration: Static float table[2][3]={ {1.1,1.2,1.3}, }; What is the value of *(*(table+1)+1)? 1) 2.2 3) 2.1 2) 1.2 {2.1,2.2,2.3}

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 3) 1

3) neither of the two 4) binary code and hexadecimal code

2)18 4) 0

21) The word case used in the switch statement represents a 1) function in the c language

14) The declaration : int f(int); means 1) f accepts an integer argument and returns an integer

2) data type in the c language

quantity 2) f accepts two arguments and returns a double precision quantity, and the second is an integer 3) f accepts three arguments and returns nothing. The first arguments

3) keyword in the c language 4) global variable in the c language 22)The logical NOT operator represented by ! is a 1) unary operator binary operator 2) 4) octal operator

is a double-precision quantity, and the second is an integer 4) f does not accepts any arguments but returns a single character

3) ternary operator

16) The arguments of a function are included between 1) The parenthesis 2) double quotes 3) curly braces 4) #

23) The statement : scanf(%d,&i); 1) assigns an integer to the variable i 2) gives an error message; 3) does not assign any value to i

17) The int type of constraints are whole numbers in the range

4) assigns an float to the variable i 24) A pointer is declared by using a statement such as

162
1) int *p; 2) point; 3) pointer *p; 4) int &p;

2) equality operators 3) logical operators 4) relational operators 32) The library files that come with c are 1) text editor for program development 2) the compiler and liker 3) program examples

25)The null character is represented by 1) \n 2)\0 3)\o

4)\t

26) The members in the union 1) have different memory locations

4) files that contain functions which carry out various commonly Used operations and calculations 33) Precedence determines which operator 1) is evaluated first 3) is fastest number 2) is most important

2) share the memory with a structure 3) have the same memory location 4) have different memory variable

4) operates on the largest

27) The global variables by default belong to 1) the register type 3) the auto type 2) the static type

4) the dynamic type

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

37) The malloc() function 1) returns a pointer to the allocated memory 2) returns a pointer to the first byte of region of memory 3) changes the size of the allocated memory 4) deallocates the memory

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

3) statements

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)1stderr complement

39) If an error occurs while opening a file the file pointer is assigned a value 30) A fields width specifier in a printf() function 1) specifies the maximum value of a number 1) NULL 2) stdout 3) sstderr

4) not defined

2) controls the size of type used to print numbers

3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number

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

31) The two operators && and || are 1) arithmetic operators

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

163
42) The comments in a c language program are placed between

3) a member of a union 4) all of the above

1) \* and /* /*and*/

4) # and #

2) / and .*

3)

43) If p and q are assigned the values 2 and 3 respectively then the statement p=q++

51) Almost every c program begins with the statement 1) main() 2) printf() 3) #include<stdio.h>

1) gives an error message 2) assigns a value 4 to p 3) assigns a value 3 to p 4) assigns a value 5 to p

4) scanf()

44) A compound statement is a group of statement included between a pair of 1) double quots 3) parentesis

52) A single character input from the keyboard can be obtained by using the function 1) printf( ) ) 2) getchar( )

2) curly braces 4) / and/

3) putchar( )

4) scanf(

45) The number of the relational operators in the c language is

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

1) four 2) six

3) three 4)one

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

characters 3) causes the computer to carry out some action 4) all of the above

54) The expression c=i++ causes 1) the value of I assigned to c and then I incremented by 1 2) I to be incremented by 1 and then the value of I assigned to @ 3) Value of I assigned to c 4) I to be incremented by 1

47) In the c language, a hexadecimal number is represented by writing 1) x

2) xo

3) 0x

4)h

48) A string in the c language is represented by enclosing a series of characters in 1) single quotes 3) parenthesis 49) One structure can be 1) a member of some other structure 2) a member of the same structure

2) double quotes 4) / and /

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 the

Data item is displayed as 1) a floating point value with an exponent 2) an unsigned decimal integer 3) a signed decimal integer 4) an octal integer

164
}

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

Ans c

a)

q b) r c) z d) compilation error

4) main() { Char a[100]={abcdef}; printf(%s,&a[1]); a++;

58) In a circular linked list 1) components are all linked together in some 2) there is no beginning and no end 3) components are arranged hierarchically permitted sequential manner

} b)

4) forward and backward transversal within the list is

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

Ans c 5)

60) A c function contain 1)function body 3)a function header 2)argument declaration 4)all of the above

main() {

C QUESTIONS ON ARRAYS

Char *p=algc; Printf(%c,++*(p++)); Printf(%c,*++p);

1.

{ Int a[5];

main()

a)

al b) bg c) lg d) none of the above

a[-2]=10;

a[2]=1; printf(%d,-2[a]); }

ans b 6) main() Int n[25];

a)

compilation error b)10 c)-1 d)none of the above

n[0]=100; n[24]=200; printf(%d%d,*n,*(n+24)+*(n+0));

Ans c 2. { main() Char a[3][3]={{a,b,c},pqr,xy}; Printf(%s\n,&a[0][0]); a) }

} a)

Ans b

100 200 b) 100 300 c) 0,100 d) 0,200

Ans c 3.

a b)compilation error c)abcpqrxy d)abc

7)main() {

Int a[3]={1}; }

main() { char a[3][3]={abc,pqr,xyz};

Printf(%d,a[1]);

a)

1 b) 0 c) compillation error d) none of the above

165
Ans b 8) main() Ans: b

Static int n[3][3]={2,4,3,6,8,5,3,5,1}; }

12) main() { Char a[]={\012345\};

Printf(%d%d%d,n[2][1],n[1][1],n[3][1]); }

Printf(%s %d %d\n,a,sizeof(a),sizeof(*a));

a)5 8 garbage value b) 845 c)623 d)825 ans a) 9) main() {

13) main() { Char a[]=hell0009; Printf(%s\n,a);

Char a=ab; } a)

Printf(%c,a);

} Ans:: hell0009

ans a)

a b) b c) ab d) error

DATA STRUCTURES ON SINGLE LINKED LIST 1) each structure in a single linked list contains --------&-------------

10) main() { Char *p;

p=%d\n; p[1]=c; }

a) data & pointer to hold the address of that node. b) data & pointer to hold the address of next node.

printf(p,65);

c) data & pointer to hold the address of previous node. d) pointer to hold the address of next and previous node. Ans b

ans a 11) main() {

a)

A b) c c) 65 d) error

2) a) b) c)

address of first node address of that node null

what does the last node link contain

int a=1; switch(a==5) { Case 1: pf(hi);

d) address of previous node ans c 3) a) Break; c) b) d) a) c) steps involved in insertion of a node

Creating a new node.

Accepting data into the node

Case 0:pf(hello);break; Default : pf(wipro\n); }

If the list does not exist, assign start to the new node.

If the list exists insert the new node at the end of the list. 1234 1324 4321

b)

a) Hi b)hello c) hi d)wipro

d) 3 1 2 4 Ans a)

166
4) 1) 2) 3) 4) steps involved in traversing the list

ans 4 7) when start and last points to same node,how many elements are present 1) Ans 2 0 2)1 3)2 4)3

store the address of the start node in a temporary variable. Repeat steps 2 & 3 until the the temporary pointer points to null. Print data in the node.

Move the temporary pointer pointer to the next node. 1234 1432 1342 2314

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)

b)

c) d)

Ans 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) f) 1234 3241

} (a) garbage value (b) 2 3 3 (c) 3 2 2 (d) 0 0 0 ans::d 2).What would be the output of the following program. main() { int i=-3,j=2,k=0,m;

Ans f

g) 1 3 2 4 h) 2 4 3 1

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

6) if a node (q) is to be inserted at the beginning the operations which are performed is 1) q->next =start->next start =q; start=q;

(a) -2 3 0 1 error ans::a 3)

printf("\n %d %d %d %d",i,j,k,m); (b) -3 2 0 1 (c) -2 3 1 1 (d)

main() Int n[25]; n[0]=100;

2)

q->next=start; q->next=start; q=start; q->next =start; start =q;

n[24]=200; }

printf(%d%d,*n,*(n+24)+*(n+0));

3)

a)100 200 b) 100 300 c) 0,100 d) 0,200 4) { main()

4)

char str[]="I am in wipro"; printf("%s\n",&str[5]);

167
ans::in wipro 5) { main() Char *p=algc;

8).main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) {

Printf(%c,++*p++); } Printf(%c,*++p);

printf(%d ,*a); a++;

} p = a; {

a)al b) mg c) lg d) none ans::none.....bg 6)main() { void fun(int); int n=3; } fun(n);

for(j=0; j<5; j++) 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++) {

void fun(int n) { {

if(n>0) fun(--n);

} ans::0120

printf("%d",n); fun(--n);

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

7).What would be the output of the following program. main() { } ans::222223465 10. #define ABC #define XYZ void main() { int #define XXX

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

struct emp { char name[20]; float sal; int age;

20 10 ABC - XYZ

};

the above ans::a

(a) 0 0.000000 (b) Garbage values (c) Error (d) none of

struct emp e = {"tiger"}; printf("\n %d %f",e.age,e.sal);

a;

a = XXX * 10; printf("%d\n", a);

168

ans::-80 11. #define calc(a, b) void main() { int a = 20, b = 10; printf("%d\n", calc(a + 4, b -2)); (a * b) / (a - b)

15.main() { static char int i;

names[5][20]={"pascal","ada","cobol","fortran","perl"}; char *t;

t=names[3];

names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) } printf("%s",names[i]);

} {

12.void main() int cnt = 5, a; do { } while (cnt --); a /= cnt;

ans::Error......base address can't be changed names[3]=names[4] 16.main() {

printf ("%d\n", a);

int x=20;y=35; x=x++ + y++; y=++y + ++x;

ans::Error..divide error 13. void main() {

int a, b, c, abc = 0; a = b = c = 40; if (c) {

} ans::57 94

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

17.Assume that integer is 4 bytes,pointer as 4 byter and character as 1 byte,then predict the output struct student { int a;

int abc; abc = a*b+c;

char name[10]; int *p; }s1,*s2;

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

printf("%d%d",sizeof(s1),sizeof(*s2)); a) 18,18 b)18,4 d) 4,4 c) 4,18 18.int fun(int x) { int y=55;

ans::40 0 {

14.main() int k = 5; if (++k < 5 && k++/5 || ++k <= 8) printf("%d\n", k);

} ans::7

} main()

return((x-y)?y:x);

169
int a=20; printf("%d",y); fun(a); } {

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

main( ) int i= 2; { int i = 3;

ans::20 19.int compute(int n) { { if(n>0) }

printf(" %d", i); fun(); } 3, 15 3, 6 3 0

n=compute(n-3)+compute(n-1); return(n); return(1);

b.

} }

c. d. Ans::a e.

void main()

{ printf("%d",compute(5)); }

3. #define xsq(x) x*x main( ) {

20.int main()

int i, j; i = 5;

{ char *ptr="abcdefgh"; char *sptr; sptr=ptr+5; }

j = xsq(i-2); }

printf(%d\n, j); 7 9

printf("%s",sptr); Ans::-7

a. b. c.

d.

13 29

ans::fgh

4. main( ) {

int a=35; printf( %d %d %d\n, a == 35,a=50,a>40); a. c. 1 50 1 0 50 0 0 50 1

b. d.

1 50 0

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 ans::d 2.

ans::c 5. void main() {

int i=5; fun( ) {

char a[]="123abcd";

clrscr(); printf("%d",strlen(a));

getch(); }

170

} a. Zero b. One c. Error ans::b

a. c.

b. d.

6 7 8 5

d. Compiler Error 9. void main() {

Ans::7 6. main() { static int var=5; if(var--) { printf("%d",var); main(); } } a. 4 3 2 1 0 b. 4 3 2 1 c. 5 4 3 2 1

int p=1,sum=0; clrscr(); { while(p<20) p++;

} } a. 120 b. 100 c. 110 d. Error ans::A

sum+=p++;

printf("\nsum=%d",sum);

d. 5 4 3 2 1 0

ans::a 7. void main() { int i=1,j=2; switch(i)

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

{ case 1: printf("One"); break;

case j: printf("Two"); break; default: printf(Default); break; } } a. One

b. Two c. Default ans::d

d. Compiler Error 8. void main() { switch('a') {

case 'A': printf("Zero"); break; case 97: printf("One"); default: printf("Error"); }

break;

break;

171
a. 12 12 c. 12 13

} a. 5 5 3 b. 4 5 3 c. 2 5 3 ans::c

b. 11 12 d. 13 13 11. main() { static i=3;

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 2 b. 2 1 c. 2 2 ans::b

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

return i>0?main():0;

a. 3 2 1 0 b. 3 2 1 c. 2 1 0 d. 2 1 12. void main()

d. 1 1 16. void main()

{ char *ptr="Hello World"; *ptr++; printf("%s",ptr); ptr++; printf("%s",ptr); } a. Iello World Iello World b. Hello World ello World c. ello World d. ello World ello World llo World

{ char *s[]={"dharma","hewlet-packard","siemens","ibm"}; char **p; p=s;

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

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

a. harma

b. dharma harma

harma ewlet-packard

ewlet-packard

13. int const *p; *p=5;

printf("%d",*p++); a. 5

c. harma hewlet-packard siemens d. harma harma

b. 6

c. Compiler Error d. Garbage Value ans::c 14. void main() {

ans::d

hewlet-packard

17. void main() { (*ptr)++;

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

char *str1="abcd";

char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("ab"));

} a. Samco Systems Samco Systems b. Samco Systems amco Systems c. amco Systems ans::b d. amco Systems amco Systems mco Systems

172

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

18. #define square(x) x*x void main() { int i=7;

a. 0 0 1 1 b. 0 0 3 3

clrscr();

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

3 3 c. 1 1 2 2 3 3 d. 1 1 2 2 2 2

2 2

a. 7

b. 16 c. 64

d. 4 ans::c

19. #define man(x,y) (x)>(y)?(printf("%d",x)):(y) void main()

Ans:a 21. void main() { struct emp { struct e { }e1; int a; int *a;

{ int i=15,j=10,k=0; k=man(i++,++j); printf(" %d %d %d",i,j,k); } a. 16 17 11 2

};

b. 17 17 11 2 c. 16 16 11 2 d. 16 17 12 2 ans::a 20. struct one { int no:1; int pl:2; int x:3; };

struct emp emp1; printf("%d %d",sizeof(emp1),sizeof(emp1.e1)); } a. 2 4 c. 4 4

b. 2 2 d. 4 2

ans::d 22. struct emp emp1; struct emp { int a;

void main() { struct one a; a.no=0;

}; main()

173

printf("Enter 1 values:");

{ int a=1,b=2,c=3; c=(--a, b++)-c; printf("%d %d %d",a,b,c); } (a)0 3 -3 (c)0 3 -1 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 (c)a=6 b=0 Ans::c 3. void main() { int i=5; printf("%d %d %d %d %d",++i,i++,i++,i++,++i); } (b)a=6 b=5 (d)None of these (b)Compile-Time Error (d)0 3 0

scanf("%d%d",&emp1.a,&emp1.a); //The given input is 10 and 25 } printf("a=%d a=%d",emp1.a,emp1.a);

a. 10 25 b. 25 25 c. 10 10 ans::b d. Compiler Error 23. Arrange the code in order to delete a node being pointer by temp. a) b) c) free(temp) temp->prev->next = temp->next temp->next->prev = temp->prev;

a) b c a

b) c b a

ans::d 24. What does below code do, if temp is pointing to a node other than first and last node

c) a b c d) both a and b

temp -> prev ->next = temp ->next;

temp ->next -> prev = temp -> prev; a) b) c) ans::c no effect inserts a node deletes a node

d)

shuffling of pointers

25. which is the faster traversable dynamically growing list

a) Binary Search Tree

b) Singly Linked List

(a)Compile-Time Error (c)9 8 7 6 6 Ans:d 4. void main()

(b)10 9 8 7 6 (d)10 8 7 6 6

c) Doubly Linked List d) Using Array ans::c 1. void main()

{ int i, n =10; for (i=1; i<n--; i+=2) printf("%d", n-i); } (a)84 (c)852 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; (b)840 (d)864

174

D. 5 10 E. 56

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. Which of the following is not a storage class in C? B. Stack C. Register D. Extern E. Static Ans::a 9. What is the significance of the free() function? A. It assigns the pointer a NULL value B. It erases the contents of any type and cleans the C. It places the memory address with the pointer in free D. It disables the memory address with the pointer Ans::a 10. 5 What is the data type of FILE? store pointer

A. Hello Genesis B. 13 Hello Genesis C. Hello Genesis 13 D. None of the above 6. #include <stdio.h> main() {

switch (5) {

case 5: printf(" 5 ");

default: printf(" 10 "); case 6: printf(" 6 ");

B.

C. 5 10 6

A. integer B. C. pointer union

175

ans:c 14. Which of the following function does not support dynamic memory allocation? A. alloc B. realloc C. malloc D. free ans::a 15. What is the output of the program if the input is 103? main() { int p = 234;

D. structure ans::d 11. #include <stdio.h>

#define sq(a) a * a void main() { }

printf("%d", sq(3 + 2));

A. 25 B. C. 10 D. Compilation error Ans::b 12. Which of the following is a non-linear data structure? A. Stack B. Queue D. Tree Ans::d 13. Which of the following function does not return an integer value? B. 11

printf(" %d ", printf("%d", p), scanf("%d", &p));

A. 3 103 B. 103 C. 103 3 D. 103 2 Ans::c 16. Where do we use a 'continue' statement? B. In 'if' statement

C. Linked List

C. In 'switch' statement D. In 'goto' labels E. Ans::d 17. 1. Queue is _________________ None of the above

C. scanf E.

printf

D. strcpy strlen

a) LIFO c) Ans::d 18. FIFO

176

b) LILO d) Both b & c

char s[2]; }; union U ob; what is the size of ob in bytes, a) 4

What is the postfix expression for A + B * C / D E * F/G e) ABC*D/+EFG*/f) g) ABCD/*+EF*G/ABC*D/+EF*G/-

b) 2 c) 8

d) 7 22.

Ans::b 19.

h) None of these.

ans::a

Write one statement equivalent to the following two statements: x=sqr(a); return(x); (a) return(sqr(a)); (b) printf("sqr(a)"); Choose from one of the alternatives

The operation for adding and deleting an entry to a stack is traditionally called: a.add , delete b.append , delete c.insert , delete d.push , pop e. front , rear ans::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/DE*F/G

Ans::b

(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)); Ans:c 24.

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

a) error b) 5 c) 2

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?

d) 0

ans::c 21. union U { int x; float y;

25, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69 a) 69 b) 25 c) 26 d) 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

177

Ans::b 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);

temp = head; {

while (temp->next->next!=NULL) temp = temp ->next;

(a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 Ans::d 4. What will be the output of the following program : int main() {

} temp -> prev -> next = temp -> next; free(temp); a) b)

temp -> next -> prev = temp -> prev;

c) d) ans::c 1.

no effect deletes some node

deletes 2nd last node deletes last node

else printf("Failure"); return(0);

if ((printf("%s",str)) == 4) printf("Success");

char str[]="Test";

} a)Success b)TestSuccess c)Compile-Time Error(d)Failure ans::b 5. What will be the output of the following program: int main() { int val=5;

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 Ans::c

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

2. #define Compute(x,y,z) (x+y-z) int main() {

(a)Compile-Time Error (b)Lvalue required Error (c)10 (d)11 Ans::c 6.

int x=2,y=3,z=4;

y+z)));

printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(return(0); } (d)None of these

{ printf("%d",sizeof(int)); return(0); }

void main()

(a)40 (b)30 (c)Compile-Time Error

(a)Data types not allowed (b)Compile-Time Error(c)3 (d)2 Ans::2

7.

178

In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) malloc (d) Queue Ans:b
8.

Traverse the given tree using Inorder, Preorder and Postorder traversals.

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


a. Ans:c 10. 4321 b. 4 3 2 1 0 c. 5 4 3 2 1 d. 0 0 0 0 0

Given tree: A

#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name);

}
b.

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

a)Inorder : Preorder: Postorder:

DHBEAFCIGJ

ABDHECFGIJ HDEBFIJGCA DHBEAFCIGJ DHEABCFGIJ

Ans::s #include<stdio.h> main() { const int i=4; float j; j = ++i; } a. 11.

b)Inorder : Preorder: Postorder:

HDEBFIJGCA DHBEAFCIGJ ABDHECFGIJ HDEBFIJGAC

c)Inorder : Preorder: Postorder: d)Inorder : Preorder: Postorder: Ans:a 9.

printf("%d %f", i,++j);

HDBEAFCIGJ ABDHECFGIJ HDEBFIJGCA

5 6.000000 compiler error

b. 5 5.000000 c. 6 6.000000 d.

Ans::d 12.

void main()

179
int k=ret(sizeof(float)); printf("\n %d",++k);

} {

b. Ans:d 16.

} 0 b. 0 1 2

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

int ret(int ret) ret += 2.5;

#define MESS junk main() { printf(MESS); b. Error c. MESS d. MESS junk

a. Ans::d 13.

} Compiler Error b. 8

return(ret);

c. 6 d. 7 a.

} Junk

int swap(int *a,int *b) { } main() {

Ans:c 17. { main () int i = 5; switch (i) { static int i; i = 3; i = i * i; case 3:

*a=*a+*b;*b=*a-*b;*a=*a-*b;

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:a 14.

case 4: case 5:

i = i + i; i = i + i; i = i + i; printf (%d,i);

main()

char *p = ayqm; char c; c = ++*p++; }

printf (%d,i); a. 9 b. 10 10 c. 0 5 d. 18 18 e. 18 5

a. ans:b 15.

} b. b c. y d. z

printf(%c,c);

Ans:c 18.

main()

What would be the output of the following program. Int fn(int); { main() {

float i=1.5; switch(i) {

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

case 1: printf("1"); case 2: printf("2"); default : printf("0"); fn(int i) {

return ++i; (a) 10 (b) 11 (c) 12

180

21. what type of Binary Tree is the following tree below

(d) Compilation error Ans:a 19.

main() { FILE *fp1,*fp2; fp1=fopen("one","w"); fputc('A',fp1) ; fputc('B',fp2) ; fclose(fp1) ; fclose(fp2) ;

fp2=fopen("one","w") ;

G
a. b. c. d. ans:d 22.

binary tree strictly binary tree not a binary tree

complete binary tree

Find the Error, If Any? a. no error. But It will over writes on same file. no error. But It will create one more file. error. It will not allow. file.

b. c.

If suppose root to be deleted then which node will be the root node

d.

no error. The new content will append in existing

Ans:a 20. void main() { int a=555,*ptr=&a,b=*ptr; printf("%d %d %d",++a,--b,*ptr++); } (a)Compile-Time Error (c)556 554 555 Ans:c (b)555 554 555 (d)557 554 555 Ans:a a. B

b. c. d.

G Any node Both a and b are correct

181
23. When fopen() fails to open a file it returns } }

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

ans:a 24.

a) NULL b) 1 c) 1 d) None of the above

printf("%d",x);

Predict the output 20 40 Which function is used to detect the end of file 40 20 40 20 3.

a) EOF b) feof( ) c) ferror( ) d) NULL ans:b 25.

#include<stdio.h> main() {

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

extern int a;

printf("\n %d",a); } int a=20; Predict the output 20

1.

#include<stdio.h>

0 Garbage value Error 4.

int x=40; main() {

int x = 20;

#include<stdio.h>--------------------------------doubt main() {

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

struct emp { char name[20]; int age; float sal;

Predict the output 20 40 20, 40

None of the above 2.

};

struct emp e={"Raja"}; }

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

printf("\n %d %f", e.age, e.sal);

0 0.000000

Garbage values

Error None of the above

182
5.

#include<stdio.h> main() {

o\p:

default value 8.

int x=10, y=20, z=5, i; i= x < y < z; printf("%d", i);

#include<stdio.h>------------doubt main() {

} o\p: 1

int i=1; while() { printf("%d", i++); if (i >10) { } break;

6. Which of the following definition is correct? int length char int

int long float double ans::1 7. What will be the output #include<stdio.h> main() { int i=4; switch (i) { default:

Ans::Error

9. #include<stdio.h>------------------------------doubt main() {

int x=30, y =40; if (x==y)

printf("Default Value \n");

printf("X is equal to Y"); else if (x>y)

printf("x is greater than Y");

case 1:

printf("Value is 1 \n"); break;

else if (x<y) printf("X is less than Y");

Ans: X is less than Y

case 2:

printf("Value is 2 \n"); break;

case 3:

printf("Value is 3 \n"); break;

10.

#include<stdio.h> main()

183
int i=10, j=15; if(i%2= = j%3) { } printf("Same"); 13.

#include<stdio.h> main() { float fval=7.29;

else { }

printf("Different err");

} o\p same 11.

} o\p 7 14.

printf("%d" ,fval);

#include<stdio.h>------------doubt main() { int x=4, y, z; y=--x; z= x--; } Output: 433 432 332 233

#include<stdio.h>-----------------------doubt main() {

printf("%d %d %d", x,y,z);

printf("Welcome"); main();

How many times the program will execute? Ans:Infinte

223 Ans::233 12. #include<stdio.h> main() { float a = 0.7; if (a<0.7) {

15. #include<stdio.h>----------------------doubt void fun(char *);

} else { }

printf("C");

void main() { char a[100]; a[0] = 'A', a[1] = 'B'; fun(&a[0]);

printf("C++");

a[2] = 'C', a[3] = 'D'; }

} Try with 0.7f o\p c++

void fun(char *a)

184
a++; a++;

{ char sentence[80]; int i; printf("Enter the line of text"); gets(sentence); { } for(i=strlen(sentence)-1;i>=0;i--) putchar(sentence[i]);

printf("%c", *a); printf("%c", *a);

o\p b c 16.

#include<stdio.h> #define MESS "Junk" main() { printf("MESS");

21 #include<stdio.h>-----------------------doubt 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);

} o\p mess

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

char str[] = "Sales\0man\0"; printf("%d", strlen(str));

1. Which of the following does not have an unary operator? 1) -7 3) j 2) ++i 4) all of the

o\p 5 19. #include<stdio.h> main() { char str[] = "Sales\0man\0"; printf("%d", sizeof(str));

above

2. In printf(),the appearance of the output of the output can be affected by 1) field with character 3) flag above 2) conversion 4) all of the

} o\p 11 20

3. Any of the following programs in c has access to three standard files: 1) standard input file, standard output file, standard error file 2) stdin,stdout, stderr 3) keyboard,screen,screen 4) all the above

#include<stdio.h>-------------doubt #include<string.h> main()

185
4. The comma operator(,) is used to 1) permit two different expressions to appear in situations where only one expression would ordinarily be used 2) Terminate loops or to exit from switch

4) all have the same type

11) Which of the following array is defined in the statements Char name[30]?

3) alter the normal sequence of program execution by

transferring control to some other part of the program 4) carry out a logical test and then take one of two possible actions, depending upon the outcome of the test

5) name is one dimensiona,30-element integer array

6) name is one dimensional,30-element floating point array 7) name is one dimensional ,30-element character array

5) A variable can be declared static using the keyword. 1) extern 3) stat 4) auto 2) static

8) name is one dimensional,30-elements string array

6) A program can be terminated at any time by calling the function 1) fflush() 3) exit() 2) ferror()

12) c program contains the following declaration: Static float table[2][3]={ {1.1,1.2,1.3}, }; What is the value of *(*(table+1)+1)? 2) 2.2 4) 2.1 2) 1.2 {2.1,2.2,2.3}

4) clearerr()

7) Heap 1) is a region from where memory is allocated 2) lies between you program and the stack 3) is a finite area 4) all of the above 8) A function can 1) perform a task 2) return a value

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 3) 1

3) change value of actual arguments in call by reference 4) all of the above

9) Function definition void check(int i ,char*j) is 1) call by value definition 3) both (1) and (2)

2)18 4) 0

2)call by reference 4)in valid function

14) The declaration : int f(int 1); means 1) f accepts an integer argument and returns an integer quantity 2) f accepts two arguments and returns a double precision quantity, and the second is an integer 3) f accepts three arguments and returns nothing. The first arguments

10) A union consists of a number of elements that 1) all occupy the same space in memory

2) must be structure 3) are grouped next to each other in memory

is a double-precision quantity, and the second is an integer 4) f does not accepts any arguments but returns a single character

186
5) function in the c language

6) data type in the c language 7) keyword in the c language 8) global variable in the c language

15) The c language was developed by 1) Marting Richards 3) Ken Thompson Volt 2) Dennis Ritchie

4) Smith

22)The logical NOT operator represented by ! is a 1) unary operator binary operator 3) ternary operator 2) 4) octal operator

16) The arguments of a function are included between 1) The parenthesis 3) curly braces 4) #

2) double quotes

17) The int type of constraints are whole numbers in the range

23) The statement : scanf(%d,&i); 5) assigns an integer to the variable i 6) gives an error message; 7) does not assign any value to i

1) -23677 to 23678 32768 to 32767 3) -32767 to 32768 32864 to 32864

2) 4) -

8) 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;

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 3) assigns a value 18 to i 19 to i 2) assigns a value 16 to i

4) assigns a value

25)The null character is represented by 1) \n 2)\0 3)\o

19) In a relational expression involving characters, we actually Compare

4)\t

26) The members in the union 1) have different memory locations

5) the ASCII codes of the characters 6) the characters themselves 7) neither of the two

8) binary code and hexadecimal code 20) The getchar function is used to 1) print the ASCII code of the character 3) to print a character on the screen 4) all of the above

2) share the memory with a structure 3) have the same memory location 4) have different memory variable

27) The global variables by default belong to 1) the register type 3) the auto type 2) the static type

2) to assign a character typed at the keyboard to a variable

4) the dynamic type

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

21) The word case used in the switch statement represents a

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

3) character string

4) control string

3) statements

35) The advantage of a switch statement over an else-if construct is

1) a default condition can be used in the switch 2) the switch is easier to understand 3) several different conditions can cause one set of statements to executed in a switch 4) several different statements can be executed for each case 30) A fields width specifier in a printf() function 1) specifies the maximum value of a number in a switch

2) controls the size of type used to print numbers 3) controls the merging of the program listing number 4) specifies how many characters positions will be used for a

36) The header file math.h can be used for 1) providing links to assembly-language for calls 2) providing diagnostic and debugging assistance 3) providing support for the string handling functions 4) none of the above

31) The two operators && and || are 1) arithmetic operators operators 3) logical operators operators 2) equality 4) relational

37) The malloc() function 1) returns a pointer to the allocated memory

32) The library files that come with c are 1) text editor for program development 2) the compiler and liker 3) program examples

2) returns a pointer to the first byte of region of memory 3) changes the size of the allocated memory 4) deallocates the memory

38) which of the following expressions will return a 1 if both bits have A value of 1; otherwise will return a value of 0? 1) AND 2)OR

4) files that contain functions which carry out various commonly Used operations and calculations 33) precedence determines which operator 1) is evaluated first 3) is fastest number 2) is most important

3)XOR 4)1stderr complement

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

4) operates on the largest

4) not defined

34) The string containing certain required formatting information is called

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

1) argument

2) character array

41) One of the valid keywords in the c language is

1) printf

2) CHAR

3) auto

4) scanf

188

5) a member of some other structure 6) a member of the same structure 7) a member of a union 8) all of the above

42) The comments in a c language program are placed between

1) \* and /* /*and*/

4) # and #

2) / and .*

3)

43) If p and q are assigned the values 2 and 3 respectively then the statement p=q++

50) Masking is used 1) to copy a portion of a given bit pattern to a new

1) gives an error message 3) assigns a value 3 to p 5 to p

2) assigns a value 4 to p

4) assigns a value

variable, while the remainder of the new variable is filled with 0s(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 1s (using the bitwise OR) 3) to copy a portion of a given bit pattern to a new is inverted within the new variable 4) all of the above

44) A compound statement is a group of statement included between a pair of 1) double quots 3) parentesis

2) curly braces 4) / and/

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

variable, while the remainder of the original bit pattern

51) Almost every c program begins with the statement 1) main() 2) printf() 4) scanf() 3) #include<stdio.h>

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

52) A single character input from the keyboard can be obtained by using the function 1) printf( ) ) 2) getchar( ) 3) putchar( ) 4) scanf(

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

48) A string in the c language is represented by enclosing a series of characters in 1) single quotes 3) parenthesis

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 characters

2) double quotes 4) / and /

49) One structure cannot be

7) causes the computer to carry out some action 8) all of the above

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

189

3) gives the current position in the file

4) sets the position to the beginning of the file 60) A c function contain 1)function body 2)argument declaration 4)all of the above

8) I to be incremented by 1

3)a function header 1.int a=123.12; c=a+b;

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

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

3) scanf( ) and putchar( ) 4) getchar( ) and putchar( )

b) 123.12 c) 246.24 d) None of these

56) The conversion character I for data output means that the Data item is displayed as

5) a floating point value with an exponent 6) an unsigned decimal integer 7) a signed decimal integer 8) an octal integer

2. struct emp { char *name; }; int a;

57) The header file ctype.h can be used for 1) providing links to assembly language for calls 2) providing diagnostic and debugging assistance

main() {

3) providing support for string handling functions 4) providing character type identification (Boolean) and translation

ANs: 2

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

struct emp *e;

3. which is the best thing for linked list than arrays? i) Insertion ii) Deletion

58) In a circular linked list 5) components are all linked together in some 6) there is no beginning and no end sequential manner

iii) Traversal a) (i) only

7) components are arranged hierarchically

b) (i),(ii) only c) ii,iii only d) iii only

8) forward and backward transversal within the list is permitted 59) The function ftell( ) 1) reads a character from a file 2) reads an integer form a file

4. consider the character array of size 10. When a string is more than 10 a) Error

b) Overwrites c) Nothing d) garbage value

190
a) hello world

b) Compiler error c) Runtime error ans::a d) None of the above

5. main() { char *str;

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

char *fun(); str=fun(); }

printf("%s",str);

8) int a; a=65536; printf("%d",a); a) 0 b) Garbage c) 65535 d) -32768

char * fun() {

char *buffer; strcpy(buffer,"Hello world"); return buffer;

a) hello world

b) Compiler error

9) main() { char p=65; printf("%c",p);

c) Runtime error d) None of the above 6. main() { char *str; char *fun();

a) 65 b) p c) error d) none of the above 10) In a function call, _____________ is passed as arguments. a) variables

str=fun(); printf("%s",str);

b) constants

char * fun()

c) Expressions

{ char *buffer;

d) All the above 11) The value of EOF is ___-1______. 12) () is used for __________ a) function body b) Arguments

buffer=(char *) malloc(sizeof(char)); strcpy(buffer,"Hello world"); return buffer;

c) Return type

191
18) In a queue,what condition applies a) First In First Out b) Last in first out c) Elements are inserted and deleted at one end ends

d) Declaration of function

13) How does the string ends? a) /n b) /t c) /0

d) Elements can be inserted and deleted in different

d) none 14) The range of Unsigned integer is a) 127 to -128 b) 0 to 65535 c) Depend up on the compiler d) -32768 to 32767 15) which one of the following is a illegal real constants a) 32.535

19) which of the following statements are true in the case of doubly linked list i) Every node is connected to other node

ii) We can traverse in both the directions a) i) only

b)ii) only c) Both i and ii ans::c d) neither i nor ii

b) -1.5E25 to 3.5E65 c) "53682" d) -6.583 16) main() { int i,a[5]; a[1]=5;

20) main() { char str[]="Wipro Infotech"; char *s; s=&str[13]-13; while(*s)

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

} Ans:: Wipro Infotech

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

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

21) char *a="Malayalam"; char *s; Char *str; str=a;

a) 0 0 0 0 0 c) 0 5 0 0 0

b) Garbage value d) Compiler error

s=str+8; for(;s>=str;s--)

printf("%c",*s);

ans:d..base address cant be changed a++ 17) The size of int is 2 bytes,then what is the size of short int? a) 1 b) 2

a) Malayalam

d) None of the above 22) struct main { int a;

b) malayalaM c) error

c) 4 d) 8

int b; }

192

struct main *e1;

c) #define SQRT(int) (int + int)

d) #define SQRT(int) (int) + (int)

printf("%d %d",sizeof(e1),sizeof(*e1));

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

23) #define wipro Hai void main() {

printf("wipro"); }

return p; } main() {

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

what will be the output?

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

Ans::Error Void function do not return a value. a) Compiler Error b) Hello c) Garbage value d)

None

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

29) void main() int *p; p=(int *)malloc(sizeof(int)); for(i=0;i<5;i++) printf("%d ",p[i]); {

26) Queue is used for i) Expression Evaluation

ii) Scheluding the job in First come First serve a) i) only

b) ii only c) both i & ii

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

d) 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);

Ans:6,5

31) Which of these will pass the address of the pointer *ptr to the function demofun()?

printf("%d",j);

a) demofun(ptr) b) demofun(&ptr)

c) demofun(*ptr) d) demofun(*&*ptr);

a) #define SQRT(int) (int * int) b) #define SQRT(int) (int) * (int)

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

193

33) If max=10,rear=max,front=0,then what will be my queue?

queue?

then how will you add a new element called 'item' in the

struct queue *q;

a) Queue Empty c) Queue has one element d) Queue has max-1 elements b) Queue Full

a) q->rear[a]=item;

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

d) q->rear[q->a]=item;

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)); 38) In which of the following we can sort the data without moving the data a) Array b) Single Linked list c) Doubly linked list d) Binary search trees 39) Char d=128; printf("%c",d); a)128

which is correct? i) All Values are intialised to garbage values ii) Creates memory for 10 integer data a) i only

b) ii only c) both i and ii

d) neither i nor ii

b)-128 c) error

d) Garbage values

36) int *ptr; ptr=(int *)calloc(10*sizeof(int)); which is correct? i) All Values are intialised to zero ii) Creates memory for 10 integer data a) i only

40) In the following definition struct node *ptr;

ptr=(struct node *)calloc(sizeof(ptr)); a) ptr is allocated 4 bytes

b) ii only

b) ptr will be allocated sizeof struct node c) Error d) ptr will have 8 bytes

c) both i and ii

d) neither i nor ii

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)

37) Struct queue int rear; {

int front; int a[100];

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,5

194

1.

#include<stdio.h>

b) 5,4,3,2,1 d) none 42) void main() { int b=20;

c) compilation error

int x=40; main() {

int x = 20;

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

what will be the output? ANS::C

printf("%d"*&b++); } a) 21 b)20 c) error d) Garbage value

Predict the output 20 40 20, 40 None of the above 2.

43) how will you refer the last node in the doubly linked list which is pointed by the pointer variable 'cursor'? a)cursor==NULL b)cursor->link=NULL c) Cursor->link=0 d) cursor->data=NULL

#include<stdio.h> main() { int x=40; {

} 44) how will you refer the previous node of the pointer }

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

printf("%d",x);

'cursor' in the doubly linked list (cursor is not in the first or in the last)? a)cursor->link++ b)cursor=cursor->left c) Cursor++ d) cursor->left++

Predict the output 20 40 40 20 40 20 3.

#include<stdio.h> main() {

extern int a; printf("\n %d",a);

int a=20; Predict the output

20 0 Garbage value Error 4.

195

main() { int i=4; switch (i) {

#include<stdio.h>--------------------------------doubt main() {

default:

printf("Default Value \n");

struct emp { char name[20]; int age; float sal;

case 1:

printf("Value is 1 \n"); break;

};

case 2: printf("Value is 2 \n"); break; case 3:

struct emp e={"Raja"}; printf("\n %d %f", e.age, e.sal);

0 0.000000

printf("Value is 3 \n"); break;

Garbage values Error

None of the above 5.

} }o\p default value 8. #include<stdio.h>------------doubt main() { int i=1; while() {

#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 length char int int long

printf("%d", i++); if (i >10) { } break;

float double 7. What will be the output #include<stdio.h> } 9.

#include<stdio.h>------------------------------doubt main() {

196

} Output: 433 432 332 233 223 12.

int x=30, y =40; if (x==y)

elseif (x>y) printf("x is greater than Y"); elseif (x<y) } printf("X is less than Y");

printf("X is equal to Y");

#include<stdio.h> main() {

Statement missing Lvalue required

Expression Syntax RValue required 10.

float a = 0.7; if (a<0.7) { }

printf("C");

#include<stdio.h> main() { int i=10, j=15; if(i%2 = j%3) { } else { } } 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);

else {

} } Try with 0.7f o\p c++

printf("C++");

printf("Same"); 13. printf("Different err");

#include<stdio.h> main() { float fval=7.29; printf("%d" ,fval);

}o\p 7 14.

#include<stdio.h>-----------------------doubt main() { printf("Welcome"); main();

197
How many times the program will execute? 32767 65535 Till the stack doesnt overflow 15. #include<stdio.h>----------------------doubt void fun(char *);

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

void main() { char a[100]; a[0] = 'A', a[1] = 'B'; a[2] = 'C', a[3] = 'D'; fun(&a[0]);

#include<stdio.h>-------------doubt #include<string.h> main() { char sentence[80]; int i;

void fun(char *a) {

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

printf("Enter the line of text"); gets(sentence);

for(i=strlen(sentence)-1;i>=0;i--) { } putchar(sentence[i]);

} o\p b c 16.

#include<stdio.h> #define MESS "Junk" main() { printf("MESS");

21 #include<stdio.h>-----------------------doubt main() { float a=3.15529;

}o\p mess

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

18.

#include<stdio.h> main()

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

198
2. int i=5; fun( ) { } {

char a[]="123abcd"; clrscr(); getch(); } printf("%d",strlen(a));

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

main( ) int i= 2; { int i = 3; fun(); } 3, 15 3, 6 3 0

a.

b. c.

6 7 8 5

d. 6. main()

printf(" %d", i);

{ static int var=5; if(var--) {

f. g. h. i.

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

3. #define xsq(x) x*x main( ) {

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

int i, j;

i = 5; j = xsq(i-2); } e. 7 f. g.

d. 5 4 3 2 1 0 7. void main() { int i=1,j=2; switch(i) {

printf(%d\n, j);

h. 4. main( ) {

9 13 29

case 1: printf("One"); break; case j: printf("Two"); break; default: printf(Default); break; int a=35; } }

printf( %d %d %d\n, a == } 35,a=50,a>40); a. b. c. d. 5. void main() { 1 50 1 1 50 0 0 50 0 0 50 1

a. One

b. Two

c. Default

d. Compiler Error 8. void main() { switch('a')

{ case 'A': printf("Zero"); break;

case 97: printf("One"); } } a. Zero b. One c. Error d. Compiler Error 9. void main() { int p=1,sum=0; clrscr(); while(p<20) { p++;

default: printf("Error");

break;

break;

199

changevalue(x); }

printf("\nSecond output : %d",x);

a. 12 12 c. 12 13

b. 11 12 d. 13 13 11. main() { static i=3;

printf("%d",i--); return i>0?main():0; }

sum+=p++; }

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

printf("\nsum=%d",sum); } a. 120 b. 100

12. void main()

c. 110 d. Error 10. int x; int modifyvalue() { return(x+=10); }

{ char *ptr="Hello World"; *ptr++; printf("%s",ptr); ptr++; printf("%s",ptr); } a. Iello World c. ello World d. ello World 13. int const *p; *p=5; printf("%d",*p++); a. 5 b. 6 Iello World ello World llo World

b. Hello World ello World

int changevalue(int x) { return(x+=1); }

void main() { int x=10; x++; x++;

changevalue(x); modifyvalue(); printf("First output : %d",x);

c. Compiler Error d. Garbage Value 14. void main() {

char *str1="abcd";

200

char str2[]="abcd"; }

printf("%s\n",ptr); ptr++; } printf("%s",ptr);

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

a. 5 5 3 b. 4 5 3 c. 2 5 3 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 2 b. 2 1 c. 2 2

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

18. #define square(x) x*x void main() { int i=7;

clrscr();

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

d. 1 1 16. void main() { char **p; p=s;

char *s[]={"dharma","hewlet-packard","siemens","ibm"};

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

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

19. #define man(x,y) (x)>(y)?(printf("%d",x)):(y) void main()

a. harma harma

{ int i=15,j=10,k=0;

ewlet-packard

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

b. dharma harma

ewlet-packard c. harma siemens

a. 16 17 11 2

hewlet-packard

b. 17 17 11 2 c. 16 16 11 2

d. 16 17 12 2 20. struct one { int no:1; int pl:2; int x:3; };

d. harma

harma hewlet-packard

17. void main() { char *ptr="Ramco Systems"; (*ptr)++;

void main()

201

struct one a; a.no=0; a.pl=1; a.x=3;

main() { printf("Enter 1 values:");

};

int a;

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 3 3 b. 0 0 1 1

scanf("%d%d",&emp1.a,&emp1.a); //The given input is 10 and 25 printf("a=%d a=%d",emp1.a,emp1.a); } a. 10 25

b. 25 25

2 2 3 3

c. 10 10 d. Compiler Error 23. Arrange the code in order to delete a node being pointer by temp. a) free(temp)

c. 1 1

d. 1 1 2 2 2 2

2 2 3 3

b) c)

temp->prev->next = temp->next temp->next->prev = temp->prev;

21. void main() { struct emp { struct e { int *a; }e1; int a; }; struct emp emp1; printf("%d %d",sizeof(emp1),sizeof(emp1.e1)); }

a) b c a

b) c b a c) a b c

d) both a and b 24. 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) b) c) d) no effect inserts a node

deletes a node

a. 2 4

shuffling of pointers

b. 2 2 c. 4 4

25. which is the faster traversable dynamically growing list

d. 4 2 22. struct emp emp1; struct emp {

a) Binary Search Tree

b) Singly Linked List

c) Doubly Linked List d) Using Array

202
4. 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 (c)0 3 -1 (b)Compile-Time Error (d)0 3 0 5. 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 (c)a=6 b=0 (b)a=6 b=5 (d)None of these 6. #include <stdio.h> main() { switch (5) { } What is the output of the program? #include <stdio.h> int main(int argc, char *argv[]) { printf(" %d", printf("Hello Genesis")); return 0; } (a)84 (c)852 (b)840 (d)864 void main() { int i, n =10; for (i=1; i<n--; i+=2) printf("%d", n-i);

E. F.

G. Hello Genesis 13 H. None of the above

Hello Genesis 13 Hello Genesis

3. void main() { int i=5; printf("%d %d %d %d %d",++i,i++,i++,i++,++i); } (a)Compile-Time Error (c)9 8 7 6 6 (b)10 9 8 7 6 (d)10 8 7 6 6

case 5: printf(" 5 "); case 6: printf(" 6 ");

default: printf(" 10 "); }

F.

G. 5 10 6 H. 5 10 I. 7. Which argument of function 'strncmp()' specifies number of characters to be compared? E. F. first 56

203

#include <stdio.h>

#define sq(a) a * a void main() { } printf("%d", sq(3 + 2));

E. F.

25 11

G. 10

G. between 2 strings H. third 8. Which of the following is not a storage class in C? F. Stack G. Register H. Extern I. 9. What is the significance of the free() function? E. F. It assigns the pointer a NULL value Static

second

H. Compilation error 12. Which of the following is a non-linear data structure? E. F. Stack

G. Linked List H. Tree 13. Which of the following function does not return an integer value? F. printf

Queue

G. scanf

It erases the contents of any type and cleans the pointer store 14.

H. strcpy I. strlen

G. It places the memory address with the pointer in free H. It disables the memory address with the pointer 10. What is the data type of FILE? E. F. integer union

Which of the following function does not support dynamic memory allocation? E. F. alloc

G. malloc H. free 15.

realloc

G. pointer H. structure 11.

What is the output of the program if the input is 103? main() { int p = 234;

204

(d) printf("%d",sqr(a)); 20.

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

printf(" %d ", printf("%d", p), scanf("%d", &p));

E. F.

3 103 103

G. 103 3 H. 103 2 16. Where do we use a 'continue' statement? F. In 'if' statement

main() int i=4;

printf("%d",abc(i=i/4));

a) error b) 5 c) 2 d) 0 21. union U {

G. In 'switch' statement H. In 'goto' labels I. None of the above 17. 2. Queue is _________________ a) LIFO c) FIFO

int x;

float y; char s[2];

b) LILO d) Both b & c 18.

}; union U ob; what is the size of ob in bytes, a) 4 c) 8

What is the postfix expression for A + B * C / D E * F/G i) j) ABC*D/+EFG*/ABC*D/+EF*G/-

b) 2 d) 7 22. The operation for adding and deleting an entry to a stack is traditionally called: a.add , delete b.append , delete c.insert , delete

k) ABCD/*+EF*G/l) None of these. 19.

Write one statement equivalent to the following two statements: x=sqr(a); return(x); (a) return(sqr(a)); Choose from one of the alternatives (b) printf("sqr(a)"); (c) return(a*a);

d.push , pop e. 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/DE*F/G

205

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 }

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

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?

2.

#define Compute(x,y,z) (x+y-z) int main() {

25, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69 e) 69 f) 25 g) 26 h) 9

y+z)));

int x=2,y=3,z=4; printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(return(0); (d)None of these

(a)40 (b)30 (c)Compile-Time Error

3. 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

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

int val=5; val=printf("C") + printf("Skills"); printf("%d",val);

temp = head;

while (temp->next->next!=NULL) { } temp = temp ->next;

(a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 4.

return(0); }

temp -> prev -> next = temp -> next;

What will be the output of the following program : int main() { char str[]="Test"; printf("Success"); printf("Failure"); return(0);

temp -> next -> prev = temp -> prev; free(temp); a) no effect

if ((printf("%s",str)) == 4)

b) c) d)

deletes some node deletes 2nd last node deletes last node

else

a)Success b)TestSuccess c)Compile-Time Error(d)Failure

206
a)Inorder : Preorder: Postorder: b)Inorder : Preorder: Postorder: c)Inorder : Preorder: Postorder: d)Inorder : Preorder: Postorder: DHBEAFCIGJ ABDHECFGIJ HDEBFIJGCA DHBEAFCIGJ DHEABCFGIJ HDEBFIJGCA DHBEAFCIGJ ABDHECFGIJ HDEBFIJGAC

5.

What will be the output of the following program: { int val=5; int main()

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

(a)Compile-Time Error (b)Lvalue required Error (c)10 (d)11 6. { printf("%d",sizeof(int)); return(0); } void main()

HDBEAFCIGJ ABDHECFGIJ HDEBFIJGCA

9.

(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.

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


b. 4321 b. 4 3 2 1 0 c. 5 4 3 2 1 d. 0 0 0 0 0

Traverse the given tree using Inorder, Preorder and Postorder traversals.

10.

Given tree: A

#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name);

G
}

c.

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

207
11.

c = ++*p++; } b. b c. y d. z

#include<stdio.h> main() {

printf(%c,c);

b.

const int i=4; float j; j = ++i; printf("%d %f", i,++j);

15.

main()

} b.

float i=1.5; switch(i) {

5 6.000000 compiler error

b. 5 5.000000 c. 6 6.000000 d.

case 1: printf("1");

12.

void main() { int k=ret(sizeof(float)); printf("\n %d",++k); 16. c.

} } 0 b. 0 1 2

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

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

} {

int ret(int ret) ret += 2.5; return(ret); c. 6 d. 7

#define MESS junk main() { } Junk

b. 13.

printf(MESS); b. Error c. MESS d. MESS junk

Compiler Error b. 8

b.

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

17. main () { int i = 5; switch (i) { static int i; i = 3; i = i * i; case 3: case 4: case 5:

main() int x=10,y=20; swap(&x,&y);

printf("x= %d y = %d\n",x,y); c. 20 10 b. 10 20 c. 20 20 d. 10 10

i = i + i; i = i + i; i = i + i;

14.

main()

printf (%d,i); char *p = ayqm; char c; } printf (%d,i);

208
b. 9 b. 10 10 c. 0 5 d. 18 18 e. 18 5

{ int a=555,*ptr=&a,b=*ptr; printf("%d %d %d",++a,--b,*ptr++); } (a)Compile-Time Error (b)555 554 555

18. What would be the output of the following program. Int fn(int); main()

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

(c)556 554 555

(d)557 554 555

fn(int i) {

21.what type of Binary Tree is the following tree below

return ++i; (b) 11 (c) 12

(d) Compilation error 19. main() { FILE *fp1,*fp2; fp1=fopen("one","w");

} (a) 10

H
e. f. g. h.

binary tree

strictly binary tree

fp2=fopen("one","w") ; fputc('A',fp1) ; fputc('B',fp2) ; fclose(fp1) ; } fclose(fp2) ;

complete binary tree not a binary tree

22. If suppose root to be deleted then which node will be the root node

Find the Error, If Any? e. f. no error. But It will over writes on same file. no error. But It will create one more file. error. It will not allow. file. no error. The new content will append in existing

g.

h.

20.void main()

209 A

i=i&=j&&10;

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

ans::1 10

3.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);

J
}

e. f. g.

ans::0 0 1 3 1 3.28. main() { int i=4,j=7;

h. 23.

Any node

Both a and b are correct

a) NULL b) 1 c) 1 d) None of the above 24.

When fopen() fails to open a file it returns

j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j);

ans::4 1 3.29 main() {

a) EOF b) feof( ) c) ferror( ) d) NULL

Which function is used to detect the end of file

int a=500,b=100,c=300,d=40,e=19;

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

a+=b-=c*=d/=e%=5; printf("%d %d %d %d %d",a,b,c,d,e);

2.main( ) { int k=35;

printf( %d %d %d\n, k == 35,k=50,k>40); } ans::0 5 0 3.main( ) {

1.main() { int x,y,z; x=y=z=1;

int x=4,y,z; y = --x; z = x--; printf(%d %d %d\n,x,y,z);

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

printf("%d %d %d",x,y,z); 2.13. main()

ans:2 3 3 1.6. main()

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

int a=1,b=2,c=3,d=4; clrscr(); printf("%d\n",!a?b?!c:!d:a); return(0);

ans::0

printf("%d %d %d %d",a,b,c,d); }

1.20. main()

{ int i=-1; +i; } printf("i = %d, +i = %d \n",i,+i);

5.main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

ans -1,-1 1.34. #include<conio.h> main() {

int x,y=2,z,a;

if(x=y%2) z=2; a=2; } {

1. main()

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

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

1.42. main() int i=10,j=20;

j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); } 3.4. main() { int i=5;

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

char a[]="abcdef"; char *p=a; clrscr();

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

p++; p++;

p[2]='z'; printf("%s",p); getch(); }

ans::cdzf 2.6. main() { char *str1="abcd";

return 0; }

int main()

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

char str2[]="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]);

211

str=p;

str1=s; }

printf("%d",++*p + ++*str1-32);

3.6. main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t;

ans:: m m m n n n 1.7. #define square(x) x*x main() { int i; a a a

t=names[3];

names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) } printf("%s",names[i]);

} ans::64

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

ans::Lvalue Required.....base address can't be changed names[3]=names[4];

1.7.2 #define cube(x) x*x*x main() { int b=3,a;

1)Allocating a 2 blocks of memory for 'n' intgers is by using a) malloc b) calloc

a=cube(b++); }

c) both malloc and calloc d) none of the above 2) In queue using linked list, which is correct? a) both insertion and deltionis made at the front end

printf("%d %d",a,b);

ans::27,6 1.8. #include <stdio.h> #define a 10 main() { #define a 50 }

b) insertion is made at the beginning and deletion is made at the last c) insertion is made at the last and deletion is made at the beginning d) both insertion and deltionis made at the back end 3) for(i=0;i<2;i++) { { for(j=0;j<5;j++) if(i==j) break; }

printf("%d",a); ans::50 3.3. #include<stdio.h> main() {

printf("wipro"); }

char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3];

how many times would wipro to be printed? 1 time

212
4) all the local variables are stored in ----------------a) stack b) heap

back=back->left; }

c) queue d) none ans::a

Data Structure Questions & Answers

1)Consider the following structure struct node { int info;

5) Once you call a function,all the return addresses are stored in ---------------a) stack b) heap

c) queue d) none 6) Which of the following is true about binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. a) i only b)ii only

};

struct node *link;

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;

Suppose ptr is a pointer which is not pointing to the

c) both i and ii

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

d) neither i nor ii 7) Which of the following is true about complete binary tree i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and lesser than the right sub tree. a) i only b)ii only c) both i and ii 2) Consider the following structure struct node { int info; struct node *link;

};

d) neither i nor ii 8) struct node { int data; }; 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,

struct node *left,*right; suppose start and end are the pointers pointing to the

beginning and ending node reapectively.then,what will be the output of the following snippet front=start; back=end;

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 node

while(back!=NULL)

{ printf("%d",back->data);

b) It is a circular linked list c) It is a doubly linked list d) None of the above

213

c) 20

d) 15

9) The infix expression is a+b*(c-d)/(e+f)*h then my postfix 3) In a queue, if rear=front then what will be the queue a) Queue is empty b) Queue is full expression is a) ab+cd-*ef+h*/ b) abcd-ef+*/h* c) abcd-*ef+/h*+

c) Queue has only one element d) None of the above

d) abcdef+-*/h*+ 10) In the stack, if top=0 then the stack is a) Stack is empty b) Stack is full

4) In a queue, if rear=0, front=0 then what will be the queue a) Queue is empty b) Queue is full

c) Stack has only one element d) None of the above

c) Queue has only one element d) None of the above

5) In a queue, if rear=0, front=1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) Queue is circular

11) Consider the structure struct node int info; struct node *left; struct node *right; }; {

6) In a queue,if rear=-1,front=-1 then what will be the queue a) Queue is empty b) Queue is full c) Queue has only one element d) None of the above

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

7) In a queue, if rear=max-1, front=0 then what will be the queue a) Queue is empty b) Queue is full

c) Queue has only one element d) None of the above

a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values

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

12)

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

}; Suppose nd is a node which is not in the beginning

214

d)

>left;free(ptr);

ptr->left->right=ptr->left;ptr->left->right=ptr-

and also not in the end. How will you delete a node after nd? a)

>right;

nd->right=nd->right->left;nd->right->left=nd->left-

15)

struct node { int data;

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;

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. 13) struct node { int data; struct node *left,*right; Here is the coding: ii) nd->left=ptr;

i) ptr->right->left=nd; iii) ptr->right=nd;

};

iv) nd->right=ptr->right; Then what sequence does it follows for inserting nd after ptr? a) i,ii,iii,iv

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)

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

nd->left=nd->right->left;nd->right->left=nd->left-

b) ii,iv,i,iii c)iv,iii,ii,i

d) 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) + c) * d) /

14)

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

b) -

};

and also not in the end. How will you delete a node ptr?

Suppose ptr is a node which is not in the beginning

17) Consider a binary search tree insert(10,root); insert(25,root); insert(5,root); insert(8,root);

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

insert(13,root); insert(45,root); insert(70,root);

insert(32,root); insert(66,root); insert(13,root); insert(36,root);

215

delete(13,root);

int a = -1,b=2,c=3,d=4;

printf(%d %d %d %d,a,b,c,d); (a) 0 3 4 1 } (b) 1 3 4 5

d=++a||++b&&++c;

What will be the preorder traversal is a) 5,8,10,13,25,32,36,45,66,70 c) 10,8,5,13,32,45,36,66,32,70

(c)1 3 4 0 (d) 1 2 3 4 void main() {

3. What will be the output of the following program :

b) 10,5,8,25,13,45,32,36,70,66 d) 8,5,32,36,10,66,45,70,25,13

char line[80]; // Max. length=80 Chars scanf("%[^,]s",line); printf("\n%s",line);

INPUT :Dear,how, are, you

19) The preorder traversal is 5, 3, 66, 30, 77, 70 .What will be the root node a) 5 b) 66 c) 70 d) 30 20) Which one of the following is true for the binary tree i) root is greater than the left sub tree and lesser than the right sub tree ii) root is lesser than the left sub tree and greater than the right sub tree

(a)Compile Error (b)Dear Friends (c) dear (d) runtime error 4.. 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 run time error void main() { }

b) h , e , l (c ) compile time error (d)

5) What will be the output of the following program :

a) only i b) only ii c) both i and ii

printf();

d) Neither i nor ii

(a)Run-Time Error

Output (d)None of these

(b)Compile-Time Error

(c)No

1. What will be the output of the following program : { printf("%f",123); (a)123 } (b)Compile-Time Error void main()

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

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

(c)123.00

(d)123.000000

of these

(b)Compile Error

(c)%d

(d)None

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

7) void main() { int val=5;

(a)

printf("%*d",val); (d)None of these (b)5

216
(a) 2,5 (b) 2,5.4 (c) 2,5.000000 (d) none of these

(c)Compile-Time Error

14. int i=10,j=25; Double k; K = j/i;

8. void main() {

printf("Hi!");

Printf(%lf,k); (a) 2 (b) 2.5 (c) 2.499999 (d) invalid type conversion 15. static int choice; switch(++choice,choice+1,choice2,choice+=1)//choice =2 (b)Hi!

} (a)No Output

if (0 || -1) printf("Bye");

(c)Bye

(d)Hi!Bye

9) void main() { } (a)8, 4 (b)4,8 10,. printf("%d %d",sizeof ( 4.56),sizeof(4.56f)); (c)8,8 (d)4,4

statement: (a) 2 (b) 0 (c) invalid switch statement (d) -1

Currently choice will hold what value in Switch

main()

{ for( i=-2;i ; i++) printf(hi\n); } here the loop is performed how many times ?

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;

(a) 2 ( b) 1 ( c) 3 d) infinite 11. ) 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];

(a)0 3 -3 (c)0 3 -1 void main() { if (a > b)

printf("%d %d %d",a,b,c); (b)Compile-Time Error (d)0 3 0

U1.a=5; U1.ch[0]=4 ; u1.ch[1]=2; Printf(%d,a); } BE u1.a ( ans: 516) (a) 5 (b) 42 ( c) 1028 (d) 24

}u1;

17. #define swap(a,b) a=b ;temp=a; ; b=temp; // IT SHOULD static int a=5,b=6,temp;

13. void main() { x = 27 ; int x, y, z;

} b=5

swap(a,b); printf("a=%d b=%d",a,b); (b)a=6 b=5 (c)a=5

(a)a=5 b=6

(d)None of these

18. void main() what value y and z hold currently : { unsigned int val=5;

z=x/5;}

y = x % 5;

printf("%u %u",val,val-21); (b)5 -6 (c)5

217

a++;

65520 (d)None of these 19. a=5,b=6;

(a)Compile-Time error

(a) 1 (b) 2 (c) address of a[0] (d) none of these 26. feof ,NULL , EOF are used for the following commands respectively (a) fgetc,fgets,fread (b) fread, fgetc,fgets (c) fread,

printf(%d,*a);

(++a<++b) ?a:--b; Printf(%d %d,a,b); (a) 5 6 (b) 6 7 20. void main() { int x=4,y=3,z=2; *&z*=*&x**&y; } (c) 5 7 (d) 6 6

fgets,fgetc (d) none of these//ans sud be c

27, . which of the following mode is useful for editing a file ? (a) w+ (b) r+ (c) a+ (d) a 28, the term FILE is a (a) header file (b) Predefined function (c) Predefined int p[3][5] = {

printf("%d",z); }

structure (d) none of these 29,. (b)Run-Time Error (c)24

(a)Compile-Time error

{ 2, 4, 6, 8, 10}, { 3, 6, 9, 12, 15}, { 5, 10, 15, 20, 25}

(d)Unpredictable

21,. char a[2][11]={morning,India) printf(%s, *(a[0]+3)); (a) compile error main() (b) n *22. #define f(g,g2) g##g2 { int var12=100; }

(c) i (d) none of these

}; 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 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( )

printf("%d",f(var,12)); a)compilation error b)runtime error c)100

31. Which data structures used to perform recursion? A. FIFO Structure B.

d)var##12

C. LILO Structure 23,. int I=40; I++; Int *p= i;//there sud be p=&i;

LIFO Structure

D. NON Linear Structure 32. The operation for adding an entry to a stack is traditionally called: a. (c) 40 40 (d) compile time b. c. d. add append insert push

Int *q = i; Printf(%d %d, *p, *q); (b) 41 41

(a) 40 41 error

24. The syntax of a function call statement is a) function name (argument list);

33. I have implemented the queue with a linked list,

b) [storage class] function name (parameter list); c) function name (parameter list); 25. int a[5] = { 1,2,3,4,5}; d) [return type] function name (argument 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. c. d.

Only front_ptr changes. Only rear_ptr changes. Both change.

218

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. c. b. d. -*AB*+CD/PQ AB*CD+PQ/*ABCDPQ-*+*/ *-+*/ABCDPQ

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. b. c. d. Que[0] Que[1] Que[9] Que[10]

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. b. c. d. time. A syntax error always occurs at compilation A run-time error always occurs when the program finishes. The results are unpredictable. A run-time error always occurs when *p is evaluated.

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. c. d. DCBA ABCD DCAB

39. Which of the following stack operations could result in stack Overflow flow? a. b. c. d. is_full pop push Two or more of the above answers

*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. f. g. h. i. 1 2 3 4 5

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. b. Ptr->next->next->data Ptr->next->data Ptr->next->next->next->data Ptr->next->next->next

36. One difference between a queue and a stack is: a. b. c. d. Queues use two ends of the structure; stacks use only one. Queues require dynamic memory, but stacks do not. Stacks require dynamic memory, but queues do not. use only one. Stacks use two ends of the structure, queues

41. A Full Binary Search Tree contains, How many Nodes? (where n is height) a. b. c. n nodes 2^(n-1) nodes 2^n nodes

c. d.

42. A Structure which can refer an another Structure of same type is called as: a. b. Structure within structure Nested structure

d.

(2^n)-1 nodes

c.

43. Suppose think there is a Double linked list with 15 nodes and a pointer Ptr pointing to the Fifth node. to point 3 node data. a. b. c.
th

d.

Self referential structure Dynamic structure

219
47. In a Binary Search tree a new node is always inserted as: a. b. Right child Left child Leaf node Non leaf node

Then which of the following statement will cause Ptr Ptr->next->prior->prior

d.

Ptr->next->next->next Ptr->next->prior->prior->prior Ptr->next->prior->next->prior

c. d.

48. Suppose Ptr needs to point last but one node in a me the result? a. b. c. d. stack? a. b. c. d.

Double linked list. Which of the statement will give Ptr=first->prior Ptr=last->prior Ptr=last->next Ptr=first->next->prior

44. What kind of list is best to access the item at given position n?" a. b. c. d. Doubly-linked lists. Lists implemented with an array. Singly-linked lists. Doubly-linked or singly-linked lists are equally best

49. Which of the following applications may use a A parentheses balancing program. Evolution of postfix expression. Syntax analyzer for a compiler. All of the above.

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? a. b. c. d. e. Ptr == NULL Ptr->link == NULL Ptr->data == NULL Ptr->data == 0.0 None of the above.

1.Consider the following statement :

s= fscanf(infile, %c, &nextChar);

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

what is true about the above statement? A. infile is the name of a file B. 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 only B only infile is the name of a variable of type

a. b. c. d. e.

C only

All of A, B and C

b. c. d.

ptr = last; (ptr); ptr = ptr->prior ptr = last; (ptr); ptr = ptr->next ptr = first; (ptr); ptr = ptr->prior

None of A, B, or C

Answer: b. B only

220
1. Which of the following can be used across files a. c. b. d. extern static volatile const

#define assert(cond) if(!(cond)) \ \n",#cond,\

(fprintf(stderr, "assertion failed: %s, file %s, line %d

__FILE__,__LINE__), abort())

void main() { int i = 10; if(i==0) else macro");

Answer: a 2. When fopen() fails to open a file it returns _______ a. b. NULL -1

assert(i < 100); printf("This statement becomes else for if in assert

c. d.

1 None of the above

Answer: a. NULL 3. The EOF is equivalent to a. -1 b. c. 1 0

a. c.

b. d.

no output error else part is printed

prints assertion failed in the file

Answer: c

d.

Answer: a 4.

None of the above

#include<stdio.h> main() {

What will be the output of following code assuming file already exists with some contents

7. What will be the output of the following code segmet FILE *fp1,*fp2;

FILE *ptr; char i;

fp1=fopen("one","w") ; fp2=fopen("one","w") ; fputc('A',fp1) ; fputc('B',fp2) ; fclose(fp1) ;

ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF); printf("%c",i); }

fclose(fp2) ; a. No Error, but it will over writes on b. c. d. same file Error in pointer declaration Runs successfully None

a. c.

b.

contents of zzz.c error contents of zzz.c followed by an infinite loop prints some data after EOF reaches.

d.

Answer: C 8. Considering the code Char x[20]; ----

6. what is the output of the following

Answer: D

----fgets(x,20,fp);

printf(%s,x);

221

the data in the following format wipro innovation program

where fp points to the file which contains

if(me==you) else }

printf("Hello"); printf("Welcome");

what is the output? a. c. wipro ram

1. Answer:

Welcome Explanation:

b. d.

wiproinnovationprogr wipro\ninnovation\npro

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:

For floating point numbers (float, double,

Answer: A

9.

When file opened in mode ab a. pointer is placed at the beginning of file b. c. end of the file error in opening

Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= )

d.

none of the above

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

Answer: b 10. Consider the following statement fseek(fp,50,4); which among the following is correct a. b. c. d. moves the file pointer to beginning of file moves the file pointer to the 50th byte from beginning of file moves file pointer to the 50 byte from end of file compilation error
th

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

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

2. Answer :

Answer: d

Explanation :

three The default case can be placed anywhere

SESSION 1 1. main() { float me = 1.1; double you = 1.1;

inside the loop. It is executed only when all other cases doesn't match.

3. main() {

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

222

} 5. Answer: Explanation: 1

3. Answer:

i=0

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.

Explanation:

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

In the expression !i>14 , NOT (!) operator

6. main()

{ int i=0; for(;i++;printf("%d",i)) ;

4. #include<stdio.h> main() { int i=1,j=2; switch(i)

printf("%d",i);

6. Answer: Explanation: before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the semicolon after the for loop). 1

{ case 1: printf("GOOD"); break; case j: printf("BAD");

} }

break;

loop, and i is incremented (note the

4. Answer: Compiler

required in function main.

Error:

Constant

expression

7. main() { int i=-1;

Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error). Enumerated types can be used in case

Note:

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

statements.

7. Answer:

5. main()

i = -1, +i = -1 Explanation:

int i;

Where-ever it comes you can just ignore it

Unary + is the only dummy operator in C.

printf("%d",scanf("%d",&i)); // value 10 is given as input here

just because it has no effect in the expressions (hence the name dummy operator).

223

else 8. main() }

printf("%d is a leap year"); printf("%d is not a leap year");

char not; not=!2; printf("%d",not); } 8. Answer: Explanation: ! is a logical operator. In C the value 0 is 0

10. Answer:

Explanation: An ordinary program to check if leap year or not.

2000 is a leap year

considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a nonzero value so TRUE. !TRUE is FALSE (0) so it prints 0.

11. main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); } 11. Answer:

9. main() {

int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

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.

i = -1, -i = 1

9. Answer:

1==1 is TRUE Explanation:

When two strings are placed together (or separated by concatenated white-space) they (this is called are as

12. int i;

main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) } printf("%d--",t--);

"stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".

// If the inputs are 0,1,2,3 find the o/p 12. Answer:

10. main() { int y;

4--0 3--1 2--2 Let us assume some x= scanf("%d",&i)-t the

Explanation:

scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 )

values during execution will be,

4 3 2

0 1 2

224
else }

-4 -2 0 }

break; continue;

15. Answer: 13. main(){ int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello");

Explanation: The inner printf executes first to print some

Garbage values

garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf

13. Answer:

Explanation:

hello The comma operator has associativity from

prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.

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.

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

int x,y=2,z,a;

if(x=y%2) z=2; a=2; }

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

14. main(){ unsigned int i;

for(i=1;i>-2;i--) printf("c aptitude");

16. Answer:

Garbage-value 0 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

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 huge value so condition becomes false and control comes out of the loop.

value. The unsigned equivalent of -2 is a

free code.

uninitialized. Thumb Rule: Check all control paths to write bug

17. main() 15. void main() { while(1){ if(printf("%d",printf("%d")))

unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i);

225
17. Answer

infinite loop Explanation The difference between the previous

Explanation:

Due to the assignment p[1] = c the string the format string for printf and ASCII value of 65 is A, the same gets printed.

becomes, %c\n. Since this string becomes

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

18. main()

char i=0;

for(;i>=0;i++) ; }

int i=10,j=20; j = i, j?(i,j)?i:j:j;

printf("%d\n",i); 18. Answer:128 Behavior

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

20. Answer: is implementation

dependent. Explanation:

signed/unsigned implementation

The

detail

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:

by default dependent. If

if

the

char

is the

is

The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the question can be written as: if(i,j) { if(i,j)

10 10 Explanation:

j = i; else } j = j;

else

implementation dependent behavior. But dont write programs that depend on such behavior.

You can write programs that have

j = j;

21. main() {

19. main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65);

float i=1.5; switch(i) {

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

default : printf("0");

19. Answer:

21. Answer: integral

226
24. Answer:

Compiler Error: switch expression not

Explanation: integral types.

Switch statements can be applied only to

Explanation:

Compiler error: Too many initializers The array a is of size 4 but the string constant requires 6 bytes to get stored.

22. Which version do you prefer of the following two, 1) printf(%s,str); curt one 2) printf(str);

// or the more

25.

main() { char a[4]="HELL"; printf("%s",a);

22. Answer & Explanation:

Prefer the first one. If the str contains any format characters like %d then it will result in a subtle bug.

25. Answer:

HELL 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.

Explanation:

23. void main()

{ char ch;

for(ch=0;ch<=127;ch++) printf(%c %d \n, ch, ch); }

Session -2 26. main() {

23. Answer: Infinite Loop

Implementaion 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

int c=- -2; printf("c=%d",c);

back to -128. Thus ch is always smaller than 127.

26. Answer:

c=2; Explanation:

used twice. Same maths rules applies, ie. minus * minus= plus. 24. main() { char a[4]="HELLO"; printf("%s",a); Note:

Here unary minus (or negation) operator is

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

However you cannot give like --2. Because

27. void main() { int i;

227

char a[]="\0";

if(printf("%s\n",a)) else }

printf("Ok here \n"); printf("Forget it\n");

29. main() { char i=0;

for(;i>=0;i++) ; printf("%d\n",i); } 29. Answer: Behavior Explanation: The signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program the other hand if it considers char to be unsigned by default, it goes to Rule: infinite loop. detail if the char is

27. Answer:

Ok here Explanation:

Printf will return how many printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed.

characters does it print. Hence

dependent.

is

implementation

will print 128 and terminate. On

28. What is the output of the program given below main() { signed char i=0;

You can write programs that have

for(;i>=0;i++) ; printf("%d\n",i);

implementation dependent behavior. But dont write programs that depend on such behavior.

28. Answer -128

Explanation Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. The inner loop

30. main() { int i = 3;

executes to increment the value

for (;i++=0;) printf(%d,i);

from 0 to 127 (the positive range of char) and then it rotates to the negative condition in the for loop fails and prints the current value of i that is -128. value of -128.

The

30. Answer:

so comes out of the for loop. It

Explanation:

Compiler Error: Lvalue required. As we know that increment

operators return rvalues and hence it cannot appear on the left

hand

operation.

side

of

an

assignment

228

33. main() { int i=5;

31. main() { int i=5,j=10;

i=i&=j&&10; printf("%d %d",i,j);

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

33. Answer:

31. Answer:

1 10 Explanation: The

Explanation:

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

i=(i&=(j&&10));

expression

The

can

inner

be

written

expression

as

(j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.

Session 3 32. main() { int i=-1,j=-1,k=0,l=2,m;

34. main()

{ int i=5,j=6,z;

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

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

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

34. Answer: 11

32. Answer: 00131 Explanation : Logical operations always give a result of 1

Explanation: the expression i+++j is treated as (i++ + j)

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

35. main() { int i =0;j=0; if(i && j++)

Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for 0 || 0 combination- for values of other variables are also which it gives 0). So the value of m is 1. The incremented by 1.

(-1 && -1 && 0 = 0).

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 boolean expression. So the statement

229

enough to determine the truth value of the following the if statement is not executed. get printed.

38. Answer: Explanation: 1

The values of i and j remain unchanged and

Note

statement. When the value of i becomes 0 it

the

semicolon

after

the

while

comes out of while loop. Due to postincrement on i the value of i while printing is 1.

36. void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit);

39. main() { int i=5; }

36. Answer: 0 65535

printf(%d,i=++i ==6);

39. Answer: 1

37. main() { unsigned int i=10; while(i-->=0)

Explanation: The expression can be treated as i = than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.

(++i==6), because == is of higher precedence

printf("%u ",i);

} 37. Answer:

10 9 8 7 6 5 4 3 2 1 0 65535 65534.. Explanation:

40. main() {

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. }

int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j);

40. Answer: 41

Explanation: 38. main() { unsigned int i=65000; while(i++!=0) ; } printf("%d",i);

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

230

an expression, when any of the operands value becomes false and hence the

} Ans: Three 4. main() {

become false, the whole expressions truth remaining expression will not be evaluated. (anything) will not be evaluated. false &&

(anything) => false where

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

} void display(char *string) SESSION 1 { } printf("%s",string);

1. main() {

Ans::Hello World

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

double you = 1.1; printf("Hello"); printf("Welcome");

5. #define int char main() { int i=65;

} Ans: welcome 2. main() {

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

Ans: 1 6. main() {

extern int i;

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

int i=10;

i=!i>14; printf ("i=%d",i);

Ans: linker error. 3. main() { int i=3; {

Ans: 0

switch(i) default:printf("zero"); case 1: printf("one"); break; break; break;

7. #define square(x) x*x main() { int i;

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

case 2:printf("two");

Ans: 64

case 3: printf("three"); }

8. #include <stdio.h> #define a 10

main() { #define a 50

231
}

i++;

printf("%d",a);

} {

fun() here:

Ans: 50 9. #define clrscr() 100 main() {

printf("PP");

Ans: error::goto here sud be defined and called in same fuction

clrscr();

printf("%d\n",clrscr());

14. #include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); } } break;

Ans: 100 10.main() { }

printf("%p",main);

Ans : address of main 11. main() {

clrscr(); } clrscr();

Ans: Error::case sud have a constant value 15. main() {

ans::error:type mismatch 12. main() { int i=400,j=300;

int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

printf("%d..%d"); } Ans::300 400 13. main() { int i=1; {

Ans: 1 16. main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i);

while (i<=5) printf("%d",i);

if (i>2) goto here;

Ans: 1 ya since i++ will not increment first time so I is o in for thats why

232

22. main() { } main();

17 . main() { extern int i; i=20;

Ans: runs until stack overflow.

printf("%d",sizeof(i)); } Ans: Linker error

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

18. main() { extern out; printf("%d", out);

} int out=100; Ans: 100 19. main() {

#define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) else } puts("TRUE");

show(); }

void show()

{ printf("I'm the greatest"); } Ans::I m the greatest 20. main() {

puts("FALSE");

Ans: TRUE ::print as it anythng in double quotes 25. main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

int i=-1; +i; }

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

Ans: 1==1 is True. 26. main()

Ans: -1 -1 21. What are the files which are automatically opened when a C file is executed?

{ int y;

scanf("%d",&y); // input given is 2000 printf("%d is a leap year",y);

if( (y%4==0 && y%100 != 0) || y%100 == 0 ) else printf("%d is not a leap year",y);

Ans: stdinput,stdoutput,stderror.

} Ans: 2000 leap year 27. main() { int i=-1;

233
Ans:Error?? 30. int i;

main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) } printf("%d--",t--);

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

// If the inputs are 0,1,2,3 find the o/p Ans: 40

Ans: i=-1 i=1

31 22 //GUD 1

28. main()

{ char c=' ',x,convert(z);

31. main(){

getc(c); if((c>='a') && (c<='z')) x=convert(c);

int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello");

printf("%c",x); } convert(z) { return z-32; } Ans: Error//1ST convert (char);will do in fuction prtotype+fuc dec convert(char function

Ans:hello

32. main() { unsigned int i;

for(i=1;i>-2;i--) } Ans: infinite. 33. void main() {

printf("c aptitude");

z) sud be used+getc() is not a library

29. main(int argc, char **argv) { printf("enter the character"); getchar(); } sum(argv[1],argv[2]); }

while(1) {

if(printf("%d",printf("%d"))) else break;

sum(num1,num2) int num1,num2; {

continue;

return num1+num2; }

Ans: (garbage or 0) 1(compiler dependent) 34. #include<conio.h>

main() { int x,y=2,z,a; if(x=y%2) z=2;

234

41. main() { char str1[] = {s,o,m,e}; while (strcmp(str1,str2)) } Ans: no output. 42. main()

char str2[] = {s,o,m,e,\0}; printf(Strings are not equal\n);

} Ans: garbage 0 35. main()

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

a=2;

unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); } Ans: 10 10 43. main() {

int i=10,j=20; j = i, j?(i,j)?i:j:j;

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

} Ans: infinite {

36. main()

char i=0;

for(;i>=0;i++) ; printf("%d\n",i); }

register int a=2;

} Ans: error

printf("Address of a = %d",&a); printf("Value of a = %d",a);

Ans: -128

39. main() {

44. main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); float i=1.5; switch(i) {

} Ans: A 40. main() {

case 1: printf("1");

} Ans: error

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

while (strcmp(some,some\0))

printf(Strings are not equal\n);

45. main() { extern i; printf("%d\n",i);

Ans: no output//strcmp(gives 0 if all letters are equal)

235
int i=20;

} Ans: HELLgarbage 51. main() { printf("%d", out); } int out=100; Ans: error

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

Ans: linker error(run time error)

46. char inputString[100] = {0}; the following is better?

To get string input from the keyboard which one of 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); curt one 2) printf(str);

// or the more 1. main()

SESSION 2

Ans: 1 48. void main() { char ch; for(ch=0;ch<=127;ch++)

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]);

printf(%c %d \n, ch, ch); } Ans: infinite 49. main() {

Ans: mmmm aaaa nnnn 2. main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); } Ans: 1 2

char a[4]="HELLO"; printf("%s",a);

Ans: error//too many intializers 50. main() { char a[4]="HELL"; printf("%s",a);

*3. main()

{ }

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

236
Ans: 0xfff0 4. main() } Ans: Ok here else

printf("Ok here \n"); printf("Forget it\n");

}
Ans: 2

int c=- -2; printf("c=%d",c);

9. What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ;

5.. main()

{ char *p;

p="Hello";

printf("%c\n",*&*p); } //here*&p==&*p Ans: H 6. main() Ans : -128 10. main() {

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

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

char *str1="abcd"; char str2[]="abcd";

char i=0;

%d

for(;i>=0;i++) ; printf("%d\n",i); } Ans : -128

Ans: 2 5 5 7. #include<stdio.h> main() { register i=5;//valid int can be dropped char j[]= "hello"; printf("%s %d",j,i); }

*11. void main() { if(~0 == (unsigned int)-1) printf(You can answer this if you know how values are represented in memory);

Ans: hello 5

represented in memory

Ans : you can answer this if you know how values are

8. void main() { int i;

12. main() { int i = 3;

char a[]="\0"; if(printf("%s\n",a))

for (;i++=0;) printf(%d,i);

237
Ans : L value required error. 13. main() { 1.

SESSION 3

main()

int i=5,j=10;

i=i&=j&&10; } Ans : 1 10

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

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

14. #define DIM( array, type) sizeof(array)/sizeof(type) main() {

Ans : 5 4 3 2 1 2. main()

int arr[10];

printf(The dimension of the array is %d, DIM(arr, int)); } Ans: 10

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
int DIM(int array[])

15.

{ return sizeof(array)/sizeof(int ); } main() {

3. #include<stdio.h>

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

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

typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; }

printf("%d %s",list[0],name); Ans: Error

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 printf("%s %s",p,p1); } Ans: ibj!gsjfoet

238

char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s;

Ans : 77

printf("%d",++*p + ++*str1-32);

10. #include<stdio.h> main() { const int i=4; float j; j = ++i; } Ans: error 11. main() printf("%d %f", i,++j);

6. main()

static int i; char *t;

char

names[5][20]={"pascal","ada","cobol","fortran","perl"};

t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]);

} Ans: Error

{ int i=5,j=6,z;

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

7. void main() { int i=5;

Ans: 11 12. main() {

printf("%d",i++ + ++i); } Ans: 12 8. void main() { int i=5;

int i=_l_abc(10);

printf("%d\n",--i); } int _l_abc(int i) { } Ans : 9. 13. main() { int i =0;j=0; return(i++);

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

Ans : Lvalue required error 9. #include<stdio.h> main()

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++;

239

Ans: 6 *18. void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); }

printf("%u \n",gotit=--giveit);

} //printf(name of string )==will print string.. Ans: 300

printf(p-2,300);

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() { }

15. void main() { static int i=5; if(--i){ main();

printf("%d ",i);

static int i=i++, j=j++, k=k++;

Ans: 0 0 0 0

Ans: Error 21. main() { unsigned int i=10;

printf(i = %d j = %d k = %d, i, j, k);

16. void main() {

int k=ret(sizeof(float)); printf("\n here value is %d",++k); }

while(i-->=0) printf("%u ",i);

int ret(int ret) {

} Ans: 7. 17. void main() {

ret += 2.5; return(ret);

Ans: infinite

22. main() { unsigned int i=65000; while(i++!=0); printf("%d",i);

char a[]="12345\0"; int i=strlen(a); printf("%d\n",++i);

Ans: 1

23. main()

240
int i=0; 28. main() { int i=4,j=7;

while(+(+i--)!=0) printf("%d",i); i-=i++;

Ans: -1//ya check while 24. main() { float f=5,g=10;

j = j || i++ && printf("YOU CAN"); } printf("%d %d", i, j);

Ans: 4 1

29. char *someFun1()


{ char temp[ ] = string"; return temp; } {

enum{i=10,j=20,k=50};

printf("%d\n",++k);//cannot increment. printf("%f\n",f<<2);//illegal instruction printf("%lf\n",f%g);//illegal instruction } printf("%lf\n",fmod(f,g)); //Legal instruction Ans: error 25.. main() {

char *someFun2() char temp[ ] = {s, t,r,i,n,g}; return temp; } int main() {

int i=5;

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

puts(someFun1()); puts(someFun2()); } Ans: garbage

Ans: l value required ++(i++) since (i++)will give an 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--; } Ans: 32767//ya printf(%d, i);

constatnt value and cant perform ++ on a constant

1.

main() {

SESSION 4

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

241
3. void main() { int i=10, j=2;

char * str = "hello"; char * ptr = str; while (*ptr++) char least = 127; least = (*ptr<least ) ?*ptr :least;

int *ip= &i, *jp = &j;

int k = *ip/*jp;//ya but *ip/(*jp) is valid since /* is used for comment } Ans : error 4. void main() { printf(%d,k); }

printf("%d",least);

Ans: 0//gud 1
8. main()

printf(sizeof (void *) = %d \n, sizeof( void *)); printf(sizeof (int *) = %d \n, sizeof(int *)); printf(sizeof (double *) = %d \n, sizeof(double *)); unknown *) = %d }

int i=300; char *ptr = &i; *++ptr=2; printf("%d",i);

printf(sizeof(struct sizeof(struct unknown *)); }

\n,

Ans:300
*9. main()

Ans: 2 2 2 2 5. void main()

{ int *i = 0x400; // i points to the address 400 *i = 0; pointed by i; }

int i = 258; int *iPtr = &i; printf("%d

// set the value of memory location

*((char*)iPtr+1) ); // Ans: 2 1 }

%d",

*((char*)iPtr),

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)

*10. main() { int i = 257;// int *iPtr = &i; *((char*)iPtr+1) ); } printf("%d

%d",

*((char*)iPtr),

p = &arr[i]; *p = 0;

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

Ans: only one stmt executes with in while loop. 7. #include <stdio.h> main()

242
for(j=0;j<3;j++)

3. char const *a;

-Differentiate the above declarations. Ans: data constant

printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), }

*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));

Pointer constant Data constant

} Ans : 1 1 1 1

15.

2424 3737

main() {

char *p = ayqm; char c; c = ++*p++;

6868 7373 8686 9999

4242 5555

Ans:b

printf(%c,c);

16. main()

//gud que 12. main() {

{ char *p = ayqm;

printf(%c,++*(p++)); } char *p="GOOD"; char a[ ]="GOOD"; Ans: b 17. What is the output for the following program main() int arr2D[3][3];

printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); } strlen(p));

Ans: 2 1 4 54 13. main() { int a=2,*f1,*f2;//a=2,f1=&a,f2=&a// *f2+=*f2+=a+=2.5; } Ans: 16 16 16 Gud1 14. f1=f2=&a; Ans: 1

printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }

18.

declaration/definition. Find what does it mean? Ans: pointer to an array of 10 integer data. 19. main() { int a[10]; int (*x)[10];

Is

the

following

statement

printf("\n%d %d %d",a,*f1,*f2);

1. const char *a; 2. char* const a;

Ans: 4

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

Gud1

243

20. void main() { void *v;

} Ans: 10 garbage 24. main() { int *j;

int integer=2; v=i; } Ans : 2 21. # include <stdio.h> int one_d[]={1,2,3}; main() {

int *i=&integer; printf("%d",(int*)*v);

{ int i=10; j=&i; } }

printf("%d",*j);

Ans: 10

25. main() { char *cptr,c; void *vptr,v;

int *ptr;

//if ptr+=2 then 3 will printed Ans: garbage 22. main() {

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

ptr=one_d; ptr+=3;

c=10; v=0; cptr=&c; vptr=&v; }

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

Ans: error 26. main()

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

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

{ int i, n;

char *x = girl; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) {

Ans : 1 2 4 23. #include<stdio.h> main() {

} Ans: irl

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

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2];

rl l

*q=***a; printf("%d..%d",*p,*q);

27. main ( ) {

violet}; p = ptr; **++p; } Ans::ck

static char *s[ ]

= {black, white, yellow,

244

++*ptr;

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

printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);

printf(%s,*--*++p + 3);

31. main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { a++;

28. main( ) { void *vp;

printf(%d ,*a);

char ch = g, *cp = goofy; int j = 20; vp = &ch; vp = &j; printf(%c, *(char *)vp);//g printf(%d,*(int *)vp);//20 vp = cp;

p = a; for(j=0; j<5; j++) { printf(%d ,*p); p++;

Ans: g 20 fy

printf(%s,(char *)vp + 3);//fy }http://www.orkut.co.in/Main - Home?rl=t

} Ans: Error 32. main( ) {

29. main( ) {

char *q;

int a[2][3][2] {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1); } printf(%u %u %u %d \n,a,*a,**a,***a);

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: let base address be 1000. 1000 1000 1000 2 1012 1004 1002 3

Ans: Error (Null pointer assignment) 30. main( ) { static int a[ ] = {0,1,2,3,4}; int **ptr = p; ptr++; *ptr++;

33. #include<stdio.h>

int *p[ ] = {a,a+1,a+2,a+3,a+4};

printf(\n %d %d %d, ptr-p, *ptr-a, **ptr); printf(\n %d %d %d, ptr-p, *ptr-a, **ptr); *++ptr; printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);

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

245

} Ans: bye. 2. In the following pgm add a stmt in the function fun such that the address of main(){ int * j; 'a' gets stored in 'j'.

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; }

void fun(int **); fun(&j);

void fun(int **k) { int a =0; }

Ans: 2 2 2 2 2 23465

/* add a stmt here*/

Ans: *k=&a; 3. main(){ char a[100]; abc(a); }

35. void main()

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

a[0]='a';a[1]='b';a[2]='c';a[4]='d';

Ans: error

abc(char a[]){ a++;

printf("%c",*a); a++; printf("%c",*a);

1.

# include<stdio.h> aaa() { printf("hi"); } bbb(){

SESSION 5

} Ans: b c 4.

ccc(){ }

printf("hello"); } printf("bye");

func(a,b) int a,b; { } main() {

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

main() {

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

int process(),func(); printf("The } ",process(func,3,6)); value

of

process

is

%d

!\n

process(pf,val1,val2) int (*pf) (); { int val1,val2; return((*pf) (val1,val2)); }

246

int foo(int *arr[2])

12. char *someFun() { char *temp = string constant"; return temp; }

Ans: error

5.

#define prod(a,b) a*b main() {

int main() { } puts(someFun());

int x=3,y=4;

} Ans: 10

printf("%d",prod(x+2,y-1));

Ans: string constant. 13. main()

6. int swap(int *a,int *b) { } main() {

*a=*a+*b;*b=*a-*b;*a=*a-*b;

printf(%d\n,i); } int _l_abc(int i) { return(i++); } Ans: -10 14. main()

{ int i=_l_abc(10);

int x=10,y=20; swap(&x,&y);

printf("x= %d y = %d\n",x,y); } Ans: 20 10

{ char a[100]; a[0]=a'; a[1]]=b';a[2]=c';a[4]=d'; abc(a); } abc(char a[]) a++;

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?

a++; printf(%c,*a); }

printf(%c,*a);

11. Is there any difference between the two declarations, int foo(int *arr[]) and

15. void main() { static int i=5;

if(i)

247

5. The value of EOF is -1. 6. Using pointers to call a function is called as function pointer

main(); } }

printf(%d ,i);

Ans:Infinite Loop No Output

7.

The variable that contains address of another variable is called as Pointer

1. what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);

SESSION 6

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 above Ans : main()

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

10. The variables that can be used only within the function in which it is declared is called as Local variable.

FILE *ptr;

char i; ptr=fopen("zzz.c","r");

while((i=fgetch(ptr))!=EOF) printf("%c",i); }

SESSION 7 1. #include<stdio.h>

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); } Ans: garbage 0 printf(%d,*cptr);

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

248
*2. #include<stdio.h>

def.next=&ghi;

Ans: Error

main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

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; 3. enum colors {BLACK,BLUE,GREEN} main() { main() {

pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); } Ans: 0 0 00

printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } Ans: 0 1 2

printf("origin is (%d%d)\n",pp->x,pp->y);

8. What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() {

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;

Ans: Error (multiple declaration of error). 9. typedef struct error{int warning, error, exception;}error; { main()

g1=1; printf("%d",g1);

error g1;

def.i=1;def.prev=&abc;

g1.error =1; printf("%d",g1.error);

error g1;

Ans : error
10. main() {

249

char name[30], rollno[6]; }stud; FILE *fp = fopen(somefile.dat,r);

struct student { char name[30]; struct date dob;

while(!feof(fp)) {

fread(&stud, sizeof(stud), 1 , fp); puts(stud.name);

}stud; {

struct date int day,month,year; };

Ans: last record will get printed twice when feof is used.

&student.dob.day, }

scanf("%s%d%d%d",

&student.dob.month,

stud.rollno,

13.

Is the following code legal? struct a {

&student.dob.year);

Ans: error Ans : no 14.

int x; struct a b;

11. main() {

struct date; struct student char name[30]; struct date dob; struct date { int day,month,year; stud.rollno, &student.dob.month,

Is the following code legal? struct a {

}stud;

} Ans: no// 15.

struct a *b;

int x;

scanf("%s%d%d%d", &student.dob.day, } &student.dob.year);

};

Is the following code legal? typedef struct a { int x;

Ans: error

}aType

aType *b;

12.

the following program printed 11 names. What went wrong? void main() {

There were 10 records stored in somefile.dat but

Ans: syntax error. 16. Is the following code legal? typedef struct a aType; struct a {

struct student

int x; aType *b;

}; Ans: yes

250

2) ans::2 3)

enum value{VAL1=0,VAL2,VAL3,VAL4,VAL5}var; printf("%d",sizeof(var));

17.

Is the following code legal? void main() {

typedef struct a aType; aType someVariable; struct a

printf("%d %d %d %d %d %d",MON,TUE,WED,THU,FRI,SAT); ans::-1,0,55,56,57,58

enum days{MON=-1,TUE,WED=55,THU,FRI,SAT};

}; } Ans: no 18.

int x; aType *b;

4)

void main() { {

union var int a,b;

list.

Printf can be implemented by using __________

}; union var v; v.a=80; v.b=100;

19. main()

{ float f=5,g=10;

printf("%d",v.a);

enum{i=10,j=20,k=50}; printf(%d\n,++k); printf(%f\n,f<<2);

ans::100 5) void main() { struct node {

printf(%lf\n,f%g); printf(%lf\n,fmod(f,g)); }

Ans:error.

};

int data; struct node *link;

q=(struct node *)malloc(sizeof(struct node)); printf("%d %d",sizeof(p),sizeof(q)); 1) struct value { int bit1:1; int bit3:4; int bit4:4; }

struct node *p,*q; p=(struct node *)malloc(sizeof(struct node));

ans::2,2

}bit={1,2,2};

printf("\n %d %d %d",bit.bit1,bit.bit3,bit.bit4); ans::-1,2,2

6)

struct byte { int one:1;

};

struct byte var={1};

251

printf("%d",var.one); ans::-1

printf("%s",(*(c+2)).coursename);

printf("%d",c[1].courseno);

ans::103 Design enum status{pass,fail,atkt};

7)

enum status stud1,stud2,stud3; stud1=pass; stud2=atkt; stud3=fail;

11) {

void main() union test { int i; float f;

printf("\n %d %d %d",stud1,stud2,stud3); ans::0 1 2

}; 8) printf("%d %d %d ",i|j&j|i,i|j&&j|i,i^j); int i=4,j=8;

char c;

union test *t;

t=(union test *)malloc(sizeof(union test)); t->i=10; printf("%d\n",t->c); t->f=10.10f;

9)

union x int i; char ch[2];

printf("%f\n",t->f);

t->c='a'; printf("%c\n",t->i); }

};

u.ch[1]=2; printf("%d %d %d ",u.ch[0],u.ch[1],u.i);

union x u; u.ch[0]=3;

12) {

void main() struct address { char phone[15]; char city[25]; int pin; }; { struct emp char name[25]; struct address a;

10)

struct course {

int courseno;

void main() {

};

char coursename[25];

struct course c[]={ {102,"Thermal"},{103,"Manufacturing"},{104,"Desi }; }

};

struct emp e={"jeru","2344","kerala",55};

gn"}

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

252

int b:2; };

unsigned int c:3;

13) {

struct book char name[25];

struct sample s; s.a=-2; s.b=1; s.c=3;

};

char author[25]; int no;

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;

void display(struct book *); void main() {

struct book b1={"Let us C","YPK",101}; display(&b1);

s.b=0; s.c=5;

} { }

printf("\nThe value of a is %d",s.a); printf("\nThe value of c is %d",s.c);

printf("\nThe value of b is %d",s.b);

void display(struct book *b) printf("\n %s %s %d",b->name,b->author,b->no);

ans:: Let us C,YPK,101

%d",sizeof(s)); }

printf("\n Total size of the structure sample is

14) {

void main() struct sample { int num;

17)

}m;

char m1[50]; char m2[50];

struct sample char name[10]; int no;

};

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

void main() {

struct sample s; void passrecord(struct sample); printf("\n Enter the name:"); scanf("%s",s.name); scanf("%d",s.no); passrecord(s);

ans::garbage value will be printed

printf("\n Enter the Roll Number:");

16) {

void main() struct sample { int a:3;

printf("\n values after the function:\n"); printf("\n Name : %d",s.no); } printf("\n No %s",s.name); :

void passrecord(struct sample x) { x.no=x.no+10;

253

c) a) b c a c) a b c

temp->next->prev=temp->prev;

printf("\n Inside the function:\n"); printf("\n Name : %s",x.no); printf("\n No :

%s",x.name);

b) c b a d) both a and b 4. struct list { int data;

struct list* left,

18) Point out if there is any error in the program void main() {

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. 2. 3. 4. n->left = ptr->left n->left->right = n ptr->left = n n->right = ptr b) 4 3 2 1 c) 4 2 1 3 d) 3 1 2

struct employee {

char name[25]; int age; float bs;

}; struct employee e;

strcpy(e.name,"Hacker"); age=25; } ans::error

printf("\n %s %d",e.name,e.age);

a)1 2 3 4 4 .

5.

where does the pointer temp pointing after the

code execution, where head is startning node in D.L.L of nine 1. can we have more than one data members in a nodes,. for( i=1; head!=NULL;head=head ->next, i++) { If(i==1)

doubly linked list structure a) yes no

b)

else if (i%2==1) } a) c) middle node

temp=head; temp= temp->next;

3.

pointer a) b)

Arrange the code below, to delete a node being

by temp.

b) d)

last but one node cannot make out second node

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

6. What does function do, if temp is pointing to a node in DLL and

254

{ }

Temp = temp ->next;

temp1 is a newnode?

temp1 -> prev = temp

temp -> prev -> next = temp -> next; free(temp); a) b) c) d)

temp1 -> next =temp ->next temp -> next = temp1

temp -> next -> prev = temp -> prev;

temp -> next->prev = temp1

no effect deletes some node deletes last node

a)

b)

inserts node before temp; inserts after temp deletes node pointed by temp; none of the above

deletes 2nd last node

c) d)

10. what does the code do, if there are 100 nodes temp=head; {

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

while ( temp -> next -> next -> next != NULL) Temp = temp -> next;

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

} temp -> prev -> next = temp -> next;

b) c)

no effect

temp -> next -> prev = temp -> prev; free ( temp ); a) b) deletes 3rd last node no effect

d)

inserts a node deletes a node

shuffling of pointers

8. What does the code below do, where head is starting node & temp is temporary pointer

c) d) 1.main() { }

3rd node is deleted Middle node is deleted

temp=head; head= head -> next; head -> prev = null; free(temp); a) b) c) d) no effect NULL data is stored

printf("%c\n", '1' + 1);

a)ASCII value of '1' is required to find out the answer b)2 c)50 d)Syntax Error ans::b { 2. main() char y[10] = "abcdefghi"; char *p = y; p = p + 9; } printf("%c\n",*p);

Starting node is deleted

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 nodes temp = head; while (temp->next->next!=NULL)

a)i

b)Program will have runtime error c)Unpredictable ans::d { d)No visible output 3. main() int y[2][2] = { {1,2}, {3,4} }; int *p = &y[1]; p = p + 1; }

255

{ }

printf("Hello World\n");

a)5

b)6

c)Infinite

d)Program will not compile ans::c

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

a)4 b)3

c)The program doesn't compile d)Output is unpredicatable ans::a 4. int y = 10; main() {

6. struct emp {

int x = 10; int y = 20; x = x + y;

int age; char name[10]; struct emp e; };

if (x >= 30) { x = x + y;

int y = 30;

void main() { } a)24 b) No Output

printf(%d.sizeof(struct emp));

else {

int y = 40;

c) Compiler Error d) None Of the above ans::c 7. what is the outpur of the following prog. void main() {

} }

x = x + y;

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

a)40 c)60

b)50 d)70 ans::b 5. main() { unsigned int i = 5; while (--i >= 0)

insert(root,2); insert(root,1); insert(root,3); insert(root,4); insert(root,5); preorder(root);

correct position in the tree. root is the root of the tree and

assume insert function inserts a node at its

256

/ \ 2 /\ /\ 1 3 10 30 / / 7 40 \ 50 11

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); push(top,1); push(top,25); x=pop(top);

12. There is a tree in the box at the top of this section. How many leaves does it have? A. B. 5 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. F. 5 6

printf(%d, x);

} consider push function pushes onto the stack the given

G. 7 H. 8 I. 9

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

14.There is a tree in the box at the top of this section. containing 30? J.

What is the value stored in the parent node of the node 10

K. 11 L. d.push 14

10. The operation for adding an entry to a stack is traditionally called: a.add b.append c.insert

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

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

Q. 9 R. 8

14

16.There is a tree in the box at the top of this section. What is the depth of the tree? S. T. 2 3

257

(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 (b) front = 2 rear=0

U. 4 V. 8 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. b. c. d. e. Something between -15 and -100 Something between -5 and -15 Something between 5 and -5 Something between 5 and 15 Something between 15 and 100

(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.

the back of the list. based method.

(ii) The queue can be implemented only by stack. (iii) There are references kept at both the front and (iv) The Queue can be implemented only by an array-

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 (e) (ii) and (iv) only

(d) (i),(iii) and (iv) only

the node definition with member functions called data and next node?

19. Suppose cursor points to a node in a linked list (using

22. main(){ int i,b[]={1,2,3,4,5},*p; p=b; ++*p; Printf(%d,*p); P+=2; Printf(%d,*p); } A. 2 3 B. 2 4 C. 3 4 D. 2 5 Ans::2 3 23. void main() {

link). What statement changes cursor so that it points to the a. b. c. d. cursor++; cursor = link; cursor += link; cursor = cursor->link;

20. Consider the following queue which can be allocated eight integers and five operations.front = 1 rear= 3 Queue = -,2 , 4 ,5, - , - , -,cell)

(for notational convenience used to denote an empty

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

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.

e=(a,a)+(b,c)+(c,d)-(d,b); }

(a)Compile-Time Error (c)6

(b)10

258
(d)2
25

Ans::6

24. struct aaa{

(b) struct aaa *prev; int i; struct aaa *next; };


11

16

72

21

26

88

14

36

main() {

45

struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def;


69

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; (c)


16

25

72

x=abc.next->next->prev->next->i; printf("%d",x);

11

21

26

88

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

14

36

69

45

25, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69 (d) (a)
25 16 72 11 11 21 36 88 72

21
16

16

25

9 9
14 26 45

14

36
16

88

26 69

45

69

259

switch(f) { default: puts(hi); case 2.0 : puts(helloo); break;

2) which of the following data structure is used in hierarchical data modeling a) stacks c) trees b) queues d) structure ans: trees

3) a binary tree with 20 nodes have _____ null branches a) 20 b) 22 c) 21 d) 40 Ans: 21 4) in tree construction which of the following is suitable efficient data structure a) array b) doubly linked list c) stack d) queue

a) compile time error b) hi c) d) No output helloo

Ans::a 2. which finite set of elements that is either empty or is portioned into 3 disjoint subset. a. b. c. single linked list double linked list stack

d. binary tree Answer: D 3.

e) none ans: doubly linked list 5) find output of the following code. #define min(a,b) (a<b?a:b)

what type of Binary Tree is the following tree below

B
main() {

int a; a=min(3+4,4+4); printf(%d\n,a);

G
} a) 7 b) 8 c) Compile time error d) Garbage. Ans::a a. c.

H
b. d.

strictly binary tree

complete binary tree not a binary tree

almost complete binary tree

Answer: D 4. Which is the preorder of a Binary tree represented below

6) main() { float f=2;

260 A

b. c. d.

^+-//*BC*DEGA+HI*J/KL ^-+/*/BC*DEGA+HI*J/KL ^-+/*/BC*DEGA+HI*J/KL

C
7.

Answer: A postfix form of the following expression is A*B*C*D*E*F/G+H-I^J -/*****ABCDEFGH+^IJ BA*D*C*F*GH/+IJ^-

G
a.

b. c. d.

AB*C*D*E*F*G/H+IJ^AB*CB*D*E*F/GH*IJ^

I
a. b. c. ABDHIECFJKG IHDEBKJFGCA IHDBEAKJFCG ABCDEFKJGHI

8.

which is formula to find the total no. of node in complete B.T a. tn=2d+1 1 where depth(d) !=level

5.

Answer: A If suppose root to be deleted then which node will be the root node

d.

b. tn ==2d+1 1 where depth != level(L) c. tn = 2L+1 d. 2n-1

Answer: A

9.

what type of B.T is the following tree

A B G B C E H I D D K J H
a. b. c. d. B G

F
a.

G
strictly B.T

Any node

Both a and b are correct

6.

conver this expression in prefix form (A+B * C/D * E /G H + I) ^ ( J /K * L) a. ^-+//*BC*DEGA+HI/J*KL

Answer B

b. c.

d.

completely B.T stricktly complete B.T almost complete B.T

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; {

261

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

code?

what is the output after execution of this

a. b.

Deletes the key value node & make leaf node connected to its parent Deletes the leaf node of key node Deletes the key node None of the above

c. d.

Answer: A

You might also like