Multiple Choice Questions and Answers for Type Conversions in C Language

https://www.computersprofessor.com/2017/09/multiple-choice-questions-and-answers_27.html
List of C language interview questions on “Type Conversions” along with answers, explanations and/or solutions:
1. What is the output of this C code?
#include
void main()
{
float x = 0.1;
if (x == 0.1)
printf("Sanfoundry");
else
printf("Advanced C Classes");
}
a) Advanced C Classes
b) Sanfoundry
c) Run time error
d) Compile time error
b) Sanfoundry
c) Run time error
d) Compile time error
Answer:a
2. Comment on the output of this 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
b) Junk value, 0.100000
c) 0, 0.100000
d) 0, 0.999999
Answer:b
3. What is the output of this C code?
(7 and 8 are entered)
(7 and 8 are entered)
#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
b) Run time error
c) 7.000000, junk
d) Varies
Answer:c
4. What is the output of this C code?
#include
void main()
{
double x = 123828749.66;
int y = x;
printf("%d\n", y);
printf("%lf\n", y);
}
a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
Answer:d
5. What is the output of this C code?
#include
void main()
{
int x = 97;
char y = x;
printf("%c\n", y);
}
a) a
b) b
c) 97
d) Run time error
b) b
c) 97
d) Run time error
Answer:a
6. When double is converted to float, the value is?
a) Truncated
b) Rounded
c) Depends on the compiler
d) Depends on the standard
a) Truncated
b) Rounded
c) Depends on the compiler
d) Depends on the standard
Answer:c
7. What is the output of this C code?
#include
int main()
{
unsigned int i = 23;
signed char c = -23;
if (i > c)
printf("Yes\n");
else if (i < c)
printf("No\n");
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system
b) No
c) Depends on the compiler
d) Depends on the operating system
Answer:b
8. What is the output of this C code?
#include
int main()
{
int i = 23;
char c = -23;
if (i < c)
printf("Yes\n");
else
printf("No\n");
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
b) No
c) Depends on the compiler
d) Depends on the standard
Answer:b
9. function tolower(c) defined in library works for
a) Ascii character set
b) Unicode character set
c) Ascii and utf-8 but not EBSIDIC character set
d) Any character set
a) Ascii character set
b) Unicode character set
c) Ascii and utf-8 but not EBSIDIC character set
d) Any character set
Answer:d
10. What is the output of the below code considering size of short int is 2, char is 1 and int is 4 bytes?
#include
int main()
{
short int i = 20;
char c = 97;
printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
return 0;
}
a) 2, 1, 2
b) 2, 1, 1
c) 2, 1, 4
d) 2, 2, 8
b) 2, 1, 1
c) 2, 1, 4
d) 2, 2, 8
Answer:c
11. Which type conversion is NOT accepted?
a) From char to int
b) From float to char pointer
c) From negative int to char
d) From double to char
a) From char to int
b) From float to char pointer
c) From negative int to char
d) From double to char
Answer:b
Explanation:Conversion of a float to pointer type is not allowed.
Explanation:Conversion of a float to pointer type is not allowed.
12. What will be the data type of the result of the following operation?
(float)a * (int)b / (long)c * (double)d
a) int
b) long
c) float
d) double
(float)a * (int)b / (long)c * (double)d
a) int
b) long
c) float
d) double
Answer:d
13. Which of the following type-casting have chances for wrap around?
a) From int to float
b) From int to char
c) From char to short
d) From char to int
a) From int to float
b) From int to char
c) From char to short
d) From char to int
Answer:b
14. Which of the following typecasting is accepted by C?
a) Widening conversions
b) Narrowing conversions
c) Both
d) None of the mentioned
a) Widening conversions
b) Narrowing conversions
c) Both
d) None of the mentioned
Answer:c
15. When do you need to use type-conversions?
a) The value to be stored is beyond the max limit
b) The value to be stored is in a form not supported by that data type
c) To reduce the memory in use, relevant to the value
d) All of the mentioned
a) The value to be stored is beyond the max limit
b) The value to be stored is in a form not supported by that data type
c) To reduce the memory in use, relevant to the value
d) All of the mentioned
Answer: d