Here is a listing of C language Objective Questions on “Type Conversions” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
float x = 0.1;
-
if (x == 0.1)
-
printf("");
-
else
-
printf("Advanced C Classes");
-
}
a) Advanced C Classes
b)
c) Run time error
d) Compile time error
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
float x = 0.1;
-
printf("%d, ", x);
-
printf("%f", x);
-
}
a) 0.100000, junk value
b) Junk value, 0.100000
c) 0, 0.100000
d) 0, 0.999999
Answer: b
Clarification: None.
3. What will be the output of the following C code? (Initial values: x= 7, y = 8)
-
#include
-
void main()
-
{
-
float x;
-
int y;
-
printf("enter two numbers n", x);
-
scanf("%f %f", &x, &y);
-
printf("%f, %d", x, y);
-
}
a) 7.000000, 7
b) Run time error
c) 7.000000, junk
d) Varies
Answer: c
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
double x = 123828749.66;
-
int y = x;
-
printf("%dn", y);
-
printf("%lfn", y);
-
}
a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
Answer: d
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int x = 97;
-
char y = x;
-
printf("%cn", y);
-
}
a) a
b) b
c) 97
d) Run time error
Answer: a
Clarification: None.
6. When double is converted to float, then the value is?
a) Truncated
b) Rounded
c) Depends on the compiler
d) Depends on the standard
Answer: c
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
unsigned int i = 23;
-
signed char c = -23;
-
if (i > c)
-
printf("Yesn");
-
else if (i < c)
-
printf("Non");
-
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system
Answer: b
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int i = 23;
-
char c = -23;
-
if (i < c)
-
printf("Yesn");
-
else
-
printf("Non");
-
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
Answer: b
Clarification: None.