C Programming MCQ Questions and Answers on Arithmetic Operators 2

Image
C MCQ Questions and Answers

Learn C Programming MCQ Questions and Answers on C Arithmetic Operators like Modulo Division Operator, Plus, Minus, Star and Division Operators. Operator Precedence and Priority is also explained. Easily attend Job interviews after reading these Multiple Choice Questions.

Go through C Theory Notes on Arithmetic Operators before studying questions.



1) What is the Priority among (*, /, %), (+, -) and (=) C Operators.?
A) (*, /, %) >  (+, -) < (=)
B) (*, /, %) <  (+, -) < (=)
C) (*, /, %) >  (+, -) > (=)
D) (*, /, %) <  (+, -) (+, -) == (=)
Answer [=]
C
Explanation:

Assignment operator in C has the least priority.

2) What is the output of the C statement.?
int main()
{
    int a=0;
    a = 4 + 4/2*5 + 20;
    printf("%d", a);

    return 0;
}
A) 40
B) 4
C) 34
D) 54
Answer [=]
C
Explanation:

/ and * has equal priority. But associativity is from L to R.

4 + 2*5 + 20

4 + 10 + 20 = 34

3) What is the output of the C Program.?
int main()
{
    int a=0;
    a = 10 + 5 * 2 * 8 / 2 + 4;
    printf("%d", a);

    return 0;
}
A) 124
B) 54
C) 23
D) 404
Answer [=]
B
Explanation:

10 + 10*8/2 + 4

10 + 80/2 + 4

10 + 40 + 4 = 54

4) What is the output of the C Program.?
int main()
{
    int a=0;
    a = 4 + 5/2*10 + 5;
    printf("%d", a);

    return 0;
}
A) 29
B) 5
C) 4
D) 34
Answer [=]
A
Explanation:

5/2 is 2 only because both numerator and denominator are integers. So only int value i.e 2 is the result.

4 + 2 * 10 + 5

4 + 20 + 5 = 29.

5) What is the output of the C Program.?
int main()
{
    int a=0;
    a = 10 + 2 * 12 /(3*2) + 5;
    printf("%d", a);

    return 0;
}

A) 31
B) 19
C) 11
D) 29
Answer [=]
B
Explanation:

Paranthesis changes the associativity of operators.

10 + 2 * 12 / (3*2) + 5;

10 + 24 / (3*2) + 5;

10+ 24/6 + 5;

10 + 4 + 5 = 19;

6) What is the output of the C Program.?
int main()
{
    int a=0;
    a = 10 + 2 * 12 / 3 * 2 + 5;
    printf("%d", a);

    return 0;
}
A) 19
B) 31
C) 11
D) 25
Answer [=]
B
Explanation:

10 + 2 * 12 / 3 * 2 + 5;

10 + 24/3*2 + 5;

10 + 8*2 + 5;

10 + 16 + 5 = 31;

7) What is the output of the C Program.?
int main()
{
    float a=10.0;
    a = a % 3;
    printf("%f", a);

    return 0;
}
A) 0
B) 1
C) 1.000000
D) Compiler error.
Answer [=]
D
Explanation:

You can use the operator Modulus Division % with only integers.

 error: invalid operands to binary % (have ‘float’ and ‘int’)
     a = a % 3;
           ^


8) What is the output of the C Program.?
int main()
{
    float a=10.0;
    a = (int)a % 3;
    printf("%f", a);

    return 0;
}
A) 0
B) 1
C) 1.000000
D) Compiler Error.
Answer [=]
C
Explanation:

Type casting from float to int is done by (int).

(int)10.000000  = 10;

10%3 = 1. Reminder of the division of 10 by 3.

%f in printf prints it as 1.000000.

9) What is the output of the C Program.?
int main()
{
    int a=0;
    a = 14%-5 - 2;
    printf("%d", a);

    return 0;
}
A) 0
B) -4
C) -2
D) 2
Answer [=]
D
Explanation:

14%5  = 4 ( Reminder)

14 % -5  = 4. Yes sign of the reminder is the sign of Numerator.

4- 2 = 2;

10) What is the output of the C Program.?
int main()
{
    int a= 3 + 5/2;
    printf("%d", a);

    return 0;
}
A) 3
B) 2
C) 5
D) Can not assign an expression to variable at the time of declaration.
Answer [=]
C
Explanation:

Assignment Operator = in C language has the least priority. So the right hand side expression is evaluated first and then assigned to the left side variable.

a = 3 + 5/2;

a = 3 + 2;

a = 5;