NEW
Font size
WorksheetsDay 3 C Programming quiz
Total questions: 10
Worksheet time: 5mins
Which conversion is not possible in c programming?
int to float
float to char pointer
float to int
All of these
Which header file is needed to include to use typecasting?
stdin.h
math.h
ctype.h
None
#include<stdio.h>
int main()
{
double x = 1.2;
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
what will be the value of the variable sum?
1
2
3
0
Which type of conversion is also called Automatic Type Conversion?
Implicit Type Conversion
Explicit Type Conversion
None of the above
Both A and B
#include <stdio.h>
int main()
{
int a=40,b=20;
if (a>b) {
printf("a is greater than b");}
else if(a<b) {
printf("a is less than b"); }
else {
printf("a is equal to b");}
}
What is the output of the code?
a is greater than b
a is equal to b
a is less than b
compilation error
int main()
{
switch(24.5)
{
case 24.5: printf("A ");break;
case 25.0: printf("B "); break;
default: printf("None ");
}
printf("Done");
}
What is the output of the above C Program?
Compiler error
Done
A , Done
B , Done
#include <stdio.h>
int main()
{
int x = 5;
if (x < 1)
printf("x<1");
if (x == 5)
printf("x=5");
else
printf("none");
}
what is the output of the following code?
x=5
x<1
none
error
Why can typecasting be dangerous in some cases?
Some conversions are not defined, such as char to int.
You might temporarily lose part of the data - such as truncating a float when typecasting to an int.
You might permanently change the value of the variable.
There are no dangers in typecasting.
#include<stdio.h>
int main()
{
int i = 2;
if(i == (1, 2))
printf("1 or 2");
else
printf("None");
return 0;
}
what will be the output of above programme?
Compilation error
1 or 2
None
Run time error
Which is a good use for typecasting?
To allow your program to use nothing but integers.
To change the return type of a function.
To allow the division of two integers to return a decimal value.
To swap variables rapidly.
