0

Why does this code prints 20 instead of 30?

#include <stdio.h> void fun (int x){ x = 30; } int main(){ int y = 20; fun(y); printf("%d", y); return 0; }

24th Dec 2020, 12:30 AM
Glade
Glade - avatar
2 Respostas
+ 4
You are passing the value of *y* to the function instead of variable *y* itself, this means when inside function, no matter whatever you do with *x*, no changes will be reflected back to *y* thus the output 20.
24th Dec 2020, 1:57 AM
Arsenic
Arsenic - avatar