(1) What will be output if you will compile and execute the following c code?
void main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr);
}
(a)320
(b)1
(c)64
(d)Compiler error
(e)None of above
Output: (c)
Explanation:
As we know size of int data type is two byte while char pointer can pointer one byte at time.
Memory representation of int i=320

So char pointer ptr is pointing to only first byte as shown above figure.
*ptr i.e. content of first byte is 01000000 and its decimal value is 64.
(2) What will be output if you will compile and execute the following c code?
#define x 5+2
void main(){
int i;
i=x*x*x;
printf("%d",i);
}
(a)343
(b)27
(c)133
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
As we know #define is token pasting preprocessor it only paste the value of micro constant in the program before the actual compilation start. If you will see intermediate file you will find:
test.c 1:
test.c 2: void main(){
test.c 3: int i;
test.c 4: i=5+2*5+2*5+2;
test.c 5: printf("%d",i);
test.c 6: }
test.c 7:
You can absorb #define only pastes the 5+2 in place of x in program. So,
i=5+2*5+2*5+2
=5+10+10+2
=27
(3) What will be output if you will compile and execute the following c code?
void main(){
char c=125;
c=c+10;
printf("%d",c);
}
(a)135
(b)+INF
(c)-121
(d)-8
(e)Compiler error
Output: (c)
Explanation:
As we know char data type shows cyclic properties i.e. if you will increase or decrease the char variables beyond its maximum or minimum value respectively it will repeat same value according to following cyclic order:

So,
125+1= 126
125+2= 127
125+3=-128
125+4=-127
125+5=-126
125+6=-125
125+7=-124
125+8=-123
125+9=-122
125+10=-121
(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");
}
(a)Equal
(b)Less than
(c)Greater than
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
5.2 is double constant in c. In c size of double data is 8 byte while a is float variable. Size of float variable is 4 byte.
So double constant 5.2 is stored in memory as:
101.00 11001100 11001100 11001100 11001100 11001100 11001101
Content of variable a will store in the memory as:
101.00110 01100110 01100110
It is clear variable a is less than double constant 5.2
Since 5.2 is recurring float number so it different for float and double. Number likes 4.5, 3.25, 5.0 will store same values in float and double data type.
Note: In memory float and double data is stored in completely different way. If you want to see actual memory representation goes to question number (60) and (61).
(5) What will be output if you will compile and execute the following c code?
void main(){
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x);
}
(a)21
(b)18
(c)12
(d)Compiler error
(e)None of above
Output: (a)
Explanation:
In ++a, ++ is pre increment operator. In any mathematical expression pre increment operator first increment the variable up to break point then starts assigning the final value to all variable.
Step 1: Increment the variable I up to break point.

Step 2: Start assigning final value 7 to all variable i in the expression.

