-1

Can anyone clear this doubt..??

First C compiler program compiled on which compiler..???

void main()
{
int x=4,i;
i=fun(x=x/4);
printf("%d",i);
}
int fun(int c)
{
return c/2;
}

the answer is 1...how??please reply ....

that prog doesn't give output 1. definitely output will be 0 only. because fun returns 1/2 i.e 0.5 but fun return type is int so fun returns 0 only.. check ur code once again

#include<iostream.h>
#include<conio.h>
int &maxref(int &a, int &b)
{
if (a>b)
return a;
else
return b;
}
void main()
{
int x=20,y=30, max=0;
clrscr();
maxref(y,y)=-1;
cout<<"\n value of x is :"<<x;
cout<<"\n value of y is :"<<y;
getch();
}

This program output is
value of xis 20
value of y is : -1
but how to get this output?
help me.

because fun returns variable as return type is int &. if & is omitted in fun return type,value will be returned but it leads to error as invalid assignment in main function (20=-1).

Edited by Nick Evan: n/a

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Narue
0

>First C compiler program compiled on which compiler..???
Unknown, but probably either an assembler or Ken Thompson's B compiler on the PDP-11.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.