OA. free
Free
TCS Data Structures & Algorithms Data Structures & Algorithms Medium

Question 4: include <stdio.h int function1(int,int); int main() 216 TCS NQT Solved Paper -...

TCS technical mcq question, verified with a worked answer. Free to practise - no sign-up.

#include <stdio.h> int function1(int,int); int main() 216 TCS NQT Solved Paper - 13th Sept 2021 [Slot 1] { int a=10,b=10; printf("%d",function1(a,b)); return 0; } int function1(int a , int b) { return(a-(a==b)); } Ans:- B) 9 - A) 0 - B) 9 - C) Not visible - D) Not visible

Choose one option.
Show answer & explanation
Answer: B. 9

The expression (a == b) is a relational operation that evaluates to a boolean value. In C, a true condition evaluates to 1 and a false condition evaluates to 0. Since a and b are both 10, the expression becomes 10 - 1, resulting in 9.

Step-by-step Derivation:
Step 1: Analyze the main function. Two integer variables 'a' and 'b' are initialized to 10.
Step 2: The function 'function1(a, b)' is called with arguments (10, 10).
Step 3: Inside 'function1', the return expression is 'a - (a == b)'.
Step 4: Evaluate the relational expression '(a == b)'. Since 10 == 10 is true, this expression evaluates to the integer 1.
Step 5: Substitute the value back into the expression: 10 - 1.
Step 6: The final result is 9, which is returned to the main function and printed via printf.