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 2 of 5.
Ahmedhalim said:
9 years ago
This code will print garbage value because it isn't has return.
SyntaxError said:
9 years ago
In the above given program, there is no return type in called fn. Then how it return the value to calling function?
And why this c compiler showing an error?
And why this c compiler showing an error?
Ashok said:
9 years ago
How can prototype declaration of fun() done in main function?
Swapnil said:
9 years ago
First, declare the _AX as integer variable in fun function then, return the _AX from fun Function in order to get the same output. But _AX is an accumulator which we can not access directly in GCC compiler. Why so? Please explain.
Manish kulkarni said:
8 years ago
As there is no return statement then how it will return value to calling the function?
Gulshan Kumar said:
8 years ago
In this program, fun has no any return type so according to me, it returns garbage value.
Jit said:
8 years ago
The answer is wrong. [Error] '_AX' was not declared in this scope.
Prerna said:
8 years ago
In the function, fun we didnot write return ax so how will the value be passed in main?
Sam said:
8 years ago
Function "fun" is defined after the main function. So where is the function prototype. Also there is no return statement available present in the fun function.
Harish Mahajan said:
7 years ago
What is the difference between return 0, return 1?
What is void main(), int main(), main()?
What is void main(), int main(), main()?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers