Assignment 2: Modify Operators (MCQ)
1. What is the output of the following?
#include<stdio.h>
int main()
{
int var=5;
printf(“%d\n”, var++);
printf(“%d\n”,++var);
return 0;
}
2. Evaluate the following expressions;
-3+4*5-6
3+4%5-6
-3*4%6/5
(7+6)%5/2
3. What is the output of the following?
void main()
{
int i=0, j=1, k=2, m;
m = i++ || j++ || k++;
printf("%d %d %d %d", m, i, j, k);
}
Hint: In an expression involving || operator, evaluation takes place from left to right and will be stopped if one of its components evaluates to true(a non zero value). So in the given expression m = i++ || j++ || k++. It will stop at j and assign the current value of j in m. therefore m = 1 , i = 1, j = 2 and k = 2 (since k++ will not encounter. so its value remain 2)
4. What is the output of the following.
-
#include <stdio.h>
-
int main()
-
{
-
int i = 0;
-
int x = i++, y = ++i;
-
printf("%d % d\n", x, y);
-
return 0;
-
}
5. What is the output of the following..
-
#include <stdio.h>
-
void main()
-
{
-
int x = 97;
-
int y = sizeof(x++);
-
printf("X is %d", x);
-
}
Hint: The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.
6. What is the output of the following Program?
void main()
{
int a=100, b;
b = a++ + ++a;
printf(“%d %d %d %d”, b, a++, a, ++a);
}