C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 1)
1.
What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>
int main()
{
int fun();
int i;
i = fun();
printf("%d\n", i);
return 0;
}
int fun()
{
_AX = 1990;
}
Answer: Option
Explanation:
Turbo C (Windows): The return value of the function is taken from the Accumulator _AX=1990.
But it may not work as expected in GCC compiler (Linux).
Discussion:
43 comments Page 1 of 5.
Amit said:
1 decade ago
What is accumulator?
Amit said:
1 decade ago
Accumulator is a place where the results are stored after calculation.
Rakesh said:
1 decade ago
But the function doesnt have any return value / statement so how could this be possible according to me there must be a garbage value can give a fulfledged explanation if this ques?
Sundar said:
1 decade ago
Compile and Run the following program in Turbo C, you will get 35 as output. It may not work in other compilers.
#include<stdio.h>
int main()
{
int a = 0;
a = 35;
printf("%d");
}
Assume the address of a = 1200.
Assume the address of video memory = 5500;
MOV AH, 35
MOV [1200], AH
MOV [5500], AH // prints on the screen.
This is the way of execution takes place. After copying the value 35 to location 1200, AH retains the value 35.
Then printf("%d") tries to get the value from AH and sends to video memory to display it on screen.
If we use printf("%d %d", age, salary), the value of age transfered to AH before using that value to send to video memory. Then the value of salary is moved to AH then send to video memory.
Assume,
Address of age = 1200;
Address of salary= 1202;
Address of video memory = XXXX; (It will changed according to no. of chars printed on the screen, dont think much about this address value)
MOV AH, [1200]
MOV [XXXX], AH
MOV AH, [1202]
MOV [XXXX], AH
I hope this will help to understand the solution for the given program.
Have a nice day!
#include<stdio.h>
int main()
{
int a = 0;
a = 35;
printf("%d");
}
Assume the address of a = 1200.
Assume the address of video memory = 5500;
MOV AH, 35
MOV [1200], AH
MOV [5500], AH // prints on the screen.
This is the way of execution takes place. After copying the value 35 to location 1200, AH retains the value 35.
Then printf("%d") tries to get the value from AH and sends to video memory to display it on screen.
If we use printf("%d %d", age, salary), the value of age transfered to AH before using that value to send to video memory. Then the value of salary is moved to AH then send to video memory.
Assume,
Address of age = 1200;
Address of salary= 1202;
Address of video memory = XXXX; (It will changed according to no. of chars printed on the screen, dont think much about this address value)
MOV AH, [1200]
MOV [XXXX], AH
MOV AH, [1202]
MOV [XXXX], AH
I hope this will help to understand the solution for the given program.
Have a nice day!
Vishal said:
1 decade ago
Thanks Sundar for explaining in detail.
Ravi said:
1 decade ago
Nice answer sundar.
Supriya said:
1 decade ago
In above given program, there is no return type in called fn. then how it return the value to calling fn?
MANSIH said:
1 decade ago
What is _AX ?
Rathika.B said:
1 decade ago
What is _AX, same type of similar models & their explanations?
KinG said:
1 decade ago
In C, _AX Denotes the Accumulator Where the result of Airthmatic & Logical Operation is stored.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers