Exceptions to the rule

The C++ Standard is a pretty large and complex document; however, it is the bible as far as writing C++ code is concerned. The standard is full of exceptions that prove the rule, and this quiz demonstrates just one trivial example.

Question: What, if anything, is wrong with the following code?

int main(){}

Answer: Nothing, it is perfectly valid

Why?

In C++ the return is an optional statement in (and only in) the main function, with 0 being implicitly returned if the return statement is omitted. This is a special case that only applies to the main function.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s