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

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
@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)

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.

Harish Mahajan said:   7 years ago
What is the difference between return 0, return 1?

What is void main(), int main(), main()?

Harish Mahajan said:   7 years ago
If the compiler is GCC Linux then what will be the output?

Please, anyone, tell me.

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.

BhavadipGothadiyaBG said:   8 years ago
Here If we assume the int _AX.

Then output of the program is 1.


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int fun();
int i;
i = fun();
cout<<i;
return 0;
}
int fun()
{
int _AX = 1990;
}

How 1990? Explain Please.
(2)

Prerna said:   8 years ago
In the function, fun we didnot write return ax so how will the value be passed in main?

Jit said:   8 years ago
The answer is wrong. [Error] '_AX' was not declared in this scope.

Gulshan Kumar said:   8 years ago
In this program, fun has no any return type so according to me, it returns garbage value.


Post your comments here:

Your comments will be displayed after verification.