0
C ++ question
#include <iostream> using namespace std; int x=20; int f(){ x-=2; return --x; } int g(){ int x=50; x++; return f(); } int main() { while(x%3>=1) cout<<g()<<" "; return 0; } Can someone tell me how this is work? I know the answer but not how it’s work
1 Resposta
+ 4
start with " while " loop
>>while(20%3>=1) //true
>>calls " g() " function
>>g() calls " f() " //x in g() set to x=51 , I think no work of this x
>>in f() value of " x " is 20 //x is declared global (not in f() )
>>in f() x=x-2; > x=20-2; x=18
>>return --x //it makes x=17 and it return to g() , g() return in main and 17 will be printed
>>now value of global variable is x=17
>>again start with while loop while(17%3>=1) //same process till while condition evaluates to false !
HOPE THIS HELP !
I suggest, if you are beginner, write this process on your notebook