C + + Primer notes (2) Chapter II variables and basic types

Source: Internet
Author: User

Chapter II variables and basic types

1. The basic built-in types include arithmetic types and empty types, and arithmetic types are divided into two categories: integer (including character and Boolean type) and floating point type;

2. The value of the Boolean type (BOOL) is true (true) or False (false);

3. Literal constants: Each literal constant corresponds to a data type, and the form and value of the literal constant determines its data type.

A character enclosed in single quotation marks is a char literal, with 0 or more characters enclosed in double quotation marks, which are string literals;

20 Shaping literals

' A ' character literals

"Hello World" or "" will have string literals

' A ' represents an individual character a, while "a" represents an array of qualifying characters, one is the letter A and the other is a null character.

4. The basic form of the variable definition: The first is the type specifier, followed by one or more variable names (variable names separated by commas), and finally end with a semicolon;

1     int 1, i,k; // I,j,k is the same as int type, I is initialized to 1;

5. Variable declaration and definition: declaration is to make the name known to the program, a file if you want to use a name defined elsewhere must contain a declaration of the name, and the definition is

Creates the entity associated with the name, the keyword extern. Any declaration that contains an explicit initialization becomes a definition;

1     extern int i; // declaring I rather than defining 2     int i; // declare and define 3     extern int 1; // definition

6. Identifiers consist of letters, numbers, underscores, must start with letters or underscores, variable names to reflect the actual meaning, the variable name is generally lowercase, the custom class name usually begins with an uppercase letter,

If it consists of multiple words, there should be a clear distinction between the words.

1     int index; 2     Char " ABC " ; 3     int Sales_item; 4     int Carbridegesort;

Also attached is a basic data type understanding and conversion of small programs:

1 //Type Conversion Example2 3#include <iostream>//header File4 using namespaceStd//with Std::cout a function;5 6 intMain ()7 {8     BOOLb = the;9cout<<"B ="<<b<<endl;//B = 1Ten  One     inti =b; Acout<<"i ="<<i<<endl;//i = 1 -  -i =3.14; the     DoublePI =i; -cout<<"pi ="<<pi<<endl;//pi = 3.0 -  -UnsignedCharc =-1; +cout<<"C ="<<c<<endl;//if char accounts for 8 bits, C is 255 -  +SignedCharC2 = the; Acout<<"C2 ="<<c2<<endl;//if char occupies 8 bits, C is undefined at  -System"Pause"); -}

C + + Primer notes (2) Chapter II variables and basic types

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.