C ++ introduces data types

C ++ is a statically typed, compiled style, universal, case-sensitive, irregular programming language that supports procedural programming, object-oriented and generic programming.

C ++ is a superset of C, in fact, any valid C program is legal C ++ program.

Note: Use statically typed programming language is to perform type checking at compile time rather than at run-time type checking.

C ++ fully supports object-oriented programming, including object-oriented development of four major features:

  • Package

  • abstract

  • inherit

  • Polymorphism

Standard Library

The C ++ standard consists of three important components:

  • Core language, provides all the building blocks, including variables, constants and data types, and the like.

  • C ++ Standard Library provides a number of functions for manipulating files, string and the like.

  • Standard Template Library (the STL), provides a number of methods, data structures, etc. for operation.

ANSI standard is to ensure portability of C ++ - code that you write on the Mac, UNIX, Windows, Alpha computer can compile.

 

 

C ++ program can be defined as a collection of objects, these objects interact with each other by calling the method. Now let's briefly look at what is classes, objects, methods, real-time variables.

  • Objects -  objects that have state and behavior. For example: a dog state - color, name, breed, behavior - shaking, call out to eat. Objects are instances of classes.

  • Class -  class can be defined to describe the behavior of the object / state template / blueprint.

  • Method -  Basically, a method represents an act. A class can contain multiple methods. Can write logic in the method,

  • Operation data and perform all operations.

  • Instant variables -  Each object has its own unique real-time variables. State of the object is created by the immediate value of these variables.


#include < the iostream > the using namespace STD ; // main () is where the program begins execution int main ( ) { COUT << " the Hello World " ; // World output of the Hello return 0 ;    

}

 

 

 

 

 

 

 

Statement block is a set of statements enclosed in curly braces logically connected. E.g:

{   

    cout << "Hello World"// 输出 Hello World   

    return 0;

}

 

 

In addition, we can also use  #if 0 ... #endif to achieve comments, and can achieve a nested format:

#if 0
   code#endif

You can put  #if 0 into  #if 1 to execute  code  in the code.

This form can also help to debug, test using  #if 1  to execute the test code, using the release  #if 0  to mask test code.

#if  after can be any conditional statement.

The following code execution if the condition is true conditions code1, otherwise perform code2.

#if condition
  code1#else
  code2#endif

When using a programming language programming, the need to use a variety of variables to store a variety of information. Variable retains the value of its memory location is stored.

 

Character, wide character, integer, float, double float, Boolean

 

In fact, wchar_t is to come:

typedef short int wchar_t;

So wchar_t actual space and short int are the same.

 

Use  typedef  to take a new name for an existing type. Here is typedef to define a new type of syntax:

typedef type newname;

Enumerated type (Enumeration) is a derived data type in C ++, which is a collection of several enum constant defined by the user.

The following code defines a color enumeration, the variable c of type color. Finally, c is assigned the value "blue".

enum color { red, green, blue } c;c = blue;

By default, the value is 1, the name of the third value is 0, the second name first name is 2, and so on. However, you can also

To the name given to a special value, just add an initial value. For example, in the following enumeration, Green  value of 5.

enum color { red, green=5, blue };

Here, Blue  is 6, because by default, than it will be in front of each name in the name of a big one, but the value 0 is still red.

C ++ also allows to define various other types of variables, such as enumeration, pointer, array, references, data structures, classes , etc., which will be explained in the subsequent chapters

float

单精度浮点值。单精度是这样的格式,1位符号,8位指数,23位小数。

double

双精度浮点值。双精度是1位符号,11位指数,52位小数。

void 表示类型的缺失。

In a C ++ program repeatedly declare a variable, but variables can only be defined once in a file, function or block of code.

 

Try following examples, wherein the variable has been declared in the head, but they are defined and initialized in the main functions:

Examples

#include <iostream>

using namespace std

// variable declaration

extern int ab;

extern int c;

extern float f;  

int main ( ) { // definition of variables      

an int of a ,  . b ;   

int c;  

float f ;   // actual initialization   

a = 10;  

b = 20;  

c = a + b;  

cout << c << endl ;  

f = 70.0/3.0

 cout << f << endl ;  

return 0;

}

 

Similarly, in the function declaration, a function name, and the actual definition of the function can be performed anywhere. E.g:

// function declaration int FUNC ( )  

int main(){ 

    // function call    

you i  =  func ( ) 

; } // function definition 

int func ( ) {  

    return 0

}





Variable definition is to tell the compiler to create a variable to store where, and how to create a storage variable.

 

Guess you like

Origin www.cnblogs.com/webcyh/p/11260785.html