GATE CS 2024 Set 2 — Question 13
MCQ+1 / -0.33MediumFunctions & RecursionC ProgrammingProgramming & Data Structures
Programming & Data Structures → C Programming → Functions & Recursion
Last updated
Question
Consider the following C program. Assume parameters to a function are evaluated from right to left.Which one of the following options is the CORRECT output of the above C program?
#include
int g(int p) { printf("%d", p); return p; }
int h(int q) { printf("%d", q); return q; }void f(int x, int y) {
g(x);
h(y);
}
int main() {
f(g(10),h(20));
}
A.
20101020
B.
10202010
C.
20102010
D.
10201020
Correct answer
(A) 20101020
Solution
The problem specifies that function parameters are evaluated from right to left. In the
main function, the call is f(g(10), h(20)). 1.Evaluate arguments of
f (Right to Left):- First,
h(20)is evaluated. It executesprintf("%d", 20), printing 20, and returns 20. - Next,
g(10)is evaluated. It executesprintf("%d", 10), printing 10, and returns 10. - At this point, the output sequence is 2010.
f(10, 20):- Inside
f,g(x)is called withx=10. It prints 10. - Then,
h(y)is called withy=20. It prints 20.
More questions on C Programming
2024 Set 1 Q17Given an integer array of size , we want to check if the array is sorted (in either ascending or…2024 Set 2 Q17Let be the adjacency matrix of a simple undirected graph . Suppose is its own inverse.…2024 Set 1 Q18Consider the following C program: [code] Which one of the following statements is CORRECT?2024 Set 1 Q19Consider the following C program: [code] Assume that the input to the program from the command line…2024 Set 1 Q21In a tree, the requirement of at least half-full (50%) node occupancy is relaxed for which…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free