1. Type conversion:

If we assign an out-of-range value to an object of unsigned type, the result is the remainder of the value modulo the number of values the target type can hold.

If we assign an out-of-range value to an object of signed type, the result is undefined.

2.What does a variable mean?

A variable provides us a named storage that our program can manipulate.

3.Variable initialization and assignment

Initialization happens when a variable is given a value when it is created, whereas assignment is to replace the old value of the variable with new value.

4.Variable declaration and definition

To support seperate compilation, C++ distinguishes declaration and definition. A declaration makes a name known to the program, especially when a program wants to use a variable that is defined in other file. The definition creates the associated entity.

To get a declaration that is not a definition, we can add the 'extern' word before variable and not provide an initial value.

P.S. Variable must be defined exactly once but can be declared many times.

5. Reference and pointer

Reference defines an alternative name for an object. A reference must be initialized. And once initialized, a reference remains bound to its initial object. There is no way to rebind a reference to a different object.

Pointer is a type that stores the address of an object. Unlike reference, a pointer needn't to  be initialized when it's created. And a pointer can point to differnent object in its lifetime.

P.S. Reference is not an object. Hence, we may not have a pointer to a reference. Also, there is 'const pointer' but no 'const reference'.

6. void * pointer

The type void * is a special pointer type that can hold address of any type of object.

7. Const

We can make a variable unchangeable by defining the variable's type as const. Because we can't change the value of a const object after we create it, so we need to initialize it when creting it.

P.S. To share a const object across multiple files, you must define the variable as extern.

Const pointer: we indicate the pointer is const by putting the 'const' after '*'.

8. Auto type specifier

Under the new standard, we can let the compiler to figure out the type of an expression by using the auto type specifier. The variable using auto as its type specifier must have its initializer.

In particular, when we use the reference as the initializer, the initializer is the corresponding object. Second, auto ordinarily ignores top-level const.

9. Decltype type specifier

Sometimes we want to define a variable with the type that the compiler deduces from an expression but not want to use the expression to initialize the variable. For such case, the new standard introduce the 'decltype' specifier, which returns the type of its operand.

C++ Variables and Basic Types Notes的更多相关文章

  1. [C++] Variables and Basic Types

    Getting Started compile C++ program source $ g++ -o prog grog1.cc run C++ program $ ./prog The libra ...

  2. C++Primer 5th Chap2 Variables and basic Types

    wchar_t,char16_t,char32_t用于拓展字符集 char和signed char并不一样,由编译器决定类型char表现上述两种中的哪一种 一般long的大小和int无二,如果超过in ...

  3. TypeScript学习指南第一章--基础数据类型(Basic Types)

    基础数据类型(Basic Types) 为了搭建应用程序,我们需要使用一些基础数据类型比如:numbers,strings,structures,boolean等等. 在TypeScript中除了Ja ...

  4. A Tour of Go Basic types

    Go's basic types are bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr ...

  5. 编译器重复定义错误:error C2371: 'SIZE' : redefinition; different basic types

    我们常常会定义自己工程用的数据类型,可能会与Windows的基本数据类型冲突. vs会报重复定义错误:error C2371: 'SIZE' : redefinition; different bas ...

  6. QML学习【一】Basic Types

      QML入门教程(1) QML是什么? QML是一种描述性的脚本语言,文件格式以.qml结尾.语法格式非常像CSS(参考后文具体例子),但又支持javacript形式的编程控制.它结合了QtDesi ...

  7. [GraphQL] Use GraphQL's Object Type for Basic Types

    We can create the most basic components of our GraphQL Schema using GraphQL's Object Types. These ty ...

  8. Kotlin Reference (四) Basic Types

    most from reference 基本类型 在kotlin中,一切都是对象,我们可以在任何变量上调用成员函数和属性.一些类型可以具有特殊的内部表示:例如,数字.字符和布尔值都可以在运行时被表示为 ...

  9. Go xmas2020 学习笔记 00-03、Basic Types

    00-02-Hello Example. 目录结构. 不一样的Hello World. 巧妙的单元测试. 传入os.Args切片. go mod init. 03-Basic Types. 变量类型与 ...

随机推荐

  1. iPhone的全球之旅 读书笔记

          最近在看<一只iPhone的全球之旅>,文章主要从iPhone供应链角度入手,从各个方面来详细剖析了iPhone这一智能手机领头羊的生产过程.       苹果iPhone手机 ...

  2. VS2010使用TeeChart5的ColorGrid绘制一维距离像

    绘制一维距离像原理:使用TeeChart控件中的ColorGrid显示(X,Y,Z)三维数据,X和Z分别代表一维距离像的x轴和y轴数据,Y代表对应的数值,以不同颜色显示. 1.注册TeeChart5 ...

  3. PHP学习之数组的定义和填充

    数组就是把一组数据按顺序放在一起.PHP的数组和其它的语言数组有一点点不同:第一,保存的数据是可以是任何类型的:第二,数组的索引可以是数字,也可以是字符串. PHP的数组,说白了,就是关联数据每一条数 ...

  4. Azure Bill

    MSDN的本月订阅的被用完了,所有的付费订阅均变成了不可用的状态. 信用额度为0元,还有2天能恢复 点击上方的MSDN订阅名会进入更加详细的账单,账单以月的形式提供. 邮件中也会通知您到了限定额度所停 ...

  5. Hadoop管理员的十个最佳实践(转)

    前言 接触Hadoop有两年的时间了,期间遇到很多的问题,既有经典的NameNode和JobTracker内存溢出故障,也有HDFS存储小文件问题,既有任务调度问题,也有MapReduce性能问题.遇 ...

  6. 提高SQL语句的性能

    一.FROM子句中的表 FROM子表的安排或次序对性能有很大的影响,把较小的表放在前面,把较大的表放在后面,可以得到更高的效率. 二.WHERE子句中的次序 一般来自基表的字段放在结合操作的右侧,要被 ...

  7. 【http】http/1.1 八种请求方式

    OPTIONS 返回服务器针对特定资源所支持的HTTP请求方法.也可以利用向Web服务器发送'*'的请求来测试服务器的功能性. HEAD 向服务器索要与GET请求相一致的响应,只不过响应体将不会被返回 ...

  8. EditorWindow 和MenuItem

    using UnityEngine; using System.Collections; using UnityEditor; public class ClipEventEditor : Edito ...

  9. 【原创】jQuery插件 - Booklet翻书特效教程(一) 一般设置

    jQuery插件 - Booklet翻书特效教程(一) 一般设置 本文由五月雨恋提供,转载请注明出处. 一.宽高(width/height) 1.自定义大小 $(function(){ // 自定义页 ...

  10. cocos2dx中创建标签CCLabel的三种方法及特点

    创建标签的三种方式:1.CCLabelTTF     (True Type Font,又叫本地字体)这是最简单,也是最常用的方式,不依赖于资源文件,也不依赖于某个系统,所指定的字体如果系统没有,则会提 ...