why return causes an Illegal syntax??

C

chump1708

main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0; //line 1
}

1. Can I know why using return causes an illegal syntax...I guess it
has something to do with command line arguments..
2. can anyone explain the line 1?? its a bit confusing....
 
A

Artie Gold

main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0; //line 1
}

1. Can I know why using return causes an illegal syntax...I guess it
has something to do with command line arguments..
2. can anyone explain the line 1?? its a bit confusing....
1. No, it's because `return' is a statement, not an expression.
2. Simple. Syntax error. Next?

--ag
 
C

chump1708

I meant what does first part of the statement (main && argc) ?
main(argc-1, NULL) : return 0;
does...IGNORE THE PRESENCE OF return...
 
M

Mark McIntyre

main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0; //line 1
}

1. Can I know why using return causes an illegal syntax...

The operands of the ternary operator must be of the same type, eg both
numeric, both the same struct type, both pointers to the same type,
both void, etc etc. "return 0" has no type and is not the same as the
type of main() which is int.

The correct way to write this (which is an example of a recursive
main, and illegal in C++ by the way) ) is

return (main && argc) ? main(argc-1, NULL) : 0;
has something to do with command line arguments..
2. can anyone explain the line 1??
its a bit confusing....

Where do you get this rubbish? This is the third total nonsense bit
of code you've posted. What are you trying to do?

Also, when posting to CLC, you should post snippets which #include any
relevant headers. In this case, you need something to define NULL.
Mark McIntyre
 
C

chump1708

Hey brother...chill off...All I am trying to do is learn the way you
experts think....Is it bad??
 
M

Mike Wahler

Hey brother...chill off...All I am trying to do is learn the way you
experts think....

What the experts think is that you need to read
some C textbooks and learn how the language works
instead of guessing.
Is it bad??

Yes, I think your apparent method of learning C is
quite bad.

Also note that it's not usually a good idea to
insult those who can help you.

Mark might not be the best expert here (I doubt he'd
make that claim), but imo he does have considerable
C knowledge and can offer much help (if you don't
drive him away, that is).

-Mike
 
I

Ingo Menger

main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0; //line 1
}

1. Can I know why using return causes an illegal syntax...

Yes you can. Just learn C syntax.
2. can anyone explain the line 1?? its a bit confusing....

Since it's not C, there is nothing to explain.
 
P

pete

Mark said:
main(int argc, char *argv[])
{
(main && argc) ? main(argc-1, NULL) : return 0; //line 1
}

1. Can I know why using return causes an illegal syntax...

The operands of the ternary operator must be of the same type, eg both
numeric, both the same struct type, both pointers to the same type,
both void, etc etc.

Assuming that you mean the two rightmost operands,
if either of the two right most operands
is a null pointer constant, or pointer to type void,
then the other operand may be a pointer to a different type.
Where do you get this rubbish? This is the third total nonsense bit
of code you've posted.

I've noticed that too.
 
M

Mark McIntyre

I meant what does first part of the statement (main && argc) ?
main(argc-1, NULL) : return 0;

its a ternary operator, equivalent to if... then... else... endif

if (main && argc)
main(argc-1, NULL):
else
return 0;

except that it has different syntax rules.
does...IGNORE THE PRESENCE OF return...

but you did ask about that bit
Mark McIntyre
 
M

Mark McIntyre

Hey brother...chill off...

Sure, if you promise to start learning properly and use a book. You
cannot learn programming from usenet.
All I am trying to do is learn the way you
experts think....Is it bad??

Learning the way we think, by posting garbage posts?

Well, you're going to achieve that, because most of us are probably
now thinking "this chump1708 is a complete idiot".

Mark McIntyre
 
C

Chuck F.

Hey brother...chill off...All I am trying to do is learn the way
you experts think....Is it bad??

Now this sort of rudeness is what will get you plonked.

--
"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." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 

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
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top