C QUESTIONS:
[Q001].
The following code is not well-written. What does the program do?
Void
main()
{
int a=1, b=2, c=3,d=4;
printf("%d %d", a, b);
printf (" %d %d", c, d);
}
(a)Run-Time
Error (b)Compile-Time Error (c)1 2 3 4 (d)None of these
Ans.
(c)
__________________________________________________________________________________
[Q002].
What will be the output of the following program :
void
main()
{
int a=1,b=2,c=3;
c=(--a, b++)-c;
printf("%d %d %d",a,b,c);
}
(a)0
3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3 0
Ans.
(c)
__________________________________________________________________________________
[Q003].
What will be the output of the following program :
void
main()
{
int a=1,b=2,c=3,d=4,e;
e=(a,a)+(b,c)+(c,d)-(d,b);
printf("%d", e);
}
(a)Compile-Time
Error (b)10 (c)6 (d)2
Ans.
(c)
___________________________________________________________________________________
[Q004].
What will be the output of the following program:
void
main()
{
float val=2.;
printf("%.2",val);
}
(a)Compile-Time
error (b)2.00 (c)%.2 (d)2.000000
Ans.
(c)since there is no ‘f’ .
__________________________________________________________________________________
[Q005].
What will be the output of the following program :
void
main()
{
int a=5;
int b=6;;
int c=a+b;
printf("%d",c);
}
(a)Compile-Time
Error (b)Run-Time Error (c)11 (d)None of these
Ans.
(c)
___________________________________________________________________________________
[Q006].
What will be the output of the following program :
void
main()
{
int i,j;
for (i=1; i<=3; i++)
for (j=1; j<3; j++)
{
if (i == j)
continue;
if ((j % 3) > 1)
break;
printf("%d",i);
}
}
Ans.:2,3
____________________________________________________________________________________
[Q007].
What will be the output of the following program :
#define swap(a,b) temp=a; a=b; b=temp;
void
main()
{
static int a=5,b=6,temp;
if (a > b)
swap(a,b);
printf("a=%d b=%d",a,b);
}
(a)a=5
b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of these
Ans.
(c)
___________________________________________________________________________________
[Q008].
What will be the output of the following program :
void
main()
{
unsigned int val=5;
printf("%u %u",val,val-11);
}
(a)Compile-Time
error (b)5 -6 (c)5
65530 (d)None of these
Ans.
(c) since 2’s complement of –6 = 65530.
___________________________________________________________________________________
Q009].
What will be the output of the following program :
void
main()
{
int x=4,y=3,z=2;
*&z*=*&x**&y;
printf("%d",z);
}
(a)Compile-Time
error (b)Run-Time Error (c)24 (d)Unpredictable
Ans.
(c) since *&z=z
___________________________________________________________________________________
[Q010].
What will be the output of the following program :
void
main()
{
int i=5,j=5;
i=i++*i++*i++*i++;
printf("i=%d ",i);
j=++j*++j*++j*++j;
printf("j=%d",j);
}
(a)Compile-Time
Error (b)i=1680 j=1680 (c)i=629 j=6561 (d)i=1681 j=3024
Ans.
(c) Compiler dependent
__________________________________________________________________________