Variable definition is a strange problem.

Source: Internet
Author: User

[Cpp] # include "stdio. h "# include <string> int add () {int a; int B = 2; a = a + B; printf (" % d \ n ", ); return 0;} void cat () {char st1 [] = "bbbbbbb"; char tt [50]; strcat (tt, st1); printf ("% s \ n ", tt);} int main () {// loop body definition is defined only once during compilation. The space is the same space for (int j = 0; j <2; j ++) {char st1 [] = "bbbbbbbbb"; char tt [50]; strcat (tt, st1); printf ("% s \ n in loop ", tt);} printf ("\ n"); // The address space is not changed, but the content is cleared, it's amazing !???????????????!! For (int I = 0; I <3; I ++) {cat (); add ();} printf ("\ n"); // contains the cyclic body, the address space is cleared. // If the method is not cleared, the variables are in the same space. Cat (); {cat ();} printf ("\ n"); // The variable space with the same name cannot be reached. {char st1 [] = "bbbbbbb "; char tt [50]; strcat (tt, st1); printf ("small scope 1% s \ n", tt) ;}{ char st1 [] = "bbbbbbb "; char tt [50]; strcat (tt, st1); printf ("small scope 2% s \ n", tt);} return 0;} Be sure to initialize the variables, clear it @!

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.