need clarification on 2 simple things

Started by
15 comments, last by graveyard filla 20 years, 2 months ago
I'm certainly not giving an answer, but my understanding was that declared variables that are not initiated contain the value held by the memory space holding them.

That said, I'm not a C/C++ programmer, and have only played briefly with the two languages.

[edited by - botman2 on February 20, 2004 10:20:10 PM]
Advertisement
quote:Original post by psamty10
quote:Original post by Deyja
3) int main() {}. Main must always return an int. It doesn''t actually need a return statement though.


This last one is compiler - specific. Try building it on a compiler for an ARM device and youll drive it crazy (without a return stmt).... hehe

According to Stroustrup (TC++PL, 3.2), main() does not need to explicitly return anything (it returns 0 for you if you do not). If your compilers do not accept this, they are not proper C++ compilers.
i think deyja was just saying that int main(){} neeeds to return an int, and it does.

what i was reffering to was the fact that my teacher said that we should always make main a function that returns void, when in fact its good practise to have main return an int.
FTA, my 2D futuristic action MMORPG
quote:Original post by graveyard filla
so if i did

switch (a > b && c < d)

case true: blah blah
break;

case false: blah blah blah
break;


this would work?


We''ve all told you "yes", but why don''t you just test it out instead of wasting time asking us?

only ''static'' variables and arrays are initialized with 0.

Lazzar
---------------------------------------------------------if god gave us the source code, we could change the world!
quote:Original post by graveyard filla
i think deyja was just saying that int main(){} neeeds to return an int, and it does.

what i was reffering to was the fact that my teacher said that we should always make main a function that returns void, when in fact its good practise to have main return an int.

It''s not "good practice" to have main() return an int. main() has to return an int. If main() doesn''t return an int, it''s not proper C++. Note, however, that as I pointed out, it does not need a return statement: If the control reaches the end of main(), the effect is the same as if there had been a ''return 0;'' at the end.
Just a few more remarks about the switch. You can basically use any expression you want for the switch as long as it evaluates to an integral type. You can't use a float variable by itself as the expression since it's obviously not an integral type. Bool can be treated as an integral type so using that as the condition works too.




--{You fight like a dairy farmer!}

[edited by - Greatwolf on February 21, 2004 1:42:32 PM]

--{You fight like a dairy farmer!}

This topic is closed to new replies.

Advertisement