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. Android 技术用于汇总

    id 名词 含义 详细  1 Android CTS     CTS 全称 Compatibility Test Suite 兼容性测试工具 当产品开发出来以后,并定制了自己的 Android 系统后 ...

  2. Window 8.1 计时器功能及图片切换

    <Canvas Margin="450,0" Width="795" Grid.Column="1"> <Image Ma ...

  3. WCF 服务与终结点(四)

    服务 服务是一组公开功能的集合. 服务内部包含了如语言.技术.版本与框架等概念,服务之间的交互只允许使用规定的通信模式 外界客户端并不知道服务内部的实现细节,所以WCF服务通常通过元数据的方式描述可用 ...

  4. php读取图片内容并输出到浏览器的实现代码

    如果php以图片,zip,exe等文件输出到浏览器,而前面还输出了其他字符,就会有乱码. 代码很简单,网上都能找到,但在我机子上就是显示不出来,显示出的一直是这个php文件路径,费了点时间才搞定,原来 ...

  5. 解决前端浏览器传JSON对像到服务端后全部变成string类型的方法

    这几天公司用nodejs+mongodb来做些东西,UI用的是kendo UI 碰到一个问题: 举个例子var a={"name":"张三","age ...

  6. hdu 5690 2016"百度之星" - 初赛(Astar Round2A) All X 快速二次幂 || 寻找周期

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5690 题意:m个数字全为x mod k ?= c;其中m <= 1010,0 < c,k ...

  7. 第六周 E题 期望.....

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  8. [原创]PostgreSQL Plus Advince Server在 HA环境中一对多的Stream Replication配置(三)

    五.准备HA环境1.准备yum源a.安装vsftp服务,将光盘镜像copy到本地ftp目录作为yum源.[root@s1 ~]# mount 可以看到cdrom已经挂载了,首先安装vsftp服务[ro ...

  9. boost安装

    虽然很多Boost组件都只有头文件,不需要编译,但是有些Boost组件,如program_options.regex等还是需要编译生成库的.考虑到目前的程序需要用到program_options.re ...

  10. Ubuntu14.04下中山大学锐捷上网设置

    Ubuntu14.04下中山大学锐捷上网设置 打开终端后的初始目录是 -,Ubuntu安装完毕默认路径,不是的请自行先运行cd ~ 非斜体字命令行方法,斜体字是图形管理方法,二选一即可 记得善用Tab ...