C ++ Primer data type learning notes

xiaoxiao2021-03-06  96

third chapter

type of data

128U no sign number 128

1024U unsigned number 1024 u case

1L long shape 1

8LU no symbol Long type 8

Vertical tab / V

Wide character wchar_t l'a '

variable

The object name generally uses lowercase letters, for example, we tend to write index without writing index.

Wood as a type name and INDEX is generally seen as a constant value usually defined with a pre-processor indicator #define

. Identifier generally uses a helpful name - that the name of the prompt can be prompted on the usage in the program.

ON_LOAN or SALARY is what should be written as a Table or TBL This is purely style problem is not correct.

problem

For a plurality of words composed, it is generally generally plus a downline or embedding between each word.

The first letter of the word is, for example, will be written into student_loan or studentloan instead of

StudentLoan I have listed all three forms of people in all three forms.

Objectorientedbackground likes people with C or process background with uppercase letters

C_OR_PROCEDURAL_BACKGROUND The next line is again explained using ISA ISA or IS_A

Just a style problem and correct or not

A simple definition specifies the type and identifier of the variable. It does not provide an initial value if a variable is defined within the full Law Global Scope, and the system guarantees the initial value of 0

If the variable is defined in the local domain local scope or dynamically allocated by the New Expression, the system does not provide initial value 0 these objects are called uninited uninitialized.

The object that is not initialized is not no value but its value is undefined undefined

C supports two forms of initialization first form is an explicit syntax form using assignment operators.

INT IVAL = 1024;

String Project = "Fantasia 2000";

In the implicit form, the initial value is placed in parentheses.

INT IVAL (1024);

String Project ("Fantasia 2001");

Pointer type

In the example below, LP is a pointer to the LONG type object and LP2 is a long-type data object not a pointer.

Long * LP, LP2;

When the programmer wanted to define the second string pointer, he will correctly modify the definition.

// 喔: PS2 is not a string pointer

String * ps, ps2;

VOID * Type pointer it can be assigned the value of the address value of any data pointer type to be assigned to it

// OK: void * can hold any address value of any pointer type

Void * PV = Pi;

PV = Pd;

Pointer to pointers, examples

#include

Using

Namespace

STD;

Int main () {

INT A = 20;

INT * P = & A;

Cout <<

"A:" << a << Endl <<

"* P:" << * p << endl;

INT ** PP = & P;

// & p point to the address of the pointer

Cout <<

"** PP:" << ** PP << Endl;

// Double solution reference

Return 0;

}

Pointer plus 2 means that the address value held by the pointer adds the length of the type of two objects, for example, suppose a char is one byte an int is 4 byte double is 8 bytes. So pointers

Plus 2 is to increase the address value of 2 8 or 16 is completely dependent on the type of pointer is Char Int or Double

String type

Convert String as a C-Style string:

Const char * str = string1.c_str ()

^^^^^

Const limit modifier

Const int buffsize = 512 // Buffer size prevents this error:

IF (bufsize = 0) {...}

Const Double * CPTR;

CPTR is a pointer to a CONST object to a Double type. We can read this definition from right left.

CPTR is a pointer to the Double type to be defined in this, this medium is subtle in the CPTR

It is not a constant that we can re-assign CPTR to point to different objects but cannot modify the object pointing to the CPTR.

Can't modify the value points to the Const pointer

Char * str = "llll";

Const char * p = STR;

* p = '4'; // incorrect

Reference type

INT IVAL = 1024;

INT * PI = & IVAL;

// ok: refptr is a reference to a pointer

INT * & PTRVAL2 = Pi;

Once the reference has been defined, you can no longer point to other objects.

Double DVAL = 3.14159;

// Only for const references is legal

Const Int & IR = 1024;

Const Int & IR2 = DVAL;

Const Double & DR = DVAL 1.0;

Boolean type enumeration type

ENUM ENUMTEST {a, b, c, d}

ENUM ENUMTEST2 {a = 1, b = 3}

>> END << //

转载请注明原文地址:https://www.9cbs.com/read-104696.html

New Post(0)