All Exams Test series for 1 year @ ₹349 only
Question

What is the output of the give C language code snippet? 

void f(int x)

{

 x = x + 5;

 }

 int main()

int a = 10;

 f(a); 

printf("%d",a); 

return 0; 

}

This question was previously asked in
RRB JE 2025 CBT 2 Mechanical and Allied Engg Question Paper English (2-Jul-2026) (Shift-1)
The correct answer is

10

The given C language code snippet is designed to illustrate the behavior of function arguments in C, particularly how they are passed to functions. Let's analyze the code step-by-step:

void f(int x) {
        x = x + 5;
    }

The function f is designed to take an integer x as its argument and add 5 to it. Importantly, the variable x in function f is a local copy of the argument passed, not the original variable itself.

int main() {
        int a = 10;
        f(a);
        printf("%d", a);
        return 0;
    }

In the main function, the integer variable a is initialized with the value 10. When f(a) is called, the value of a (which is 10) is copied into the parameter x of function f.

Within function f, x is modified (incremented by 5), but this modification does not affect the original variable a in the main function, because x is merely a copy of a. This is because C uses "pass-by-value" for function arguments, meaning that functions operate on copies of the actual values.

After the call to f(a), the original variable a in the main function remains unchanged. Therefore, when printf("%d", a); is executed, it prints the value of a which is still 10. Thus, the output of the code is 10.

Conclusion: The correct output is 10, as confirmed by the "pass-by-value" mechanism in C where the original variable remains unaltered after a function call.

Was this answer helpful?

Similar Questions

  1. Consider the following code snippet in C programming language. 

    int n = 5; 

    int m = n++; 

    What is the value of m after execution?

  2. Which statement is TRUE about if statement in the C programming language?

  3. Which shape is used to represent a decision in a flowchart?

  4. You need to read a floating-point value from the user in the C programming language. Which of the following statements correctly performs this task?

  5. What are the statements that begin with # symbol called in C programming language?


Important Questions from Programming in C

  1. Which one is the reserved word in C language ?

  2. Which of the following is the feature(s) of High level programming languages?

    I. Portability

    II. Easy debugging

  3. Which of the following is a type of subprogram?

    I. Function

    II. Subroutine

  4. In object-oriented programming, which keyword ensures that a member variable belongs to the class itself rather than to any specific object, thereby allowing all instances to share a single copy of that variable?

  5. The condition num! = 65 cannot be replaced by

Need Expert Advice?
Test Series
RRB JE img
Railways
RRB JE Prev. Yr. Paper (CBT 1 + CBT 2) Test Series
290 Tests 5 Tests Free
4860 Attempts
4.3(90)
English

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App