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 1 of 5.
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.
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)
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).
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)
Lingaraj said:
1 decade ago
@Shilpa.
In Linux the output will be zero.
In Linux the output will be zero.
Shilpa said:
1 decade ago
What will be the result in LINUX?
Richik said:
1 decade ago
In function 'fun':
Line 13: error: '_AX' undeclared (first use in this function).
Line 13: error: Each undeclared identifier is reported only once.
Line 13: error: For each function it appears in.
Encountering these errors, on copying the given code. How did you guys get the answer as 1990?
Line 13: error: '_AX' undeclared (first use in this function).
Line 13: error: Each undeclared identifier is reported only once.
Line 13: error: For each function it appears in.
Encountering these errors, on copying the given code. How did you guys get the answer as 1990?
Neeraj said:
10 years ago
How can a function be called in main without mentioning its prototype before the main()?
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.
Raju said:
9 years ago
'_AX' is undeclared so it should not give any output.
Sanju said:
9 years ago
First of all, in the function definition, there is no return statement. So error1===no return statement.
_AX is not declared. So error2=='_AX' undeclared (first use in this function).
How will it give output?
Can anyone help me?
_AX is not declared. So error2=='_AX' undeclared (first use in this function).
How will it give output?
Can anyone help me?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers