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;
}
Garbage value
0 (Zero)
1990
No output
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 4 of 5.

Ganesh said:   1 decade ago
sir _ax variable is not declared in function how can it executes

Ahmedhalim said:   9 years ago
This code will print garbage value because it isn't has return.

Kiran said:   1 decade ago
How can prototype declaration of fun() done in main function ?

Ashok said:   9 years ago
How can prototype declaration of fun() done in main function?

ADDY said:   1 decade ago
@Deepak.

Yes a function can be defined another function.

Raju said:   9 years ago
'_AX' is undeclared so it should not give any output.

Deepak said:   1 decade ago
Can a function be declared inside another function?

Lingaraj said:   1 decade ago
@Shilpa.

In Linux the output will be zero.

Vishal said:   1 decade ago
Thanks Sundar for explaining in detail.

Shilpa said:   1 decade ago
What will be the result in LINUX?


Post your comments here:

Your comments will be displayed after verification.