link->link. 2) A queue is considered full if rear is equal to max and front is equal to 0. 3) Arrays allow sorting data without moving it, as the elements remain in the same memory locations.">link->link. 2) A queue is considered full if rear is equal to max and front is equal to 0. 3) Arrays allow sorting data without moving it, as the elements remain in the same memory locations.">
FRP C & DS Dumps
FRP C & DS Dumps
FRP C & DS Dumps
prefer?
If you dont know the array size which one do you a) array
7)
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)
i=35; ??????//j=&i; }
8)
data structures used for stack a) array b) linked list c) both d) none
printf("%d",*j);
replaced by ??????
9)
4)
is used?
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
a) i only
b) ii only
c) both i and ii
d) neither i nor ii
13)
the data is
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
15)
18)
}*oemp;
oemp->name="wipro"; ans::error
16)
int k=10;
}e1;
struct b { }e2;
return(&k);
int y;
main() {
int *p;
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]);
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);
void main() { }
printf("%d",fun(5));
4. consider the character array of size 10.When a string is more than 10 a) Error
b) Overwrites c) Nothing
void 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);
a) hello world
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() {
};
b) constants
c) Expressions
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
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
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;
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) 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
c) 4 d) 8 18) In a queue,what condition applies a) First In First Out b) Last in first out
};
printf("%d %d",sizeof(e1),sizeof(*e1));
ans::2 6
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
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++);
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);
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()?
b) #define SQRT(int) (int) * (int) c) #define SQRT(int) (int + int) ans::b 28) void fun() {
c) demofun(*ptr) d) demofun(*&*ptr);
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) }
None
i) All Values are intialised to garbage values ii) Creates memory for 10 integer data a) i only b) ii only
c) both i and ii d) neither i nor ii 36) int *ptr; ptr=(int *)calloc(10*sizeof(int)); which is correct? i) All Values are intialised to zero
b) ii only
ans::
d) neither i nor ii
int rear;
int front;
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
b)cursor->link=NULL c)Cursor->link=0
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
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;
};
traverse(end->prev); }
b) ptr->link=ptr;
printf("%d",end->data);
c) ptr->link=ptr->link->link; d) ptr=ptr->link->link;
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;
};
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*+
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
a) Only even numbers are printed b) Only odd numbers are printed c) Compiler error d) Only garbage values 12) Struct node
9
int data;
};
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;
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;
delete(13,root);
a) ptr->left->right=ptr->right;ptr->right->left=ptr>left;free(ptr);
d) ptr->left->right=ptr->left;ptr->left->right=ptr-
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
printf("%d",++*&b);
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)
8)
which of these is not a valid character constant a) "A" b) '*' c) '+' d) 'h'
} ans::infinite loop 2) void main() int i=1; while(++i==1) { } printf("%d",i); } ans::14 10)
printf("%d",i);
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
ans::2 1 3 4 5 12)
The prefix expression is ab+c*d/e-.If the values of respectively,then what will be the output?
17)
bbb(){ printf("Hello")};
13) What is the order in which the preorder is evaluated? i) root node ii) left node
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)
b) false
19)
int i=1;
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
break;
12
int info;
25)
};
printf("HELLO");
27)
21)
printf("%d",x);
int x;
void main() {
struct a x;
printf("%d",x); fun();
22)
instead of ?????
} if the outputs are 7,8,9,then which is replaced a) extern int x; b) auto int x;
28)
23)
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); {}
13
{ }
printf ("HAI");
true?
ans::hai hai hai....infinite 36) *Consider a linked list where ptr is a pointer which is like new-
zero
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
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:
case 2:
ans::error//if struct element cannot be intialized +oemp cannot use -> only ".". 39)
default: }
printf ("Default");
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++:
a) Platform independent programming b) Platform dependent programming c) Object oriented programming d) None of the above
41)
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)
return(x);
printf("%d",sample(x));
43)
} 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
ans::a
} ans:: } irl rl l
51)
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)
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
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() {
ans::21 -------------------------------------------------------------1. What is the output of the following: unsigned i=32768; void main() { } a. 32768
printf("%d",i);
b. -32768
c. Error
d.
2. {
int i;
printf("%d",i);
16
a. c. 3 0
b. d. 3.
Multiple declaration (since I is static) None of the above What is the output of the following:
main() {
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.
void main()
{ int a=10,b=20;
a. 7.
10 20 value
b. 20 10
c. Error
d. Garbage
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.
} a)
printf(%s,&a[1]);
a++;
17
printf("%s",++*p);
bcdef
b) abcdef
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
c. harma
main( ) int i= 2; {
d. harma harma
harma hewlet-packard
a. 11. main()
b. 3, 6
c. 3
d. 0
a. Samco Systems Samco Systems b. Samco Systems amco Systems c. amco Systems d. amco Systems amco Systems mco Systems
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 }
A. 5
B. 5 10 6
C. 5 10
D. 5 6
A. Stack B. Register C. Extern D. Static 17. Which of the following function does not return an integer value?
18
B. scanf
C. strcpy
D. strlen
main() {
22. main()
int i=4;
printf("%d",abc(i=i/4));
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
case 1: printf("1");
} (a) 7
CSkills7
(d) } 0
} b. 0 1 2
a.
c. 1 2 0
d. Compiler Error
e. 2 0
24. If the CPU fails to keep the variables in CPU registers, in that case the variables are assumed a) static b) external c) global d) auto
struct xx *s;
};
char name[]="hello";
} a.
printf("%d",s->x); printf("%s",s->name);
b. 1
c. 0
d. None of the
3 hello b. Compiler Error c. Run time error d. use dot (.) operator
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;
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;
temp -> prev ->next = temp ->next; temp ->next -> prev = temp -> prev; free(temp); a)
};
b) c)
no effect
d)
shuffling of pointers
not in the end.How will you remove a node after nd from the list? a)
>right;
nd->right=nd->right->left;nd->right->left=nd->left-
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
};
}u1; u1.a=5;
char ch[2];
20
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
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
c. The results are unpredictable. d. A run-time error always occurs when *p is evaluated
{ struct student
45.
{ int day,month,year; };
equally best
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.
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
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
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
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;
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.
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
22
for (i=0;i<2;i++)
12.
6.
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",
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",
"Hetal"};
printf("%c",a[2]);
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",
23. 24.
19.
char c[2]="A";
20.
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) {
3.
o/p: infinite times statement will print #include<stdio.h> int check(int); void main() {
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.
4.
int i=45,c;
decrement(); decrement();
int check(int ch) { if(ch>=40000) return (ch/10); else } o/p:10 return (10);
void decrement() {
5.
int x=10;
int x=20;
printf("\n%d",x); } display();
25
void fun(int i,int j) { i=i*i; j=j*j;
fun(vptr);
o/p:5,2 (call by value ex:) 8. void fun(int *,int *); void main() {
printf("%d",**q);
printf("\n%d%d",i,j);
printf("\n%f",x); x=x-0.1;
int i=4,j=2;
continue; printf("\n%d%d",x,y);
fun(&i,j); printf("\n%d%d",i,j);
03 -1 4
o/p:16,2 10.
break; printf("\n%d%d",x,y);
} o/p:4 0 31
26
for(i=1;i<=5;printf("\n%d",i)); i++;
default: prize");
switch(i) case 0:
if(i>5) else
printf("\nCustomers are dicey"); case 1+0: break; case 4/2: printf("\nMarkets are pricey");
good");
case 8%5: printf("\nAtleast employees are } o/p: Atleast employees are good
switch(suite) { case 1: case 2: default: } printf("\n Diamond"); printf("\n Spade"); printf("\n Heart");
39. int k;
default: }
o/p:Heart
printf("\n Caught");
o/p:Trapped
27
case 'a':
o/p: 10,20,30,40,50
printf("\nYou entered b"); printf("\na as in ashar"); printf("\n You entered a and b");
2.
o/p: 0,20,0,40,5
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) {
} 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;
o/p:0 100 1
o/p:error(garbage value)
5.
1.
printf("\n%d",*(b+i));
same location");
28
a=20;
p=&a;
scanf("%d",p);
6.
{2,2}, {3,3}
q=&p;
o/p: 20 40 40 11.
printf("%d\n",*(*(s+i)+j));
o/p:2 2 3 3
7.
13.
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};
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;
p=p*2;
o/p:Hello World 2. #define newline "\n" void main() { printf("Hello newline World");
printf(str,300);
str="%d\n";
str++; printf(str-1,300);
} o/p:3.140000 4.
void main() {
} o/p:K 20.
printf(str,"K");
o/p:error 5.
scanf("%f",&pi); }
o/p:error
30
6.
printf("%d",sizeof(arr));
o/p:0.000000
printf("%f",maxi(x,y));
o/p: 24
int i=20;
printf("%f ",a[i]); }
printf("\n%d",**k); printf("\n%d",***&k); }
(2)only 7
(4)all 5,6,7
x=y+NULL;
printf("%d",x); }
printf("%s",7["wipro infortech");
o/p: 6
o/p:error
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:
printf("Hi");
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;
(2)0 (4)1
for(i=2;i=0;i--) { } } printf("%d",&i);
32
0/p: 50 (18)
(19) Convert to prefix (a+b)*(c/d) ans: *+ab/cd (20) #include<stdio.h> struct person { char *name; char *age; char *c; };
struct emp *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
33
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)
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]);
line1: j=&i;
} o/p: 0 0 0 0 (29) which is better memory allocation when size is not known
34
1) a alone
2)b alone
(33)Linked list is better than array because of 1) insertion a) (1) & (2) 2)deletion
3)traversal
(34) In the doubly linked list ,to add a new element in the tail node
char address[0];
printf("main");
struct details *d; How will u access address(member) 1)d->c.address >adddress 2)d.c.address 3)d.c-
wipro("welcome");
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
(b) all left subtree less than root and root less than right tree
a) 1 only (39)
d)neigher 1 nor 2
b) 2 only
c)both 1 and 2
35
#include<stdio.h> aaa() {
printf("hi"); } bbb() {
printf((a>b)?"hi":"hello");
printf("hello"); } ccc() { }
d)"->"
45)
(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)
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)
printf("wipro");
char name[15];
36
53)which statement used to read from file 1)fgets 2)fread
3)fscanf
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
4)extern variable
37
d) To read a line by line in a file fgets is used. Ans:(a),(b) and (d) 61)
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 }
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
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.
#include<string.h> void main() { int i,n; char *x = "OOAD"; n = strlen(x); *x = x[n]; for(i=0; i <n; ++i) {
38
switch(i) case 2:
printf ("Case2");
case 1:
}*/ o/p:Case2Case1
//_________________________________________________ _____________________________
/* When pointer is assign to null pointer what will be the output a. compile Error c. some output*/
printf ("wipro");
}*/
39
bbb() { } ccc() { } printf("bye"); printf ("Hello"); i++; j++; k++; l++;
void main() { int (*ptr[3])(); ptr[0] = aaa; ptr[2] = ccc; }*/ o/p:bye ptr[2](); ptr[1] = bbb;
printf ("something");
}*/
o/p: something will print infinitely //_________________________________________________ _____________________________ /*#include<stdio.h> define statement to
}*/
o/p: error
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;
40
}*/
o/p:error
//_________________________________________________ _____________________________ /*#include<stdio.h> struct a { int no; int *no1; int *no2;
printf("%d",sizeof(arr));
} *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() {
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]);
}*/
printf("Hello"); default:
o/p: 00000
o/p:error /*#include<stdio.h>
41
}*/
o/p: no output
//_________________________________________________ _____________________________ /*#include<stdio.h> void main() { int i=5; printf ("%d", ~i);
o/p: -6
7.
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.
e. None of the above Ans::b 9. How many times Wipro Technologies printed in the following code: for(i=0;i<5;i++) {
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);
ans::c//if static char buffer is used it would have worked 12. main() {
} e. 3
f. g.
h.
Garbage value
} void change(char *t) { char *ab="new test"; *t=*ab; new test test nest None of the above
} b. c. d. e.
Ans::d 6. main() {
char *fun();
a.
b. c.
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
return (ptr);
int main()
printf("Hi"); break;
case 3>2:
x = "HELLO";
printf("Hello"); break;
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;
a.
b. c.
d.
Ans::b Garbage value //used aswipro infotech+7 12. Predict the output char p[]="hello";
44
struct emp *pemp; How will you access city from the *pemp; a. c. b. pemp->a->city pemp->*a.city pemp->a.*city
(c)Bye
(b)Hi!
(d)Hi!Bye
(d)Hi!Bye
printf("%d ",x);
if (-1+1+1+1-1-1-1+(-1)-(-1)) } printf("Bye");
{ return(60); }
(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
(a)0 Nas::
(c)3
(b)7
(d)No Output
b. d.
printf("%d",a); }
(b)Run-Time error
Ans::c 17. What will be the output of the following program : void main() {
(d)Unpredictable
printf("Hi!");
if (-1) printf("Bye");
else; printf("Again");
45
(b)Test
(c)Compile-Time Error
(d)TestAgain
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
#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.
a) puts()
b) gets() c) scanf()
d) vsscanf() Ans::b
#include<math.h> void main ( int a,char *b[]) { int n; char *str = "324.89"; n = atoi(str); printf("%d",n); }
d.
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
b) no output c) %d d) 0
46
Ans::d
b. c. e.
d. Ans::a
a) 9
b) 7 c) 5
34. main()
printf("Enter 2 numbers\n");
a.
d. None of the above Ans::d//abnormal program termination 35. main( ) { char *q;
b. c.
ibj!gsjfoet
If a=10, b=10 What is the output a. B is less than A A is less than B Error No output
for (j=0; j<3; j++) printf(%c ,*(q+j)); for (j=0; j<3; j++) printf(%s ,(q+j)); }
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
b.
Ans::d
c. d.
47
Ans::a
d.
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.
c. d.
b. c.
#define TRUE 1
printf("hello");
main()
printf("bye"); }
a. b.
Ans::a
c. d.
TRUE FALSE
} a.
b. d.
hi
b. c.
-1
Error 0
Ans::hi
48
int a;
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'
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
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
return((x-y)?y:x);
6) which data structure is best for searching an element in the given list a) arrays
fun(a); printf("%d",y);
ans::error
11) main() {
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]);
49
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
} char *x() {
strcpy(result,"anything good"); }
ans::1
printf("%d",i==10);
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);
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
printf("case1"):
defalut:
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
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;
} {
ans::hello {
????
} fp=fopen(data,"r");
fclose(fp);
}*s;
s->name[]=(char*)
23) what is the header file to be included for doing mathematical calculations? 24) what is the way to declare a float pointer? float *f;
29) main() {
p=a[2]; }
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() {
printf("%f",f1);
27) for(i=0;i<2;i++) {
31)which of these is replaced by a switch block? a) while loop b) do while c) for loop d)else if
printf("wipro"); }
51
37) all the local variables are stored in ----------------a) stack b) heap
38) Once you call a function,all the return addresses are stored in ---------------a) stack b) heap
} {
i) all nodes except leaf node has exactly two child ii) root node is greater than the left sub tree and
strcpy(gxxx(),g); g=gxxx();
strcpy(g,"old string"); }
printf("%s\n",gxxx());
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
35) main() { night"}; char *k[ ]={" Good Morning","Good Evening","Good printf("%s\n",k[0]); 41) struct node {
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; {
};
while(back!=NULL) printf("%d",back->data);
back=back->left;
52
}abc;
struct a *g;
suppose start and end are the pointers pointing to the the output of the following snippet front=start; back=end; {
while((front!=back)&&(back->left!=front)) temp=front->data;
};
front->data=back->data; back->data=temp;
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
} ans::main
printf("main");
} void main() {
prod(a,b,c);
int a=3,b=4,c=5;
printf("Hai");
meq(); printf("Hello");
} { }
53
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?
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) {
sptr--; }
printf("%c",*sptr);
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,
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]
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
Explanation:
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:
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.
long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double. Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .
4. main() { static int var = 5; printf("%d ",var--); if(var) main(); } Answer: Explanation:
54321
extern int i; specifies to the compiler that the memory for i is allocated in
some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .
initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.
5. main() { 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);
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).
56
Explanation :
left shifted four times the least significant 4 bits are filled value be printed as a hexadecimal value.
Explanation:
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 :
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.
inside the loop. It is executed only when all other cases doesn't match.
used twice. Same maths rules applies, ie. minus * minus= plus. Note:
-- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.
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
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.
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
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).
};
58
Answer:
Explanation:
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
structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.
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
\n - newline \r - linefeed
\b - backspace
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.
popping out from the stack. and the evaluation is from right to left, hence the result.
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).
28)
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() {
Answer:
Explanation:
Note:
100; printf("%d\n",100);
Answer:
Some address will be printed. Function names are just addresses (just like
Explanation:
far pointer 30) main() {
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() { }
int i=400,j=300;
printf("%d..%d");
Answer:
clrscr(); clrscr();
Explanation:
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)
printf("%c\n",*&*p); }
p="Hello";
t=names[3];
Answer:
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
Explanation:
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:
printf("PP");
Answer:
Answer:
function main
Explanation:
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)
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:
Compiler
Error:
Constant
expression
Explanation:
The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).
40)
Note:
Answer:
Answer:
Explanation:
Explanation:
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)
int x=3;
};
char name[]="hello";
printf("%s",s->name); }
62
44)
Answer:
Explanation:
Compiler Error Initialization should not be done for structure members inside the structure declaration
Answer:
function main.
42)
#include<stdio.h> main() {
Explanation:
use from the point of declaration. Even available for main. Hence an error. 45) main() { extern out;
}; struct yy *q; } };
printf("%d", out); }
Answer:
Answer:
Explanation:
Compiler Error in the end of nested structure yy a member 46)
Explanation:
{ show();
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.
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
Answer:
=
Explanation:
printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1);
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( ) {
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( ) {
++*ptr;
Answer:
Let us consider the array and the two pointers with some address
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
p = a;
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
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
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)
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
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
violet};
Explanation:
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.
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:
error: assert
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
and this will disable all the assertions from is a good debugging tool to make use of.
printf(%s\n,x);
55)
Answer:
66
60) main() { } main();
Answer:
Explanation:
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
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()
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() {
cptr=&c; vptr=&v;
printf("%c%v",c,v); }
Answer:
is Unknown.
Explanation:
not of type void, since void is an empty type. In the second line you are creating variable an error. 62) main() {
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
59) What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;
%d
Answer:
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.
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; }
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:
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() {
puts("NULL");
puts("FALSE");
Answer:
Answer:
Explanation:
TRUE The input program to the compiler after processing by the preprocessor is, main(){ if(0) 67)
Explanation:
or not.
puts("FALSE");
printf("%d %s",list[0],name); }
Answer:
68
Compiler error (in the line arr1 list =
{0,1,2,3,4})
Explanation:
arr2 is declared of type array of size 5 of characters. So it can be used to declare the variable name of the type arr2. But it is not
printf("%d",*j);
Answer:
Explanation:
10
68)
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() {
} printf("%d",i); }
} printf("%d",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:
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() {
Answer:
Explanation:
of constant 72)
#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
Answer:
Explanation:
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
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.
74)
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.
Explanation:
76)
struct aaa{
Note:
70
Since structure point is globally declared x
{ }
return z-32;
Answer:
Explanation:
are wrong. 81)
Answer:
Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be returned.
79)
main() {
Answer:
Explanation:
passed to the function sum without converting it to integer values. # include <stdio.h> int one_d[]={1,2,3}; main() {
Answer:
Explanation:
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
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:
main()
enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed. get printed.
Answer:
Explanation:
bye
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.
{ _AX = 1000; }
Answer:
85)
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");
Answer:
loop
Explanation:
Answer:
86)
Explanation:
will be, i 0 1 2
72
x
4 3 2 89) main(){
-4 -2 0
Answer:
Explanation:
a pointer.
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
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:
93)
main() {
Explanation:
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:
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);
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)
Explanation:
0000
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() {
} {
Answer:
Explanation:
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
Compiler
Error.
We
cannot
apply
null character. Hence the 'I' will hold the value equal the 6 will be printed. 99) void main() {
Explanation:
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
2. 3.
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";
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:
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)
void main() { static int i=i++, j=j++, k=k++; printf(i = %d j = %d k = %d, i, j, k);
101)
Answer:
Explanation:
by default. 104)
Answer:
if(printf("%d",printf("%d"))) break;
else }
75
continue;
Answer:
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)
printf("%u ",i);
Answer:
Answer:
Explanation:
Explanation:
10
The macro expands and evaluates to as: x+2*y-1 => x+(2*y)-1 => 10
108)
int x,y=2,z,a;
Answer:
Explanation:
printf("%d %d ",z,x);
Note
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
goes
while(+(+i--)!=0) i-=i++;
printf("%d",i);
76
Answer:
Explanation:
Compiler error: undeclared function write Pascal keyword doesnt mean that pascal
-1
float f=5,g=10;
} {
printf("%lf\n",fmod(f,g));
Answer:
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;
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);
Answer
Answer:
Explanation
-128 Notice the semicolon at the end of the for loop. THe initial value of
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()
The
the
following
statement
Answer
Definition.
integers.
Answer
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() {
printf("%d\n",i); }
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
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
Answer Explanation
Explanation:
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;
something is not already known to the compiler making the declaration int some = 0; source code. 119) effectively
removed
from
the
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;
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
79
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
*a=*a+*b;*b=*a-*b;*a=*a-*b; } main() {
int x=10,y=20;
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)
{ 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)
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)
Explanation:
main() {
int i=5; }
printf(%d,i=++i ==6);
printf(%c,c);
Answer:
Answer:
Explanation:
Explanation:
The expression can be treated as i = (++i==6), because == is of higher precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.
Parenthesis just works as a visual clue for the reader to see which expression is first evaluated. 126) 128) main() {
{ 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)
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:
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
assignment
Answer:
Explanation:
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.
Answer:
134)
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.
135)
main() {
Answer:
int i=10,j=20;
Explanation:
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() {
Explanation:
int i=4,j=7;
if(i,j) j = i; else } j = j;
Answer:
else
j = j;
136)
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
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);
int i=5,j=10;
i=i&=j&&10; }
Answer:
printf("%d %d",i,j);
Answer:
Explanation:
83
case 1: printf("1"); case 2: printf("2"); default : printf("0");
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p)); sizeof(a), strlen(a)); } %d", sizeof(p),
sizeof(*p),
Answer:
integral
Answer:
Explanation:
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.
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(The dimension of the array is %d,
142)
main() {
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)
143)
int arr[10];
DIM(arr)); }
84
} { }
printf("x=%d y=%d",x,y);
Answer:
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
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)); } }
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
} 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.
Explanation:
%d",
*((char*)iPtr),
147)
Answer:
Explanation:
11
individual bytes are taken by casting it to char * and get printed. 149) main() { int i = 258; printf("%d
85
} %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
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)
}stud;
struct date {
Answer:
Explanation:
556 The integer value 300 in binary notation is: 00000001 00101100. It is memory (small-endian) as:
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.
154)
main() {
struct date; {
86
struct student char name[30]; struct date dob; struct date { int day,month,year; stud.rollno, 156)
feof(fp)
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:
};
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;
struct student {
If the body of the loop never executes p is assigned no address. So p remains NULL where *p =0
may result in problem (may rise to runtime error NULL pointer program). 158) What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); } return s;
Explanation:
fread reads 10 records and prints the names successfully. It will return EOF only when fread tries to read another record and fails
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
87
macro");
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:
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
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:
(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)
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
Is it not legal for a structure to contain a type as in this case. Because this will cause
the structure declaration to be recursive without end. Is the following code legal? struct a {
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;
Answer:
Explanation:
No
any type is of same size). This type of structures is known as self-referencing structure. 164)
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 *));
Answer:
}aType
Explanation:
No
printf(sizeof (int *) = %d \n, sizeof(int *)); printf(sizeof (double *) = %d \n, sizeof(double *)); unknown *) = %d
\n,
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
Explanation:
};
Answer:
Explanation:
Yes
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)
curt one
1) printf(%s,str); 2) printf(str);
// or the more
89
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
Prefer the first one. If the str contains any format characters like %d then it will result in a subtle bug.
170)
Answer:
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:
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.
174)
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
Answer:
Explanation:
Implementaion dependent
175)
90
output correctly because the character constants are stored in to dangling pointers. 179)
printf("\n %u %u ",j,k);
Answer:
pointer
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()
{ { {
printf("%d",i);
const
volatile
unsigned
i=30;
} } }
Explanation:
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
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.
Answer:
puts(someFun()); Answer:
Explanation:
string constant
91
Explanation:
Note :
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:
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:
} void PrintVal()
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(); }
Answer:
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: };
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
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
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 {
int main()
{ base baseObject;
Answer:
Explanation:
Remember that baseFunc is a virtual function. That means that it supports run-time polymorphism. So the function corresponding to the derived class object is called.
void main() { int a, *pa, &ra; pa = &a; ra = a; } cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
Answer:
/* 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
};
/*
Answer:
Explanation:
some's destructor some's destructor Destructors can be called explicitly. Here 's.~some()'
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);
Answer:
has a body
public:
Explanation:
Arrays cannot be passed to functions, only pointers (for arrays, base addresses) can be passed. So the arguments int *ptr and int prt[size] have no difference
};
as function arguments. In other words, both the functoins have the same signature and so cannot be overloaded. */
/*class fig3d : public fig2d { int dim3; fig3d() { dim3=7;} virtual void operator<<(ostream &rhs);
public:
}; {
94
}
return false;
void main(){
*/ void main() { fig2d obj1; fig3d obj2; obj1 << cout; obj2 << cout;
} Answer :
//
Explanation :
// } /*
Just like normal functions, operator functions can be called recursively. This program just illustrates that point, by calling the operator == function recursively, leading to an infinite loop.
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;
else{
using output
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.
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:
(c) data_7
(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
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() {
(j) '\'' (k) ' ' (a) VALID (b) VALID (c) VALID
} Answer :
(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 :
(j) VALID
96
__________________________________________________ _______________________________________________
(k) VALID
(i) VALID
[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
(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
[Q006]. What will be the output of the following program : void main() printf("%f",123.); } (c)123.00 {
__________________________________________________ _______________________________________________
(a)123
Ans. (d)
[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
(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)
(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
__________________________________________________ _______________________________________________
(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() {
(c)15
(d)None of these
__________________________________________________ _______________________________________________
[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;
(c)-15
[Q011]. What will be the output of the following program : void main() {
(a)100
[Q015]. What will be the output of the following program : void main() {
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 }
(c)INVALID
(d)None of these
__________________________________________________ _______________________________________________
98
+123456789
[Q016]. What will be the output of the following program : void main() {
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()
(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;
__________________________________________________ _______________________________________________ [Q019]. What will be the output of the following program : void main() { char c1='A', c2='B', c3='C';
Ans. 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -24680
123456789 -2222 5555 12345 -13579 -24680 123456789 -2222 5555 12345 -13579 -2222 5555
-24680 123456789
A B C A B C
__________________________________________________ _______________________________________________
99
[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);
__________________________________________________ _______________________________________________
Swimmers C
[Q022]. What will be the output of the following program : void main() {
int a=1,b=2,c=3;
} [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
(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
[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;
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);
(c)Sum=589
(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;
(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("%[^*]",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()
(a)5
[Q001]. What will be the output of the following program : void main() { }
(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
(a)8
printf("d%",8); } (c)d%
[Q002]. What will be the output of the following program : void main() {
} (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
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
(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 {
__________________________________________________ __________ [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!' &
(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
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
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; }
[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 } {
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 {
} (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; }
} (a)3 4 6 5
printf(str,val); (c)25
__________________________________________________
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
[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
105
int val=5; {
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
(d)Hi!Bye
[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 {
(b)5 (d)
(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)
printf("Bye"); (b)Hi!
106
__________________________________________________ _______________________________________________
(d)Hi!Bye
[Q007]. What will be the output of the following program : void main() {
__________________________________________________ _______________________________________________
[Q004]. What will be the output of the following program : void main() { (a)0
printf("Hi!");
(c)3
(b)7
(d)No Output
[Q008]. What will be the output of the following program : void main() {
[Q005]. What will be the output of the following program : void main() {
printf("%d",~val); }
(b)-1
(d)-1 0
(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))
(c)0xefff
(b)0xe75f
.(d)None of these
(c)Testing
[Q010]. What will be the output of the following program : void main()
107
unsigned val=0xabcd; {
(b)Run-Time error
(d)Unpredictable
__________________________________________________ _______________________________________________
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;
(d)Unpredictable
__________________________________________________ _______________________________________________
[Q015]. What will be the output of the following program : void main() { int a=1,b=2,c=3,d=4; if (d > c)
[Q012]. What will be the output of the following program : void main() {
(d)Unpredictable
(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);
108
printf("%d\n",i); (b)1 2 3
printf("%d %d",c,a);
(d)None of these
(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;
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");
(d)None of these
[Q021]. What will be the output of the following program : void main() { float i;
(c)Run-Time Error
__________________________________________________ _______________________________________________
[Q022]. What will be the output of the following program : void main() {
} (c)10
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
(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;
printf("%d",i); }
printf("Choice1"); break;
(b)2468
(d)None of these } }
__________________________________________________ _______________________________________________ [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) __________________________________________________ _______________________________________________
[Q028]. What will be the output of the following program : void main() {
(c)23456
(d)None of these
switch(--choice,choice-1,choice-1,choice+=2) {
case 1:
110
case 2:
printf("Choice2"); break;
(c)01234
__________________________________________________ _______________________________________________
default: }
printf("Default");
[Q032]. What will be the output of the following program : void main() {
__________________________________________________ _______________________________________________ [Q029]. What will be the output of the following program : void main() { (a)9 6 3 1 Ans.
__________________________________________________ _______________________________________________ [Q033]. What will be the output of the following program : void main() { int i;
(c)Executes INFINITELY
(d)None of these
__________________________________________________ _______________________________________________
[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.
(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);
(b)4
__________________________________________________ _______________________________________________ [Q031]. What will be the output of the following program : void main() { static int j;
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() {
Memory representation of int i=320 So char pointer ptr is pointing to only first byte as shown above figure.
*ptr i.e. content of first byte is 01000000 and its decimal value is 64.
How to represent char, int and float data in memory? Data type tutorial.
(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
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
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;
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
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
Operator tutorial.
(7) What will be output if you will compile and execute the following c code?
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 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?
(9) What will be output if you will compile and execute the following c code?
#include "stdio.h"
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.
(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?
#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.
(13) What will be output if you will compile and execute the following c code?
(12) What will be output if you will compile and execute the following c code?
(e)Compiler error Output: (e) Explanation: In c any character is starting with character \ represents
118
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:
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
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
(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:
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
(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
(18) What will be output if you will compile and execute the following c code?
(19) What will be output if you will compile and execute the following c code?
122
test.c 6: } test.c 7:
to increment the constant number. Hence compiler will show Lvalue required.
(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
(20) What will be output if you will compile and execute the following c code?
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++);
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.
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.
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= 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.
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.
126
Array tutorial.
(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?
(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
(27) What will be output if you will compile and execute the following c code?
(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
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)
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
(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?
(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.
Output: (b) Explanation: Default value of enum constant = value of previous enum
constant +1
Default value of first enum constant=0 Hence: BLUE=GREEN+1=-20+1=-19 YELLOW=BLUE+1=-19+1=-18 Complete tutorial of enum data type with examples.
(33) What will be output if you will compile and execute the following c code?
(34) What will be output if you will compile and execute the following c code?
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.
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;
132
}
(a)-1 -1 (b)-1 32767 (c)-1 -32768 (d)Not equal (e)Compiler error Output: (a) Explanation:
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); }
(39) What will be output if you will compile and execute the following c code?
(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.
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?
void main(){ clrscr(); goto abc; printf("main"); getch(); } void dispaly(){ abc :
(42) What will be output if you will compile and execute the following c code?
printf("display"); }
(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?
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: }
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.
(46) What will be output if you will compile and execute the following c code?
void main(){ int i=11; int const * p=&i; p++; printf("%d",*p); } (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.
138
}
What is precedence?
(48) What will be output if you will compile and execute the following c code?
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?
139
(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:
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)
141
(d) Compiler error (e) None of these
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.
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++; }
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
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?
Advance c tutorial?
144
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; }
Advance c tutorial.
(56) What will be output if you will compile and execute the following c code?
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
Pointer tutorial.
146
(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;
#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
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.
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?
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");
(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.
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.
(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
(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.
ptr pointer will point first eighth byte then seventh byte then sixth byte then fifth byte then fourth byte then third byte then second byte then first byte as shown in above figure.
Content of eighth byte: Binary value=11001101 Decimal value= -128+64+8+4+1=-51 Content of seventh byte: Binary value=11001100 Decimal value= -128+64+8+4=-52
Decimal value=64
Note: Character pointer treats MSB bit of each byte i.e. left most bit of above figure as sign bit.
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)
(64) What will be output if you will compile and execute the following c code?
String tutorial.
(63) What will be output if you will compile and execute the following c code?
(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
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.
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
154
Operator tutorial.
(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?
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
character while strlen function returns length of a string excluding null character.
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 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();
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 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.
(72) What will be output if you will compile and execute the following c code?
157
Explanation:
Comma operator.
Operator tutorial.
(73) What will be output if you will compile and execute the following c code?
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 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
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
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
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
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]?
2) name is one dimensional,30-element floating point 3) name is one dimensional ,30-element character
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;
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
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
4)\t
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
27) The global variables by default belong to 1) the register type 3) the auto type 2) the static 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
3) controls the merging of the program listing 4) specifies how many characters positions will be used for a number
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
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>
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( )
3) putchar( )
4) scanf(
53) An expression 1) is a collection of data objects and operators that can be evaluated to a single value 2) is a name that substitutes for a sequence of
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
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
55)The single character input/output functions are 1) scanf( ) and printf( ) 2) getchar( ) and printf( )
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
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)
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
1.
{ Int a[5];
main()
a)
a[-2]=10;
a[2]=1; printf(%d,-2[a]); }
a)
} a)
Ans b
Ans c 3.
7)main() {
Int a[3]={1}; }
Printf(%d,a[1]);
a)
165
Ans b 8) main() Ans: b
Printf(%d%d%d,n[2][1],n[1][1],n[3][1]); }
Printf(%s %d %d\n,a,sizeof(a),sizeof(*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 --------&-------------
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
a)
A b) c c) 65 d) error
2) a) b) c)
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
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;
2)
n[24]=200; }
printf(%d%d,*n,*(n+24)+*(n+0));
3)
4)
167
ans::in wipro 5) { main() Char *p=algc;
Printf(%c,++*p++); } Printf(%c,*++p);
} p = a; {
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);
7).What would be the output of the following program. main() { } ans::222223465 10. #define ABC #define XYZ void main() { int #define XXX
20 10 ABC - XYZ
};
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)
t=names[3];
} {
} 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;
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);
b.
} }
c. d. Ans::a e.
void main()
{ printf("%d",compute(5)); }
20.int main()
int i, j; i = 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( ) {
b. d.
1 50 0
char a[]="123abcd";
clrscr(); printf("%d",strlen(a));
getch(); }
170
a. c.
b. d.
6 7 8 5
sum+=p++;
printf("\nsum=%d",sum);
d. 5 4 3 2 1 0
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); }
break;
break;
171
a. 12 12 c. 12 13
} a. 5 5 3 b. 4 5 3 c. 2 5 3 ans::c
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;
{ 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
printf("%s",++*p);
printf("\n%s",*p++); printf("\n%s",++*p); }
a. harma
b. dharma harma
harma ewlet-packard
ewlet-packard
printf("%d",*p++); a. 5
b. 6
ans::d
hewlet-packard
char *str1="abcd";
} a. Samco Systems Samco Systems b. Samco Systems amco Systems c. amco Systems ans::b d. amco Systems amco Systems mco Systems
172
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
Ans:a 21. void main() { struct emp { struct e { }e1; int a; int *a;
};
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; };
b. 2 2 d. 4 2
}; 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
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 ->next -> prev = temp -> prev; a) b) c) ans::c no effect inserts a node deletes a node
d)
shuffling of pointers
(b)10 9 8 7 6 (d)10 8 7 6 6
{ 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) {
B.
C. 5 10 6
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;
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
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
176
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
main() {
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
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;
temp = head; {
(a)7 (b)C7 (c)Compile-Time Error(d)CSkills7 Ans::d 4. What will be the output of the following program : int main() {
c) d) ans::c 1.
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",5+val++); return(0); }
int x=2,y=3,z=4;
y+z)));
{ printf("%d",sizeof(int)); return(0); }
void main()
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.
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
DHBEAFCIGJ
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
a. Ans::d 13.
} Compiler Error b. 8
return(ret);
c. 6 d. 7 a.
} Junk
*a=*a+*b;*b=*a-*b;*a=*a-*b;
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()
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() {
180
fp2=fopen("one","w") ;
G
a. b. c. d. ans:d 22.
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.
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.
181
23. When fopen() fails to open a file it returns } }
printf("\n %d",x);
ans:a 24.
printf("%d",x);
Predict the output 20 40 Which function is used to detect the end of file 40 20 40 20 3.
#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;
1.
#include<stdio.h>
int x = 20;
#include<stdio.h>--------------------------------doubt main() {
printf("\n %d",x);
};
0 0.000000
Garbage values
182
5.
#include<stdio.h> main() {
o\p:
default value 8.
#include<stdio.h>------------doubt main() {
} o\p: 1
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() {
case 1:
case 2:
case 3:
10.
#include<stdio.h> main()
183
int i=10, j=15; if(i%2= = j%3) { } printf("Same"); 13.
else { }
printf("Different err");
} 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("Welcome"); main();
} else { }
printf("C");
printf("C++");
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]);
o\p b c 16.
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
1. Which of the following does not have an unary operator? 1) -7 3) j 2) ++i 4) all of the
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
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
11) Which of the following array is defined in the statements Char name[30]?
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
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
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;
9) Function definition void check(int i ,char*j) is 1) call by value definition 3) both (1) and (2)
2)18 4) 0
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
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
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
4)\t
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
28) The bit fields are the members of a/an 1) array 2) structure 3) union 4) inter section
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
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
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
39) If an error occurs while opening a file the file pointer is assigned a value 1) NULL 2) stdout 3) sstderr
4) not defined
1) argument
2) character array
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
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++
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
45) The number of the relational operators in the c language is 1) four 2) six 3) three 4)one
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(
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
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
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
55)The single character input/output functions are 1) scanf( ) and printf( ) 2) getchar( ) and printf( )
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
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)); }
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
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
190
a) hello world
7) what is the prefix expression for the given Infix expression A+B*C/D Ans::+A/*BCD
printf("%s",str);
char * fun() {
a) hello world
b) Compiler error
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
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
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
for(i=0;i<5;i++) { a++; }
printf("%c",*s++);
printf("%d",a[i]);
a) 0 0 0 0 0 c) 0 5 0 0 0
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
b) malayalaM c) error
c) 4 d) 8
int b; }
192
printf("%d %d",sizeof(e1),sizeof(*e1));
printf("wipro"); }
return p; } main() {
24) Is allocating a block of memory effectively the same as defining an array? a) True b) false
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]); {
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?
????? {
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);
193
queue?
then how will you add a new element called 'item' in the
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
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
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)
traverse(end->prev); printf("%d",end->data);
194
1.
#include<stdio.h>
c) compilation error
int x = 20;
printf("\n %d",x);
43) how will you refer the last node in the doubly linked list which is pointed by the pointer variable 'cursor'? a)cursor==NULL b)cursor->link=NULL c) Cursor->link=0 d) cursor->data=NULL
} 44) how will you refer the previous node of the pointer }
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++
#include<stdio.h> main() {
195
#include<stdio.h>--------------------------------doubt main() {
default:
case 1:
};
0 0.000000
#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
#include<stdio.h>------------------------------doubt main() {
196
elseif (x>y) printf("x is greater than Y"); elseif (x<y) } printf("X is less than Y");
#include<stdio.h> main() {
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 {
printf("C++");
}o\p 7 14.
197
How many times the program will execute? 32767 65535 Till the stack doesnt overflow 15. #include<stdio.h>----------------------doubt void fun(char *);
}o\p 5 19.
#include<stdio.h> main() {
}o\p 11 20
void main() { char a[100]; a[0] = 'A', a[1] = 'B'; a[2] = 'C', a[3] = 'D'; fun(&a[0]);
for(i=strlen(sentence)-1;i>=0;i--) { } putchar(sentence[i]);
} o\p b c 16.
}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( ) { } {
printf("%d\n", i * 3);
a.
b. c.
6 7 8 5
d. 6. main()
f. g. h. i.
printf("%d",var); 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.
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; } }
a. One
b. Two
c. Default
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); }
a. 12 12 c. 12 13
sum+=p++; }
a. 3 2 1 0 b. 3 2 1 c. 2 1 0 d. 2 1
{ 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
char *str1="abcd";
200
char str2[]="abcd"; }
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
clrscr();
i=64/square(4); printf("%d",i); }
char *s[]={"dharma","hewlet-packard","siemens","ibm"};
a. 7 b. 16 c. 64 d. 4
a. harma harma
{ int i=15,j=10,k=0;
ewlet-packard
b. dharma harma
a. 16 17 11 2
hewlet-packard
b. 17 17 11 2 c. 16 16 11 2
d. harma
harma hewlet-packard
void main()
201
};
int a;
printf("%d %u",a.no,a.no);
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)
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
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.
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
F.
203
#include <stdio.h>
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
realloc
What is the output of the program if the input is 103? main() { int p = 234;
204
E. F.
3 103 103
printf("%d",abc(i=i/4));
G. In 'switch' statement H. In 'goto' labels I. None of the above 17. 2. Queue is _________________ a) LIFO c) FIFO
int x;
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
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;
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.
25, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69 e) 69 f) 25 g) 26 h) 9
y+z)));
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
temp = head;
return(0); }
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
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()
9.
In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) malloc (d) Queue
8.
Traverse the given tree using Inorder, Preorder and Postorder traversals.
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.
15.
main()
} b.
b. 5 5.000000 c. 6 6.000000 d.
case 1: printf("1");
12.
} } 0 b. 0 1 2
c. 1 2 0 d. Compiler Error e. 2 0
} {
b. 13.
Compiler Error b. 8
b.
17. main () { int i = 5; switch (i) { static int i; i = 3; i = i * i; case 3: case 4: case 5:
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()
208
b. 9 b. 10 10 c. 0 5 d. 18 18 e. 18 5
18. What would be the output of the following program. Int fn(int); main()
fn(int i) {
} (a) 10
H
e. f. g. h.
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;
ans::1 10
3.2. main()
J
}
e. f. g.
h. 23.
Any node
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
z=++x||++y&&++z; }
210
int i=10; i=!i>14; printf ("i=%d",i);
ans::0
printf("%d %d %d %d",a,b,c,d); }
1.20. main()
int x,y=2,z,a;
1. main()
printf("%d %d ",z,x);
p++; p++;
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);
t=names[3];
} ans::64
i = 64/square(4); printf("%d",i);
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);
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("wipro"); }
212
4) all the local variables are stored in ----------------a) stack b) heap
back=back->left; }
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
};
first or the last node. Then if we are going to delete a node after ptr, then the code will be a) ptr=ptr->link; b) ptr->link=ptr;
c) 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);
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*+
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
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
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)
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 *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;
};
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)
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)
b) -
};
and also not in the end. How will you delete a node ptr?
>right=ptr;free(ptr);
215
delete(13,root);
int a = -1,b=2,c=3,d=4;
d=++a||++b&&++c;
b) 10,5,8,25,13,45,32,36,70,66 d) 8,5,32,36,10,66,45,70,25,13
19) The preorder traversal is 5, 3, 66, 30, 77, 70 .What will be the root node a) 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() { }
NOT DECLARED What will be the values of i,j,k ? a) hello , India, hi run time error void main() { }
printf();
d) Neither i nor ii
(a)Run-Time Error
(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()
printf("d%",8); (a)8
(c)123.00
(d)123.000000
of these
(b)Compile Error
(c)%d
(d)None
(a)
216
(a) 2,5 (b) 2,5.4 (c) 2,5.000000 (d) none of these
(c)Compile-Time Error
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
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];
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;
} b=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;
217
a++;
(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
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); }
(a)Compile-Time error
(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; }
}; 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( )
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
(a) 40 41 error
24. The syntax of a function call statement is a) function name (argument list);
b) [storage class] function name (parameter list); c) function name (parameter list); 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.
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
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
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.
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
d.
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.
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
__FILE__,__LINE__), abort())
c. d.
a. c.
b. d.
Answer: c
d.
Answer: a 4.
#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;
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: D
----fgets(x,20,fp);
printf(%s,x);
221
if(me==you) else }
printf("Hello"); printf("Welcome");
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:
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.
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
2. Answer :
Answer: d
Explanation :
inside the loop. It is executed only when all other cases doesn't match.
3. main() {
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).
6. main()
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
} }
break;
4. Answer: Compiler
Error:
Constant
expression
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:
statements.
7. Answer:
5. main()
i = -1, +i = -1 Explanation:
int i;
just because it has no effect in the expressions (hence the name dummy operator).
223
else 8. main() }
char not; not=!2; printf("%d",not); } 8. Answer: Explanation: ! is a logical operator. In C the value 0 is 0
10. Answer:
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() {
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:
When two strings are placed together (or separated by concatenated white-space) they (this is called are as
12. int i;
"stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".
Explanation:
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");
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:
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.
int x,y=2,z,a;
printf("%d %d ",z,x);
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
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.
free code.
225
17. Answer
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.
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++) ; }
printf("%d %d",i,j);
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.
j = j;
21. main() {
default : printf("0");
19. Answer:
226
24. Answer:
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.
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:
{ char ch;
The char type may be signed or unsigned by default. If it is signed then ch++ is executed after ch reaches 127 and rotates
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:
-- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.
227
char a[]="\0";
if(printf("%s\n",a)) else }
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.
dependent.
is
implementation
28. What is the output of the program given below main() { signed char i=0;
for(;i>=0;i++) ; printf("%d\n",i);
implementation dependent behavior. But dont write programs that depend on such behavior.
Explanation Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. The inner loop
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:
Explanation:
hand
operation.
side
of
an
assignment
228
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
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
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
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.
printf("%d..%d",i++,j); printf("%d..%d,i,j); }
35. Answer:
0..0 Explanation:
229
enough to determine the truth value of the following the if statement is not executed. get printed.
Note
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);
printf(%d,i=++i ==6);
39. Answer: 1
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.
printf("%u ",i);
} 37. Answer:
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. }
40. Answer: 41
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
remaining expression is not evaluated and so the value of i remains the same.
230
an expression, when any of the operands value becomes false and hence the
become false, the whole expressions truth remaining expression will not be evaluated. (anything) will not be evaluated. false &&
1. main() {
Ans::Hello World
printf("sizeof(i)=%d",sizeof(i));
Ans: 1 6. main() {
extern int i;
i=20; printf("%d",i);
int i=10;
Ans: 0
i = 64/square(4); } printf("%d",i);
case 2:printf("two");
Ans: 64
case 3: printf("three"); }
main() { #define a 50
231
}
i++;
printf("%d",a);
} {
fun() here:
printf("PP");
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;
printf("%p",main);
clrscr(); } clrscr();
Ans: 1 ya since i++ will not increment first time so I is o in for thats why
232
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
show(); }
void show()
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"); }
Ans: -1 -1 21. What are the files which are automatically opened when a C file is executed?
{ int y;
if( (y%4==0 && y%100 != 0) || y%100 == 0 ) else printf("%d is not a leap year",y);
Ans: stdinput,stdoutput,stderror.
233
Ans:Error?? 30. int i;
31 22 //GUD 1
28. main()
31. main(){
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
printf("c aptitude");
29. main(int argc, char **argv) { printf("enter the character"); getchar(); } sum(argv[1],argv[2]); }
while(1) {
continue;
return num1+num2; }
234
41. main() { char str1[] = {s,o,m,e}; while (strcmp(str1,str2)) } Ans: no output. 42. main()
printf("%d %d ",z,x);
a=2;
printf("%d %d",i,j);
} Ans: infinite {
36. main()
char i=0;
for(;i>=0;i++) ; printf("%d\n",i); }
} Ans: error
Ans: -128
39. main() {
44. main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); float i=1.5; switch(i) {
case 1: printf("1");
} Ans: error
while (strcmp(some,some\0))
235
int i=20;
} Ans: HELLgarbage 51. main() { printf("%d", out); } int out=100; Ans: error
printf("%d\n",i);
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);
SESSION 2
Ans: mmmm aaaa nnnn 2. main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); } Ans: 1 2
*3. main()
{ }
printf("%x",-1<<4);
236
Ans: 0xfff0 4. main() } Ans: Ok here else
}
Ans: 2
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("%d\n",i);
printf("%d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }
char i=0;
%d
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
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);
Ans : 5 4 3 2 1 2. main()
int arr[10];
Ans: 0 0 1 3 1
int DIM(int array[])
15.
3. #include<stdio.h>
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
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
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()
char
names[5][20]={"pascal","ada","cobol","fortran","perl"};
} Ans: Error
{ int i=5,j=6,z;
printf("%d",i+ + +j); }
int i=_l_abc(10);
printf("%d",i++ +++i);
239
Ans: 6 *18. void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); }
printf("%u \n",gotit=--giveit);
printf(p-2,300);
printf("%d ",i);
Ans: 0 0 0 0
Ans: infinite
Ans: 1
23. main()
240
int i=0; 28. main() { int i=4,j=7;
Ans: 4 1
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++);
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);
1.
main() {
SESSION 4
printf("\n %u %u ",j,k);
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 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 }
\n,
Ans:300
*9. main()
*((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)
%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++)
printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), }
*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));
} Ans : 1 1 1 1
15.
2424 3737
main() {
4242 5555
Ans:b
printf(%c,c);
16. 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
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);
Ans: 4
printf("%d",*a+1-*a+3);
Gud1
243
int integer=2; v=i; } Ans : 2 21. # include <stdio.h> int one_d[]={1,2,3}; main() {
printf("%d",*j);
Ans: 10
int *ptr;
printf("%d",*ptr); }
ptr=one_d; ptr+=3;
printf("%c%v",c,v);
{ int i, n;
} Ans: irl
printf(%s\n,x); x++;
rl l
*q=***a; printf("%d..%d",*p,*q);
27. main ( ) {
244
++*ptr;
printf(%s,*--*++p + 3);
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;
Ans: g 20 fy
29. main( ) {
char *q;
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>
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); }
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; }
Ans: 2 2 2 2 2 23465
a[0]='a';a[1]='b';a[2]='c';a[4]='d';
Ans: error
1.
SESSION 5
} Ans: b c 4.
ccc(){ }
printf("hello"); } printf("bye");
return( a= (a==b) );
main() {
of
process
is
%d
!\n
246
Ans: error
5.
int x=3,y=4;
} Ans: 10
printf("%d",prod(x+2,y-1));
*a=*a+*b;*b=*a-*b;*a=*a-*b;
{ int i=_l_abc(10);
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
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);
7.
SESSION 6
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) ;
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));
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
x=abc.next->next->prev->next->i; printf("%d",x);
Ans : 2
*7.
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{
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;
error g1;
Ans : error
10. main() {
249
while(!feof(fp)) {
}stud; {
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.
&student.dob.year);
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,
}stud;
struct a *b;
int x;
};
Ans: error
}aType
aType *b;
12.
the following program printed 11 names. What went wrong? void main() {
Ans: syntax error. 16. Is the following code legal? typedef struct a aType; struct a {
struct student
}; Ans: yes
250
2) ans::2 3)
17.
enum days{MON=-1,TUE,WED=55,THU,FRI,SAT};
}; } Ans: no 18.
4)
void main() { {
list.
19. main()
{ float f=5,g=10;
printf("%d",v.a);
printf(%lf\n,f%g); printf(%lf\n,fmod(f,g)); }
Ans:error.
};
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; }
ans::2,2
}bit={1,2,2};
6)
};
251
printf("%d",var.one); ans::-1
printf("%s",(*(c+2)).coursename);
printf("%d",c[1].courseno);
7)
11) {
char c;
9)
printf("%f\n",t->f);
t->c='a'; printf("%c\n",t->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];
};
gn"}
252
int b:2; };
13) {
};
printf("\nThe value of a is %d",s.a); printf("\nThe value of b is %d",s.b); printf("\nThe value of c is %d",s.c); s.a=2;
s.b=0; s.c=5;
} { }
%d",sizeof(s)); }
14) {
17)
}m;
};
void main() {
struct sample s; void passrecord(struct sample); printf("\n Enter the name:"); scanf("%s",s.name); scanf("%d",s.no); passrecord(s);
16) {
printf("\n values after the function:\n"); printf("\n Name : %d",s.no); } printf("\n No %s",s.name); :
253
c) a) b c a c) a b c
temp->next->prev=temp->prev;
%s",x.name);
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 {
}; struct employee e;
printf("\n %s %d",e.name,e.age);
a)1 2 3 4 4 .
5.
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)
b)
3.
pointer a) b)
by temp.
b) d)
free(temp) temp->prev->next=temp->next
254
{ }
temp1 is a newnode?
a)
b)
inserts node before temp; inserts after temp deletes node pointed by temp; none of the above
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)
b) c)
no effect
temp -> next -> prev = temp -> prev; free ( temp ); a) b) deletes 3rd last node no effect
d)
shuffling of pointers
8. What does the code below do, where head is starting node & temp is temporary pointer
c) d) 1.main() { }
temp=head; head= head -> next; head -> prev = null; free(temp); a) b) c) d) no effect NULL data is stored
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);
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
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 {
if (x >= 30) { x = x + y;
int y = 30;
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
correct position in the tree. root is the root of the tree and
256
/ \ 2 /\ /\ 1 3 10 30 / / 7 40 \ 50 11
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);
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.
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:
(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
the node definition with member functions called data and next node?
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)
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); }
(b)10
258
(d)2
25
Ans::6
16
72
21
26
88
14
36
main() {
45
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
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
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
e) none ans: doubly linked list 5) find output of the following code. #define min(a,b) (a<b?a:b)
B
main() {
G
} a) 7 b) 8 c) Compile time error d) Garbage. Ans::a a. c.
H
b. d.
260 A
b. c. d.
C
7.
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.
Answer: A
9.
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
6.
Answer B
b. c.
d.
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
temp1right=templeft;
code?
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