The constants C ++

constant

** ** effect: a program for recording data in an unalterable

C ++ constants defined in two ways

1. ** \ # define ** macro constants: #define constant value Constant Name
* == == defined above the usual in the file represents a constant


2. ** const ** modified variable   const data type constant name = constant value
* == == const keywords is often added before the variable definition, the variable is modified constant, can not be modified

 

 

 

#include <the iostream> 
the using namespace STD; 

// constants defined manner 
// 1, #define macro constants 
// 2, const modified variable 

// 1, #define macro constants 
#define. 7 Day 

int main () { 
	
	// day = 14; day is constant, the error will be modified once 
	cout << "one week a total of:" << day << "day" << endl; 

	// 2, const modified variable 
	const int month the = 12; 
	cout < < "year total:" << month << "month" << endl; 
	System ( "PAUSE"); 

	return 0; 
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/RevelationTruth/p/11852117.html