[C ++ Basics] 012 _ Play Main Function

Source: Internet
Author: User

Well, have you ever wondered whether the main function can be declared? Let's try it!

1 # include <iostream> 2 using namespace STD; 3 4 int main (); 5 6 int main () {7 system ("pause"); 8 return 0; 9}

There is no problem at all. It can be seen that main is also a very common function!

Can a common function call the main function? Let's try again!

1 # include <iostream> 2 using namespace STD; 3 4 int main (); 5 6 void test () {7 main (); 8} 9 10 int main () {11 test (); 12 system ("pause"); 13 return 0; 14}

Compilation is successful, but we can see that this is a dead chain. Haha, check the running effect!

Oh, my God, not good:

The 0x772115de in 005_inline.exe has an unhandled exception: 0xc00000fd: Stack Overflow.

Stack Overflow, dead chain, haha!

Even if you add anti-dead-chain code, stack overflow will still occur ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.