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.
int a = 12 + 3 * 5 / 4 - 10
Operator % is called Modulus or Modular or Modulo Division operator in C. It gives the reminder of the division.
int a = 11%4;
Now a holds only 3 which is the reminder.
Any arithmetic operation with both integers and real numbers yield output as Real number only.
5 + 10.56 = 15.560000 which is a real number.
5 + 10.0 = 15.000000 is also a real number.
int a = 10 + 4.867;
a is an int variable. So 10+4.867 = 14.867 is truncated to 14 and assigned to a.
int a = 3.5 + 4.5;
3.5 + 4.5 = 8.0 is a real number. So it is converted to downgraded to int value. So a = 8.
float var = 3.5 + 4.5;
A float variable can hold a real number.
int main() { float c = 3.5 + 4.5; printf("%f", c); return 0; }
Float can print precision up to 6 digits. So 6 zeros will be shown if there are no digits after decimal point.
int main() { float c = 3.5 + 4.5; printf("%d", (int)c); return 0; }
You are printing a float variable by type casting to int. So integer is printed.
int c = 3.5 + 4.5 also holds and prints 8.
int a = 5/2; int b = 5.0/2; int c = 5 / 2.0; int d = 5.0/2.0;
Irrespective of numbers after decimal point, an int variable holds only integer value i.e 2.
float a = 5/2; float b = 5/2.0; float c = 5.0/2; float d = 5.0/2.0;
In division, to get the actual real value, you should specify at least one real number.
Variable a holds only 2. But variables b,c and d contain real numbers as either numerator or denominator is a real number.
int a = 5/2 stores only 2.
int var = 3.5;
a stores only integer value. So, 3.5 is truncated to 3.
int main() { int var = 3.5;; printf("%f", var); return 0; }
As the variable type is an integer, you have to use %d as a format specifier. If you specify wrong format specifier, you will not get expected output.
int main() { int a = 25%10; printf("%d", a); return 0; }
Modulo division operator returns the reminder of division of 25 by 10. 10x2 + 5 = 25. So reminder is 5.
Modulo Division operator % in C language can be used only with integer variables or constants.
int main() { int a = -25%-10; int b = -25%10; int c = 25%-10; printf("%d %d %d", a, b, c); return 0; }
Sign of a modulo division operation is same as the sign of Numerator. So sign of 25 is taken always.
int main() { float a = 45; printf("%f", a); return 0; }
Integer value 45 is promoted to float i.e 45.0 and printed with all 6 decimal numbers.
Operators Multiplication *, Division / and Modulo Division % are all having the same Priority.
+ and - has same priority. *, / and % has equal priority. But (+, -) has less priority than (*, / and %).
Operators *, / and % have Left to Right Associativity. Operators + and - have Left to Right Associativity. Operator = has Right to Left Associativitiy.