JAMIA 2024 Computer PYQ — What will be values for a and c after execution of the following … | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
JAMIA 2024 — Computer PYQ
JAMIA | Computer | 2024
What will be values for a and c after execution of the following code if a is 10, b is 5, and c is 10? If ((a> b) && (a < = C)) a = a + 1; else c = c + 1;
Choose the correct answer:
A.
a = 10, c = 10
B.
a = 10, c = 11
C.
a = 11, c = 10
(Correct Answer)
D.
a = 11, c = 11
Correct Answer:
a = 11, c = 10
Explanation
Given Values
a=10
b=5
c=10
Step 1: Evaluate the Condition
The code checks the condition: (a > b) && (a <= c).
First Part: Is a > b?
10 > 5 is True.
Second Part: Is a≤c?
10≤10 is True.
Logical AND (&&): Since both sides are True, the entire condition evaluates to True.
Step 2: Execute the Corresponding Block
Because the condition is True, the if block executes, and the else block is skipped.
Update a:
a=a+1
a=10+1
a=11
Value of c:
Since the else block was not executed, the value of c remains unchanged.
c=10
Explanation
Given Values
a=10
b=5
c=10
Step 1: Evaluate the Condition
The code checks the condition: (a > b) && (a <= c).
First Part: Is a > b?
10 > 5 is True.
Second Part: Is a≤c?
10≤10 is True.
Logical AND (&&): Since both sides are True, the entire condition evaluates to True.
Step 2: Execute the Corresponding Block
Because the condition is True, the if block executes, and the else block is skipped.
Update a:
a=a+1
a=10+1
a=11
Value of c:
Since the else block was not executed, the value of c remains unchanged.