1 / 54
What is the output of the following problem ?
#include
int main()
{
int i=4;
if(i=0)
printf("statement 1");
else
printf("statement 2");
return 0;
}
Astatement 1
Bstatement 2
CCompilation Error
DNo Output
Answer: Option B
Explanation:statement 1 will only be printed when i value=0. But i value is initialized as i=4 so it doesn't go with the first condition hence the second condition is accepted and statement 2 is printed.
Workspace
2 / 54
#include
int main() {
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
return 0;
}
A0 12
B12 12
C0 0
D12 0
Answer: Option A
Explanation:4th line of the program says j=10 . 5th line says j means post increment so after that line is executed j value will become 11 but during the execution of the 5th line j value is still 10 so i= 10-10=0
Now in the 5th line itself there has been two times increment of j so final value will be 12.
Workspace
3 / 54
int main()
{
int const * p=5;
printf("%d",++(*p));
return 0;
}
ACompiler error
B5
C6
DNone of these
Answer: Option A
Explanation:p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
Workspace
4 / 54
#include
#define max
int main(){
printf("%d",max);
return 0;
}
A0
Bnull
CGarbage
DCompilation error
E-1
Answer: Option D
Explanation:#define max(a,b) ((a).(b)?(a):(b)) This is the complete and correct way to define the function max . In the code its incomplete hence it shows compiler error.
Workspace
5 / 54
What is the output of the following 'C' program?
#include
void main() {
int x = 10,y = 10, z = 5, i;
i = x;
printf("%d",i==x);
}
A1
BError
C0
D5
Answer: Option A
Explanation:The value of x initialised is 10. Also i=x so i=10. Now when comparing condition (i==x) it will give boolean result that is if the condition is true it will return 1 else it will return 0. So here the condition is true coz x=i hence output is 1.
Workspace
6 / 54
What does the following 'C' program do ?
#include
void main()
{
unsigned int num;
int i;
scanf("%u", &num);
for (i = 0; i < 16; i++)
printf("%d", (num << i & 1 << 15)? 1:0);
}
AIt prints all even bits form num
BIt prints binary equivalent of num
CIt prints all odd bits from num
DNone of these
Answer: Option B
Explanation:Here integer (unsigned) is assumed as 2 bytes so that for loop is till 16 i.e (2byte = 16 bits.)
As unsigned integer so user is expected to enter positive number.
statement in printf (num << i & 1 << 15)? 1:0 is used to convert decimal to binary equivalent.
in the above statement below things has been used.
<< ----> left shift
& -----> And operator
? : ------> trinery operator
Ex: if the number is 10 and its binary equivalent 1010 or (00000000000001010 in 16 bit)
the printf statement will be
for i = 0
(10 << 0 & 1 << 15)>?1:0
for i = 1
(10 << 1 & 1 << 15)>?1:0
similarly for i = 2, 3, 4 , ---- 15
Workspace
7 / 54
What is the output of the following program ?
include
int main()
{
int x,y=2,z,a;
x = (y*=2) + (z=a=y);
printf ("%d", x);
return 0;
}
A7
B8
C6
Dsyntactically wrong
Answer: Option B
Explanation:x = (y*=2) (z=a=y); Meaning of y*=2 means y=y*2 hence y value becomes 2*2=4.
Current value of y =4 so z=a=y=4.
Hence x=4+4=8
Workspace
8 / 54
#include
void main()
{
int x,y=2,z,a;
if(x=y%2)
z=2;
a=2;
printf("%d %d",z,x);
}
A1..0
B2..0
C2..1
DGarbage-value 0
ECompilation Error
Answer: Option D
Explanation:The value of y%2 is 0. This value is assigned to x.
The condition will if (0) so z goes uninitialized.
Workspace
9 / 54
What is the output of the following 'C' program ?
#include
void fun(void)
{
static int s = 0;
s++;
if(s == 10)
return;
fun();
printf("%d ", s);
}
int main(void)
{
fun();
}
A9 times 10
B10 times 10
CCompilation Error
DNone of these
Answer: Option A
Explanation:Here is no explanation for this answer
Workspace
10 / 54
What is the output of the following 'C' program ?
void main(){
char c=125;
c=c+10;
printf("%d",c);
}
A135
BINF
C-121
DCompilation Error
Answer: Option C
Explanation:Here char is signed so,the size of char is 1 bytes and its value range are -128 to 127,
and it will be something like below
-128 -127 -126 .......... 0 ....... 126 127 in the cycle.
Now as per questions c = 125 it is under the above limit.
but when 10 added to it, it becomes 125 10 = 135
125 126 127 -128 -127 -126 -125 -124 -123 -122 -121
So, count above 135 will fall at -121, so Answer will be -121
If in the question it would have given unsigned char then answer will be 135
Workspace