How do pointers affect function arguments in C++? Can you guess the output?

💻 GUESS..! Sometimes, understanding how functions handle variables in C++ can be a real eye-opener 👀 Here’s a short piece of code that looks simple — but the output might not be what you first expect. It’s a great reminder of how pointers, function arguments, and memory handling really work behind the scenes. Can you guess what the output will be? 🤔 #cpp #programming #developers #coding #pointers #cplusplus #learning #outputguess

  •     #include<iostream>
    using namespace std;

    void fun(int* a, int b);
    int main(){
        int x = 10, y = 5;
        fun(&x, y);
        cout << x << "\t"<< y << endl; 
    }

    void fun(int* a,int b){
        *a += 10;
        b += 10; 
    }

1. Void - ok, nothing to return. 2. We need to pass by pointer or better by reference if we want to change passed args. 2. Boom 💥 b is just copy. Nothing will happen. 3. Output : 20 5

To view or add a comment, sign in

Explore content categories