Skip to content
GATEiit

GATE CSE 2019 Q28: C program with jumble(x, y) = 2x + y called twice: value printed

Syllabus topic: Programming in C

Question

Consider the following C program:

#include <stdio.h>
int jumble(int x, int y){
    x=2*x+y;
    return x;
}
int main(){
    int x=2, y=5;
    y=jumble(y,x);
    x=jumble(y,x);
    printf("%d \n", x);
    return 0;
}

The value printed by the program is ________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 26 (official GATE 2019 final answer key)

Concept used: C passes arguments by value: changes to parameters inside a function do not affect the caller's variables, only the returned value is used.

Concept notes

Loading notes…

First step: Note the swapped argument order in the call jumble(y,x), compute the new y from the first call, then use it in the second call.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Programming in C

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key