C Programming Multiple Choice Question - Type Conversion
This section focuses on the "Type Conversion" in C programming. These Multiple Choice Questions (MCQ) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. How many type of conversion are there in c?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B
Explanation: Basically 2 types of convsersion : Implicit Type Conversion and Explicit Type Conversion.
2. Which conversion also called Automatic Type Conversion?
A. Implicit Type Conversion
B. Explicit Type Conversion
C. Both A and B
D. None of the above
View Answer
Ans : A
Explanation: This type of conversion is usually performed by the compiler when necessary without any commands by the user. Thus it is also called "Automatic Type Conversion".
3. The following code is an example of?
double da = 4.5;
double db = 4.6;
double dc = 4.9;
//explicitly defined by user
int result = (int)da + (int)db + (int)dc;
printf(""result = %d"", result);
A. Implicit Type Conversion
B. Explicit Type Conversion
C. Error
D. Can not Say
View Answer
Ans : B
Explanation: In the above code we find that the output result is 12 because in the result expression the user has explicitly defined the operands (variables) as integer data type. Hence, there is no implicit conversion of data type by the compiler.
4. What will be output for the following code?
#include<stdio.h>
int main()
{
int x = 10;
char y = 'a';
x = x + y;
float z = x + 1.0;
printf(""x = %d, z = %f"", x, z);
return 0;
}
A. x = 107, z = 108.00
B. x = 107, z = 108.0000
C. x = 107, z = 108.000000
D. x = 108, z = 108.000000
View Answer
Ans : C
Explanation: Output for the following code : x = 107, z = 108.000000
5. What will be output for the following code?
#include<stdio.h>
int main()
{
double x = 1.2;
int sum = (int)x + 1;
printf(""sum = %d"", sum);
return 0;
}
A. sum = 2
B. sum = 1
C. sum = 0
D. sum = 3
View Answer
Ans : A
Explanation: Output for the following code : sum = 2
6. In Implicit type conversion, If an operand of long int is present then the other operand will be converted to ?
A. unsigned int
B. unsigned long int
C. float
D. long int
View Answer
Ans : D
Explanation: If an operand of long int is present then the other operand will be converted to long int and the final result will also be long int.
7. In Implicit type conversion, If an operand of type long double is present in the expression, then the corresponding operand will also be converted to?
A. double
B. long double
C. int
D. float
View Answer
Ans : B
Explanation: If an operand of type long double is present in the expression, then the corresponding operand will also be converted to long double same for the double data type.
8. Which type of 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
View Answer
Ans : B
Explanation: Conversion of a float to pointer type is not allowed.
9. Which of the following typecasting is accepted by C?
A. Widening conversions
B. Narrowing conversions
C. Widening & Narrowing conversions
D. None of the above
View Answer
Ans : C
Explanation: Widening & Narrowing conversions following typecasting is accepted by C.
10. 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 above
View Answer
Ans : D
Explanation: For All of the above statement we need to use type-conversions.
Discussion