Multiple Choice Questions and Answers for Type Conversions in C Language

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?

  1.     #include 
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         if (x == 0.1)
  6.             printf("Sanfoundry");
  7.         else
  8.             printf("Advanced C Classes");
  9.     }
a) Advanced C Classes
b) Sanfoundry
c) Run time error
d) Compile time error
Answer:a
2. Comment on the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         printf("%d, ", x);
  6.         printf("%f", x);
  7.     }
a) 0.100000, junk value
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)
  1.     #include 
  2.     void main()
  3.     {
  4.         float x;
  5.         int y;
  6.         printf("enter two numbers \n", x);
  7.         scanf("%f %f", &x, &y);
  8.         printf("%f, %d", x, y);
  9.     }
a) 7.000000, 7
b) Run time error
c) 7.000000, junk
d) Varies
Answer:c
4. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         double x = 123828749.66;
  5.         int y = x;
  6.         printf("%d\n", y);
  7.         printf("%lf\n", y);
  8.     }
a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000
Answer:d
5. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         char y = x;
  6.         printf("%c\n", y);
  7.     }
a) a
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
Answer:c
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         unsigned int i = 23;
  5.         signed char c = -23;
  6.         if (i > c)
  7.             printf("Yes\n");
  8.         else if (i < c)
  9.             printf("No\n");
  10.     }
a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system
Answer:b
8. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 23;
  5.         char c = -23;
  6.         if (i < c)
  7.             printf("Yes\n");
  8.         else
  9.             printf("No\n");
  10.     }
a) Yes
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
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?
  1.     #include 
  2.     int main()
  3.     {
  4.         short int i = 20;
  5.         char c = 97;
  6.         printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
  7.         return 0;
  8.     }
a) 2, 1, 2
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
Answer:b

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
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
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
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
Answer: d

Related

Multiple Choice Questions 7285245367027887946

Post a Comment

emo-but-icon

item