what is the meaning of _AX = 1000 in the following C program?
c, function
Solution
According to TC compiler (32 bit), the returned value of a function is stored in Accumulator (AC), and it can be accessed in TC compiler using _AX, so when you write:
_AX = 1000;
means that you are placing value 1000 inside Accumulator, and when the function completes its execution and the control reaches to the caller function, then the value of Accumulator is checked, and in this case this value will be stored in x.
here the statement
x = get_val();
would be simply
x = 1000;
but this would be in your case only, means in (TC 32 bit windows compiler), it may or may not work for other compilers.
Problem
I am a beginner in C programming language, recently I have started learning functions, I have studied that functions use keyword return to return a value in the caller function. For example the following program. ``` int getVal(){ return 1000; } int main(){ int x = getVal(); printf("x = %d",x); return 0; } ``` will print x = 1000 but I am confused that (under turbo C compiler 32 bit) why the following program is producing output as x = 1000 too. Please explain. ``` int get_val(){ _AX = 1000; } int main(){ int x = get_val(); printf("x = %d",x); return 0; } ```