C Programming MCQ - Variables & Datatypes
31. What is the output of this program?
int main()
{
char ch;
ch = 128;
printf("%d", ch);
return 0;
}
A. 128
B. -128
C. Depends on compiler
D. None of the above
View Answer
Ans : B
Explanation: signed char will be a negative number.
32. What is the output of this program?
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
A. a
B. 0.000000
C. 97.000000
D. Run time error
View Answer
Ans : C
Explanation: ASCII value of a is assigned to the float variable x .
33. How would you round off a value from 6.66 to 7.0?
A. ceil(6.66)
B. floor(6.66)
C. roundup(6.66)
D. roundto(6.66)
View Answer
Ans : A
Explanation: The ceil function returns the smallest integer that is greater than or equal to x.
34. What will be the output of the program in 16 bit platform ?
#include <stdio.h>
int main()
{
extern int i;
i = 20;
printf("%d", sizeof(i));
return 0;
}
A. 2
B. 4
C. 8
D. Linker Error
View Answer
Ans : D
Explanation: The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred.
35. What will be output when you will execute following c code?
#include <stdio.h>
int main()
{
printf("%d ",sizeof(5.5));
printf("%d ",sizeof(50000));
printf("%d",sizeof('A'));
return 0;
}
A. 4 2 1
B. 8 4 4
C. 8 4 2
D. compiler dependent
View Answer
Ans : D
Explanation: None
36. What is the output of this program?
void main()
{
int i=0, j=1, k=2, m;
m = i++ || j++ || k++;
printf("%d %d %d %d", m, i, j, k);
}
A. 1 1 2 3
B. 1 1 2 2
C. 0 1 2 2
D. 0 1 2 3
View Answer
Ans : B
Explanation: n an expression involving || operator, evaluation takes place from left to right and will be stopped if one of its components evaluates to true(a non zero value).
So in the given expression m = i++ || j++ || k++.
It will be stop at j and assign the current value of j in m.
therefore m = 1 , i = 1, j = 2 and k = 2 (since k++ will not encounter. so its value remain 2)
37. What is the output of this program?
void main()
{
int c = - -14;
printf("%d", c);
}
A. 13
B. 14
C. -14
D. Compilation Error
View Answer
Ans : B
Explanation: Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus = plus.
38. What is the output of this program?
void main()
{
int i=5;
i = !i>10;
printf("%d", i);
}
A. 5
B. 10
C. 0
D. None of the above
View Answer
39. The format identifier %i is also used for _____ data type?
A. char
B. int
C. float
D. double
View Answer
Ans : B
Explanation: Both %d and %i can be used as a format identifier for int data type.
40. Variable names beginning with underscore is not encouraged. Why?
A. It is not standardized
B. To avoid conflicts since assemblers and loaders use such names
C. To avoid conflicts since library routines use such names
D. To avoid conflicts with environment variables of an operating system
View Answer
Ans : C
Explanation: To avoid conflicts since library routines use such names.
Also check :
Discussion