Program2

M

Meenu

The output of the following program confuses me

void main()
{
int x=10,y=20,z=5,i;
i=x<y<z;
printf("i=%d\n",i);
}
 
J

junky_fellow

Meenu said:
The output of the following program confuses me

void main()
This is wrong. Use
int main(void)
{
int x=10,y=20,z=5,i;
i=x<y<z;
printf("i=%d\n",i);
}

i=x<y<z is equivalent to
i = ((x<y)<z); <--- x<y is True
i = ( 1 < z) <--- 1<y is True.
i = 1
 
M

Martin Ambuhl

Meenu said:
The output of the following program confuses me
[1]

void main()
{
int x=10,y=20,z=5,i;
i=x<y<z;
printf("i=%d\n",i);
}

In both this and your other posting

[2]
main()
{
char str[]="part-time musicians are semiconductors";
int a=5;
printf(a>10?"%50s":"%s",str);
}

You are missing needed headers, since printf is a variadic function.
#include <stdio.h>

The 'void' return type for main() in [1] is wrong. main returns an int.
In [2], your main does return an int implicitly in C89 (or C90), where a
function that has no named returned type is assumed to return an int.
However, (a) implicit int is removed from the current standard, so [2]
is wrong under the current standard. Further, in C89 (and C90) in which
implicit int is allowed, main() should explicitly return a value.

In [2], there is no way to predict the output. To have a portable C
program, the last line of output to a stream must end in an end-of-line
('\n') character.

Now tell me that you're a troll and that I took the bait.
 
K

Keith Thompson

Maw said:
*the other way*

You've posted twice on this thread without providing any context or
attributions. I have no idea what you mean by "the other way".

The broken groups.google.com interface is partly responsible for this,
but only partly. It *is* possible to use groups.google.com properly.

The following has been posted here hundreds of times. Read it. Pay
attention to it.

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top