# Quiz on Arithmetic and Assignment Operators in C

Quiz on Arithmetic and Assignment Operators in C | Arithmetic operators are used to performing mathematical operations. The arithmetic operators can operate on any built-in data type.

Assignment operators are used to assign the result of an expression to a variable. Syntax: `Identifier = expression;`

Here identifier generally represents a variable and expression represents a constant, a variable, or a more complex expression. Recommended Reading:- Operators in C

## C Quiz on Arithmetic and Assignment Operators

Find the output of the programs given Quiz on Arithmetic and Assignment Operators in C?

Q1) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a = 2;
a += a += a += 3;
printf("%d",a);
return 0;
}``````

a) 9
b) 11
c) 30
d) 20

Ans:- d) 20

a+=a+=a+=3; it can written as a+=a+=a=a+3; a=2; Or, a+=a+=5; a=5; Or, a+=a=5+5; a=5; Or, a+=10; a=10; Or, a=a+10; a=10; Or, a=20. So, finally a=20.

Q2) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
float a, b;
int c;
a = 5;
b = 2;
c = a/b;
printf("%d",c);
return 0;
}``````

a) 2
b) 2.000000
c) 3
d) 2.500000

Ans:- a) 2

Q3) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int num = 10;
num /= num /= 2;
printf("%d",num);
return 0;
}``````

a) 2.5
b) 2
c) 1
d) 0

Ans:- c) 1

num/=num/=2; num=10; Or, num/=num=num/2; num=10; Or, num/=5; num=5; Or, num=num/5; num=5; Or, num=5/5=1. Finally num=1.

Q4) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a;
a=20;
a*=30+5;
printf("%d",a);
return 0;
}``````

a) 600
b) 605
c) 700
d) 20

Ans:- c) 700

a*=30+5; it can be written as a*=35; Or, a=a*35=20*35=700. Finally a=700.

Q5) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
char x, y, z;
x = 'A';
y = 'B';
z = x + y;
printf("%d", z);
return 0;
}``````

a) Garbage Value
b) -125
c) 131
d) Compile-time error

Ans:- b) -125

Value of z = 65 (for A) + 66 (for B) = 131

The value 131 is in char. Char range is from -128 to 127. 131 is out of range. So, from circle representation of char value will be -125.

Q6) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a=5;
a*=a;
printf("%d",a);
return 0;
}``````

a) 10
b) 25
c) 5
d) 0

Ans:- b) 25

a=a*a=5*5 so a=25

Q7) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
printf("%d, %d, %d, %d",
20/3, -20/3, 20/-3, -20/-3);
return 0;
}``````

a) -6, 6, -6, 6
b) -6, -6, 6, -6
c) 6, -6, -6, 6
d) 6, 6, 6, -6

Ans:- c) 6, -6, -6, 6

In the division operator, If exactly any one of the operand is negative then the result is negative. If both operators are positive/negative than the result is positive.

Q8) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
float a, c;
int b;
a = 5;
b = 2;
c = a % b;
printf("%f", c);
return 0;
}``````

a) Error
b) 2.500000
c) 2
d) 2.000000

Ans:- a) Error

Modulus operator (%) does not operate on floating point.

Q9) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a=5;
a += a+a;
printf("%d",a);
return 0;
}``````

a) 5
b) 15
c) 25
d) 10

Ans:- b) 15

a += a+a; it can be written as a += 10; Or, a = a+10 = 5+10 = 15. Finally a=15.

Q10) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int x, y, z;
z = x+y;
printf("%d", z);
return 0;
}``````

a) 32765
b) 0
c) Garbage Value
d) 1

Ans:- b) 0

Local variables (with the automatic storage duration) are not initialized implicitly if they do not have the static storage duration. The actual output will be 0. See more:- https://stackoverflow.com/questions/56887173/what-will-be-the-actual-output-and-why

Q11) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a=2;
a+=3;
printf("%d",a);
return 0;
}``````

a) 2
b) 0
c) 5
d) 3

Ans:- c) 5

a+=3 is a=a+3 which gives 2+3=5.

Q12) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
printf("%d, %d, %d, %d",
20%3, -20%3, 20%-3, -20%-3);
return 0;
}``````

a) 2, 2, -2, -2
b) 2, 2, 2, -2
c) 2, -2, 2, -2
d) 2, -2, 2, 2

Ans:- c) 2, -2, 2, -2

For % operator, the sign of the result is always the same as the sign of the numerator.

Q13) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
float a, b, c;
a = 5;
b = 2;
c = a/b;
printf("%f",c);
return 0;
}``````

a) Garbage Value
b) 1.500000
c) 2.500000
d) 2.000000

Ans:- c) 2.500000

Q14) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a, b;
float c;
a = 5;
b = 2;
c = a/b;
printf("%f",c);
return 0;
}``````

a) 2.500000
b) Garbage Value
c) 1.500000
d) 2.000000

Ans:- d) 2.000000

Q15) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
int a;
printf("%d",a=9);
return 0;
}``````

a) Compile-time error
b) 1
c) 0
d) 9

Ans:- d) 9

Q16) Find the output of the given C program.

``````#include<stdio.h>
int main ()
{
int x = 9;
printf("%d",- -x);
return 0;
}``````

a) None of these
b) Compile-time error
c) -9
d) 9

Ans:- d) 9

Q17) Find the output of the given C program.

``````#include<stdio.h>
int main()
{
printf("%f", 5.0 % 2.0);
return 0;
}``````

a) 2.500000
b) 2
c) Error
d) 2.000000

Ans:- c) Error

Modulus operator (%) does not operate on floating point.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!