C Programming Test And Answer 09
1.What will be the output of the program?
#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters\n");
else
printf("It doesn't matters\n");
return 0;
}
A. It matters
B. It doesn’t matters
C. matters
D. No output
Explanation:
printf() returns the number of charecters printed on the console.
Step 1: if(ch = printf("")) here printf() does not print anything, so it returns ‘0’(zero).
Step 2: if(ch = 0) here variable ch has the value ‘0’(zero).
Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.
Hence the output is “It doesn’t matters”.
2.What will be the output of the program ?
#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
A. 10
B. 20
C. 30
D. 0
Explanation:
Because union can initialize only one variable at a time. It overwrites the memory with binary value of 20 where it was initialized with binary value of 10 before.
It takes the last initialized value of its member variables.
3.In which order do the following gets evaluated
- Relational
- Arithmetic
- Logical
- Assignment
A. 2134
B. 1234
C. 4321
D. 3214
Explanation:
- Arithmetic operators: *, /, %, +, -
- Relational operators: >, <, >=, <=, ==, !=
- Logical operators : !, &&, ||
- Assignment operators: =
上一篇: el-tabl 列数不确定 灵活展示