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.
Abhayraj said:
1 decade ago
Accumulator, data transfer bet memory locations are used in micro-controllers, IC chips, devices like washing machine & so many.
These instructions are namely used in hardware prog -ALP (assembly prog lang). AM I right ?
These instructions are namely used in hardware prog -ALP (assembly prog lang). AM I right ?
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?
Moon said:
1 decade ago
Why this is not working? if we use any kind of variable assume 'p' instead of _AX then also the result is 0. Why it is? please give an explanation of this program.
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.
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?
Thamizharasi said:
10 years ago
Actually it shows an error because the function is defined outside the main function. To show an output the function will be declared before main function.
Saranya said:
11 months ago
In the above code the function doesn't contain any return statement, in the declaration return type is given as int. Then it leads to undefined behaviour.
(1)
Ruku said:
7 years ago
There is no need to define the return (); keyword here because the return value of the function is taken from the Accumulator _AX=1990 itself internally.
Jayanthi said:
1 decade ago
What is the difference between return; and return 0; and also return();?
Where to use void main(), int main() and main()?
Where to use void main(), int main() and main()?
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers