Variable [MCQ] : Find Output of Program (Multiple Choice Questions)
Question 1 |
Guess the output of the following code snippet -
#include<stdio.h> int main() { int i = 10 ,j; j = ++i; printf("%d, %d", i, j); return 0; }
11 10 | |
11 11 | |
10 11 | |
10 10 |
Question 1 Explanation:
In the following expression -
Thus 11 is assigned to i and value of i also becomes 11.
j = ++i;Value of i gets incremented first and then it is assigned to j.
Thus 11 is assigned to i and value of i also becomes 11.
Question 2 |
Guess the output of the following example -
#include<stdio.h> int main() { int i = 10, j = 10 ,k; k = ++i + j++; printf("%d, %d, %d", i, j, k); return 0; }
10, 11, 21 | |
11, 11, 22 | |
11, 11, 21 | |
11, 10, 21 |
Question 2 Explanation:
Step 1 : Initial Values
int i = 10, j = 10 ,k; k = ++i + j++;Step 2 : Evaluating Expression
k = ++i + j++; = (Pre Increment i) + (Post Incr. j) = (11) + (10) ....[Post Incr Pending] = 21Step 3 : Execute Pending Post Increment
j = j++ = 11
Question 3 |
In which order do the following gets evaluated in C Programming -
- Relational
- Arithmetic
- Logical
- Assignment
1234 | |
2143 | |
3214 | |
2134 |
Question 4 |
Guess the output of the following program -
#include<stdio.h> int main() { int i = 3 ,j; j = i++; printf("%d, %d", i, j); return 0; }
3, 4 | |
4, 4 | |
3, 3 | |
4, 3 |
Question 4 Explanation:
Value of i is assigned to the 'j' first then value of 'i' gets incremented because post increment is applied in the expression,
Question 5 |
Guess the output of the following expression ?
#include<stdio.h> int main() { int i = -30, j = 20, k = 1, m; m = ++i && ++j && --k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; }
-29, 21, 0, 0 | |
-29, 21, 1, 1 | |
-30, 21, 0, 1 | |
-30, 21, 1, 1 |
Question 5 Explanation:
Step 1 : Initial Values
int i = -30, j = 20, k = 1, m; m = ++i && ++j && --k;Step 2 : Evaluating Expression
m = ++i && ++j && --k; = -29 && 21 && 0; = True && 0 = True && False = False = 0and In the pre increment the value of i,j,k will be -
i = -29 j = 21 k = 0
There are 5 questions to complete.