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 5 of 5.

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.

Ruku said:   7 years ago
@All.

Read the question carefully they have mentioned: "Turbo C under DOS" that means there is no need to define return in windows c. The return value of the function is taken from the Accumulator _AX=1990.

But it may not work as expected in GCC compiler (Linux).
(1)

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)


Post your comments here:

Your comments will be displayed after verification.