GATE CS 2024 Set 2 | Question 13

Programming & Data Structures › Functions · MCQ · 1 mark · Answer: A

  1. Question 13Programming & Data Structuresmcq1 mark
    Parameters are evaluated right to left.
    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)); }
    Correct output?
    • A.
      20101020
      ✓
    • B.
      10202010
    • C.
      20102010
    • D.
      10201020

    Answer: A

    Solution

    Answer: (A) 20101020 f(g(10), h(20)): arguments evaluated right-to-left, so h(20) prints 20, then g(10) prints 10 -> "2010". Then inside f, g(x) prints 10, h(y) prints 20 -> "1020". Total: "2010"+"1020" = "20101020".

More GATE PYQ on Functions

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2024 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →