how is the ans calculated actlly?Code:#include<stdio.h> int confusion(int x,int y) { x=2*x+y; return x; } int main() { int x=2,y=5; y=confusion(y,x); x=confusion(y,x); printf("%d %d\n",x,y); system("pause"); return 0; }
how is the ans calculated actlly?Code:#include<stdio.h> int confusion(int x,int y) { x=2*x+y; return x; } int main() { int x=2,y=5; y=confusion(y,x); x=confusion(y,x); printf("%d %d\n",x,y); system("pause"); return 0; }
When you call the function you pass in 2 variables. There is a computation and x is returned. You are setting y and x to the same value in main though...
If you don't understand this, try to Google Functions in C, and also check out the functions tutorial here on this site. Also, it may help to Google about scope and automatic variables.
Oops, I hadn't read it clearly enough. For some reason I had thought they were entering the same x/y and didn't know they were overwriting one with a new value before calling the function again on the next variable.