So, i=7+7+7=21
(6) What will be output if you will compile and execute the following c code?
void main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else
{ break;
}
}
(a)It will print nothing.
(b)-3
(c)-2
(d)1
(e)Compiler error
Output: (e)
Explanation:
Keyword break is not part of if-else statement. Hence it will show compiler error: Misplaced break
(7) What will be output if you will compile and execute the following c code?
void main(){
int a=10;
printf("%d %d %d",a,a++,++a);
}
(a)12 11 11
(b)12 10 10
(c)11 11 12
(d)10 10 12
(e)Compiler error
Output: (a)
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.
(8) What will be output if you will compile and execute the following c code?
void main(){
char *str="Hello world";
printf("%d",printf("%s",str));
}
(a) 11Hello world
(b) 10Hello world
(c) Hello world10
(d) Hello world11
(e) Compiler error
Output: (d)
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.
(9) What will be output if you will compile and execute the following c code?
#include "stdio.h"
#include "string.h"
void main(){
char *str=NULL;
strcpy(str,"cquestionbank");
printf("%s",str);
}
(a)cquestionbank
(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.
(10) What will be output if you will compile and execute the following c code?
#include "stdio.h"
#include "string.h"
void main(){
int i=0;
for(;i<=2;)
printf(" %d",++i);
}
(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.
(11) What will be output if you will compile and execute the following c code?
void main(){
int x;
for(x=1;x<=5;x++);
printf("%d",x);
}
(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.
(12) What will be output if you will compile and execute the following c code?
void main(){
printf("%d",sizeof(5.2));
}
(a)2
(b)4
(c)8
(d)10
(e)Compiler error
Output: (c)
Explanation:
Default type of floating point constant is double. So 5.2 is double constant and its size is 8 byte.
(13) What will be output if you will compile and execute the following c code?
#include "stdio.h"
#include "string.h"
void main(){
char c='\08';
printf("%d",c);
}
(a)8
(b)’8’
(c)9
(d)null
(e)Compiler error
Output: (e)
Explanation:
In c any character is starting with character ‘\’ represents octal number in character. As we know octal digits are: 0, 1, 2, 3, 4, 5, 6, and 7. So 8 is not an octal digit. Hence ‘\08’ is invalid octal character constant.
(14) What will be output if you will compile and execute the following c code?
#define call(x,y) x##y
void main(){
int x=5,y=10,xy=20;
printf("%d",xy+call(x,y));
}
(a)35
(b)510
(c)15
(d)40
(e)None of above
Output: (d)
Explanation:
## is concatenation c preprocessor operator. It only concatenates the operands i.e.
a##b=ab
If you will see intermediate file then you will find code has converted into following intermediate code before the start of actual compilation.
Intermediate file:
test.c 1:
test.c 2: void main(){
test.c 3: int x=5,y=10,xy=20;
test.c 4: printf("%d",xy+xy);
test.c 5: }
test.c 6:
It is clear call(x, y) has replaced by xy.
(15) What will be output if you will compile and execute the following c code?
int * call();
void main(){
int *ptr;
ptr=call();
clrscr();
printf("%d",*ptr);
}
int * call(){
int a=25;
a++;
return &a;
}
(a)25
(b)26
(c)Any address
(d)Garbage value
(e)Compiler error
Output: (d)
Explanation:
In this question variable a is a local variable and its scope and visibility is within the function call. After returning the address of a by function call variable a became dead while pointer ptr is still pointing to address of variable a. This problem is known as dangling pointer problem.
(16) What is error in following declaration?
struct outer{
int a;
struct inner{
char c;
};
};
(a)Nesting of structure is not allowed in c.
(b)It is necessary to initialize the member variable.
(c)Inner structure must have name.
(d)Outer structure must have name.
(e)There is not any error.
Output: (c)
Explanation:
It is necessary to assign name of inner structure at the time of declaration other wise we cannot access the member of inner structure. So correct declaration is:
struct outer{
int a;
struct inner{
char c;
}name;
};
(17) What will be output if you will compile and execute the following c code?
void main(){
int array[]={10,20,30,40};
printf("%d",-2[array]);
}
(a)-60
(b)-30
(c)60
(d)Garbage value
(e)Compiler error
Output: (b)
Explanation:
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 i=10;
static int x=i;
if(x==i)
printf("Equal");
else if(x>i)
printf("Greater than");
else
printf("Less than");
}
(a)Equal
(b)Greater than
(c)Less than
(d)Compiler error
(e)None of above
Output: (d)
Explanation:
static variables are load time entity while auto variables are run time entity. We can not initialize any load time variable by the run time variable.
In this example i is run time variable while x is load time variable.
(18) What will be output if you will compile and execute the following c code?
void main(){
int i=5,j=2;
if(++i>j++||i++>j++)
printf("%d",i+j);
}
(a)7
(b)11
(c)8
(d)9
(e)Compiler error
Output: (d)
Explanation:
|| is logical OR operator. In C logical OR operator doesn’t check second operand if first operand is true.
++i>j++ || i++>j++
First operand: ++i>j++
Second operand: i++>j++
First operand
++i > j++
=> 6 > 2
Since first operand is true so it will not check second operand.
Hence i= 6 and j=3
(19) What will be output if you will compile and execute the following c code?
#define max 5;
void main(){
int i=0;
i=max++;
printf("%d",i++);
}
(a)5
(b)6
(c)7
(d)0
(e)Compiler error
Output: (e)
Explanation:
#define is token pasting preprocessor. If you will see intermediate file: test.i
test.c 1:
test.c 2: void main(){
test.c 3: int i=0;
test.c 4: i=5++;
test.c 5: printf("%d",i++);
test.c 6: }
test.c 7:
It is clear macro constant max has replaced by 5. It is illegal to increment the constant number. Hence compiler will show Lvalue required.
(20) What will be output if you will compile and execute the following c code?
void main(){
double far* p,q;
printf("%d",sizeof(p)+sizeof q);
}
(a)12
(b)8
(c)4
(d)1
(e)Compiler error
Output: (a)
Explanation:
It is clear p is far pointer and size of far pointer is 4 byte while q is double variable and size of double variable is 8 byte.
(21) What will be output if you will compile and execute the following c code?
void main(){
int a=5;
float b;
printf("%d",sizeof(++a+b));
printf(" %d",a);
}
(a)2 6
(b)4 6
(c)2 5
(d)4 5
(e)Compiler error
Output: (d)
Explanation:
++a +b
=6 + Garbage floating point number
=Garbage floating point number
//From the rule of automatic type conversion
Hence sizeof operator will return 4 because size of float data type in c is 4 byte.
Value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.
(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");
}
(a)Equal
(b)Greater than
(c)Less than
(d)Compiler error
(e)None of above
Output: (a)
Explanation:
As we know huge pointers compare its physical address.
Physical address of huge pointer p
Huge address: 0XC0563331
Offset address: 0x3331
Segment address: 0XC056
Physical address= Segment address * 0X10 + Offset address
=0XC056 * 0X10 +0X3331
=0XC0560 + 0X3331
=0XC3891
Physical address of huge pointer q
Huge address: 0XC2551341
Offset address: 0x1341
Segment address: 0XC255
Physical address= Segment address * 0X10 + Offset address
=0XC255 * 0X10 +0X1341
=0XC2550 + 0X1341
=0XC3891
Since both huge pointers p and q are pointing same physical address so if condition will true.
(23) What will be output if you will compile and execute the following c code?
void main(){
char *str;
scanf("%[^\n]",str);
printf("%s",str);
}
(a)It will accept a word as a string from user.
(b)It will accept a sentence as a string from user.
(c)It will accept a paragraph as a string from user.
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
Task of % [^\t] is to take the stream of characters until it doesn’t receive new line character ‘\t’ i.e. enter button of your keyboard.
(24) What will be output if you will compile and execute the following c code?
void main(){
int a=5,b=10,c=15;
int *arr[]={&a,&b,&c};
printf("%d",*arr[1]);
}
(a)5
(b)10
(c)15
(d)Compiler error
(e)None of above
Output: (d)
Explanation:
Array element cannot be address of auto variable. It can be address of static or extern variables.
(25) What will be output if you will compile and execute the following c code?
void main(){
int array[3]={5};
int i;
for(i=0;i<=2;i++)
printf("%d ",array[i]);
}
(a)5 garbage garbage
(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 of declaration is static. Default initial value of static integer is zero.
(26) What will be output if you will compile and execute the following c code?
void main(){
int array[2][2][3]={0,1,2,3,4,5,6,7,8,9,10,11};
printf("%d",array[1][0][2]);
}
(a)4
(b)5
(c)6
(d)7
(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.
(27) What will be output if you will compile and execute the following c code?
void main(){
int a[2][4]={3,6,9,12,15,18,21,24};
printf("%d %d %d",*(a[1]+2),*(*(a+1)+2),2[1[a]]);
}
(a)15 18 21
(b)21 21 21
(c)24 24 24
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
In c,
a [1][2]
=*(a [1] +2)
=*(*(a+1) +2)
=2[a [1]]
=2[1[a]]
Now, a [1] [2] means 1*(4) +2=6th element of an array staring from zero i.e. 21.
(28) What will be output if you will compile and execute the following c code?
void call(int,int,int);
void main(){
int a=10;
call(a,a++,++a);
}
void call(int x,int y,int z){
printf("%d %d %d",x,y,z);
}
(a)10 10 12
(b)12 11 11
(c)12 12 12
(d)10 11 12
(e)Compiler error
Output: (e)
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
(29) What will be output if you will compile and execute the following c code?
void main(){
int x=5,y=10,z=15;
printf("%d %d %d");
}
(a)Garbage Garbage Garbage
(b)5 10 15
(c)15 10 5
(d)Compiler error
(e)Run time error
Output: (c)
Explanation:
Auto variables are stored in stack as shown in following figure.

Stack follow LIFO data structure i.e. last come and first out. First %d will print then content of two continuous bytes from the top of the stack and so on.
(30) What will be output if you will compile and execute the following c code?
void main(){
register int i,x;
scanf("%d",&i);
x=++i + ++i + ++i;
printf("%d",x);
}
(a)17
(b)18
(c)21
(d)22
(e)Compiler error
Output: (e)
Explanation:
In c register variable stores in CPU it doesn’t store in RAM. So register variable have not any memory address. So it is illegal to write &a.
(31) What will be output if you will compile and execute the following c code?
void main(){
int a=5;
int b=10;
{
int a=2;
a++;
b++;
}
printf("%d %d",a,b);
}
(a)5 10
(b)6 11
(c)5 11
(d)6 10
(e)Compiler error
Output: (c)
Explanation:
Default storage class of local variable is auto. Scope and visibility of auto variable is within the block in which it has declared. In c, if there are two variables of the same name then we can access only local variable. Hence inside the inner block variable a is local variable which has declared and defined inside that block. When control comes out of the inner block local variable a became dead.
(32) What will be output if you will compile and execute the following c code?
void main(){
float f=3.4e39;
printf("%f",f);
}
(a)3.4e39
(b)3.40000…
(c)+INF
(d)Compiler error
(e)Run time error
Output: (c)
Explanation:
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.
(33) What will be output if you will compile and execute the following c code?
void main(){
enum color{
RED,GREEN=-20,BLUE,YELLOW
};
enum color x;
x=YELLOW;
printf("%d",x);
}
(a)-22
(b)-18
(c)1
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
Default value of enum constant = value of previous enum constant +1
Default value of first enum constant=0
Hence:
BLUE=GREEN+1=-20+1=-19
YELLOW=BLUE+1=-19+1=-18
(34) What will be output if you will compile and execute the following c code?
void main(){
asm{
mov bx,8;
mov cx,10
add bx,cx;
}
printf("%d",_BX);
}
(a)18
(b)8
(c)0
(d)Compiler error
(e)None of above
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.
(35) What will be output if you will compile and execute the following c code?
void main(){
enum xxx{
a,b,c=32767,d,e
};
printf("%d",b);
}
(a)0
(b)1
(c)32766
(d)Compiler error
(e)None of above
Output: (d)
Explanation:
Size of enum constant is size of sign int. Since value of c=32767. Hence value of d will be 32767+1=32768 which is beyond the range of enum constant.
(36) What will be output if you will compile and execute the following c code?
void main(){
signed int a=-1;
unsigned int b=-1;
if(a==b)
printf("%d %d",a,b);
else
printf("Not equal");
}
(a)-1 -1
(b)-1 32767
(c)-1 -32768
(d)Not equal
(e)Compiler error
Output: (a)
Explanation:
(37) What will be output if you will compile and execute the following c code?
void main(){
float f=5.5f;
float x;
x=f%2;
printf("%f",x);
}
(a)1.500000
(b)1.000000
(c)5.500000
(d)Compiler error
(e)None of above
Output: (d)
Explanation:
(38) What will be output if you will compile and execute the following c code?
void main(){
int a=-20;
int b=-3;
printf("%d",a%b);
}
(a)2
(b)-2
(c)18
(d)-18
(e)Compiler error
Output: (b)
Explanation:
Sign of resultant of modular division depends upon only the sign of first operand.
(39) What will be output if you will compile and execute the following c code?
void main(){
char c='0';
printf("%d %d",sizeof(c),sizeof('0'));
}
(a)1 1
(b)2 2
(c)1 2
(d)2 1
(e)None of above
Output: (c)
Explanation:
(40) What will be output if you will compile and execute the following c code?
void main(){
char *url="c:\tc\bin\rw.c";
printf("%s",url);
}
(a)c:\tc\bin\rw.c
(b)c:/tc/bin/rw.c
(c)c: c inw.c
(d)c:cinw.c
(e)w.c in
Output: (e)
Explanation:
1. \t is tab character which moves the cursor 8 space right.
2. \b is back space character which moves the cursor one space back.
3. \r is carriage return character which moves the cursor beginning of the line.

(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:
printf("display");
}
(a)main
(b)display
(c)maindisplay
(d)displaymain
(e)Compiler error
Output: (e)
Explanation:
Label of goto cannot be in other function because control cannot move from one function to another function directly otherwise it will show compiler error: unreachable label
(42) What will be output if you will compile and execute the following c code?
void main(){
int i=3;
if(3==i)
printf("%d",i<<2<<1);
else
printf("Not equal");
}
(a)1
(b)48
(c)24
(d)Not equal
(e)Compiler error
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*
(43) What will be output if you will compile and execute the following c code?
void main(){
int x=2,y=3;
if(x+y<=5)
printf("True");
else
printf("False");
}
(a)True
(b)False
(c)Compiler error: Lvalued required
(d)Compiler error: Invalid expression
(e)None of above
Output: (a)
Explanation:
Expression x+y<=5
=> 2+3 <=5
=> 5<=5 is true because 5 is either greater than 5 or equal to 5.
(44) What will be output if you will compile and execute the following c code?
void main(){
const int i=5;
i++;
printf("%d",i);
}
(a)5
(b)6
(c)0
(d)Compiler error
(e)None of above
Output: (d)
Explanation:
We cannot modify the const variable by using increment operator.
(45) What will be output if you will compile and execute the following c code?
void main(){
const int x=25;
int * const p=&x;
*p=2*x;
printf("%d",x);
}
(a)25
(b)50
(c)0
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
const keyword in c doesn’t make any variable as constant but it only makes the variable as read only. With the help of pointer we can modify the const variable. In this example pointer p is pointing to address of variable x. In the following line:
int * const p=&x;
p is constant pointer while content of p i.e. *p is not constant.
*p=2*x put the value 50 at the memory location of variable x.
(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);
}
(a)11
(b) 12
(c)Garbage value
(d)Compiler error
(e)None of above
Output: (c)
Explanation:
In the following line:
int const * p=&i;
*p i.e. content of p is constant pointer p is not constant pointer. So we can modify the pointer p. After incrementing the pointer it will point next memory location and its content will any garbage value.

Note: We have assumed arbitrary memory address.
To make pointer p as constant pointer write:
int const * const p=&i;
(47) What will be output if you will compile and execute the following c code?
void main(){
int a=15,b=10,c=5;
if(a>b>c )
printf("Trre");
else
printf("False");
}
(a)True
(b)False
(c)Run time error
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
Relation operator in c always returns 1 when condition is true and 0 when condition is false. So in the following expression
a > b > c
Associative of relational operators are left to right order of execution will be following manner:

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.
(48) What will be output if you will compile and execute the following c code?
void main(){
float f;
f=3/2;
printf("%f",f);
}
(a)1.5
(b)1.500000
(c)1.000000
(d)Compiler error
(e)None of above
Output: (b)
Explanation:
In the following expression:
f=3/2 both 3 and 2 are integer constant hence its result will also be an integer constant i.e. 1.
(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
(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.
(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)
Explanation:
First see intermediate file:
try.c 1:
try.c 2: void main(){
try.c 3: float a=5.5;
try.c 4: if(a==5.5)
try.c 5: printf("c");printf("c++");
try.c 6: else
try.c 7: printf("Not equal");
try.c 8: }
try.c 9:
try.c 10: