Here is a listing of C test questions on “Arithmetic Operators” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a = 3;
-
int b = ++a + a++ + --a;
-
printf("Value of b is %d", b);
-
}
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer: d
Clarification: None.
2. What is the precedence of arithmetic operators (from highest to lowest)?
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
Answer: a
Clarification: None.
3. Which of the following is not an arithmetic operation?
a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;
Answer: c
Clarification: None.
4. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
Answer: d
Clarification: None.
5. Which among the following are the fundamental arithmetic operators, i.e, performing the desired operation can be done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int a = 10;
-
double b = 5.6;
-
int c;
-
c = a + b;
-
printf("%d", c);
-
}
a) 15
b) 16
c) 15.6
d) 10
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int a = 10, b = 5, c = 5;
-
int d;
-
d = a == (b + c);
-
printf("%d", d);
-
}
a) Syntax error
b) 1
c) 10
d) 5
Answer: b
Clarification: None.