Dark Horse programmer--"Dark Horse video Notes" variable and scope of C language Foundation

Source: Internet
Author: User

1. Variable type variable name; int score; 2. Assignment of variables score = 100; Score = A; Score = b = 100; 3. The output of the variable int a = 200; printf ("%i", a); Common format characters: 1>%d\%i integer (int) 2>%f decimal (float, double) 3>%c character (char) sample code
   1:  int main ()
   2:  {
   3:  /    *
   4:      int score;
   5:      //assignment operation (initialization)
   6:      score = 1000;
   7:      
   8:      score = 10000;
   9:      
  Ten:      char c;
  11:      
  :      ' A ';
  13:      
Int.   :      int a = 20;
  15:      
  16:      
  :      //int d,e,f;
  18:      
  :      int b;
  20:      
  :      b = a = 40;
  22:      
At   :      b = 30;*/
  24:      
+//variable: As long as there is an indeterminate data, you should define the variable to save       
  :      int score = 205;
  :      //1:15
  :      int time = 75;
  29:      
  :      int bestscore = 3161;
  31:      
+   :      //%d\%i is a format character (placeholder) and can only output integers
  :      printf ("score is%d\n", score);
  34:      
  35:      
  :      float height = 1.78f;
  37:      
Number   :      //%f used to output decimals, default is 6 decimal places
  :      printf ("height is%.2f\n", height);
  40:      
  41:      
  :      char' D ';
  :      printf ("integral grade is%c\n", Scoregrade);
  44:      
  45:      
  :      printf ("score is%d, height is%f, rank is%c\n"' C ');
  47:      
  :      return 0;
  :  }

4. The scope of the variable starts with the line of code that defines the variable and ends at the end of the code block 5. The function of the code block reclaims the variables that are no longer in use, in order to improve performance 6. Exchange of variables 1). Leverage third-party variables (work, master)
   1:  int temp = A;
   2:  a = b;
   3:  
2). Do not use third-party variables (interviews, impressions)
   1:  a = b-a;
   2:  b = b-a;
   3:  

Dark Horse programmer--"Dark Horse video Notes" variable and scope of C language Foundation

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.