codecamp

C++ 变量

学习C++ - C++变量

一个变量是你定义的一个命名的内存块。

每个变量仅存储特定类型的数据。

每个变量都有一个类型来定义它可以存储的数据类型。

每个基本类型都是一个唯一的类型名称,它是一个关键字。

关键字是C ++中的保留字。

变量名称

你必须遵循一些简单的C++命名规则:

您可以在名称中使用的唯一字符是字母字符,数字数字和下划线(_)字符。

名称中的第一个字符不能是数字数字。

大写字符被认为与小写字符不同。

您不能将C ++关键字用于名称。

以下是一些有效和无效的C ++名称:

int myvalue;    // valid 
int MyValue;    // valid and distinct
int MYVALUE;    // valid and even more distinct 
Int three;      // invalid -- has to be int, not Int 
int my_value3   // valid 
int _Myvalue3;  // valid but reserved -- starts with underscore 

要从两个或多个单词中形成一个名称,通常的做法是用my_onions中的下划线字符分隔单词,或者将第一个单词的初始字符大写为myEyeColor。


const限定符

C++使用const关键字来声明常量值。

const int Months = 12;  // Months is symbolic constant for 12 

创建常量的一般形式是:

const type name = value;

注意,在声明中初始化一个const。

C++ 语句
C++ 整数类型
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }