C++ Variables and Basic Types Notes
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的更多相关文章
- [C++] Variables and Basic Types
Getting Started compile C++ program source $ g++ -o prog grog1.cc run C++ program $ ./prog The libra ...
- C++Primer 5th Chap2 Variables and basic Types
wchar_t,char16_t,char32_t用于拓展字符集 char和signed char并不一样,由编译器决定类型char表现上述两种中的哪一种 一般long的大小和int无二,如果超过in ...
- TypeScript学习指南第一章--基础数据类型(Basic Types)
基础数据类型(Basic Types) 为了搭建应用程序,我们需要使用一些基础数据类型比如:numbers,strings,structures,boolean等等. 在TypeScript中除了Ja ...
- A Tour of Go Basic types
Go's basic types are bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr ...
- 编译器重复定义错误:error C2371: 'SIZE' : redefinition; different basic types
我们常常会定义自己工程用的数据类型,可能会与Windows的基本数据类型冲突. vs会报重复定义错误:error C2371: 'SIZE' : redefinition; different bas ...
- QML学习【一】Basic Types
QML入门教程(1) QML是什么? QML是一种描述性的脚本语言,文件格式以.qml结尾.语法格式非常像CSS(参考后文具体例子),但又支持javacript形式的编程控制.它结合了QtDesi ...
- [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 ...
- Kotlin Reference (四) Basic Types
most from reference 基本类型 在kotlin中,一切都是对象,我们可以在任何变量上调用成员函数和属性.一些类型可以具有特殊的内部表示:例如,数字.字符和布尔值都可以在运行时被表示为 ...
- Go xmas2020 学习笔记 00-03、Basic Types
00-02-Hello Example. 目录结构. 不一样的Hello World. 巧妙的单元测试. 传入os.Args切片. go mod init. 03-Basic Types. 变量类型与 ...
随机推荐
- ZigBee profile
每个ZigBee设备都与一个特定模板相关联,可能是公共模板或私有模板.这些模板定义了设备的应用环境.设备类型以及用于设备间通信的簇.采用公共模板,可以确保不同供应商的设备在相同应用领域的互操作 ...
- VC6.0编译boost
今天学习了下VC6.0下boost的编译,只是对regex进行了编译,据说全部编译需要2个多小时,在此记录下学习过程中遇到的问题以便今后查看. 最开始直接从网上(www.boost.org)下载了当前 ...
- MySQL 密码增强插件
200 ? "200px" : this.width)!important;} --> 介绍 以前没有太注意MySQL密码安全策略的配置方法,只是人为了将密码设为复杂密码,但 ...
- 三角函数计算,Cordic 算法入门
[-] 三角函数计算Cordic 算法入门 从二分查找法说起 减少乘法运算 消除乘法运算 三角函数计算,Cordic 算法入门 三角函数的计算是个复杂的主题,有计算机之前,人们通常通过查找三角函数表来 ...
- WebApp遇到的一些坑
一.关于js 1. 引用zepto.js时,借用插件swipe时,写的滑动加载,在ios上可以实行滑动加载数据,但是在安卓上,就是不能滑动: 注: 在使用插件的时候,要先注意其兼容性问题. 2. 用j ...
- AngularJS(14)-动画
AngularJS 提供了动画效果,可以配合 CSS 使用. AngularJS 使用动画需要引入 angular-animate.min.js 库. <!DOCTYPE html> &l ...
- hadoop架构
HADOOP中可以分为两个大的模块,存储模块和计算模块.HDFS作为存储模块,JobTracker,TaskTracker构成计算模块. 1.HADOOP的文件是以HDFS格式存储的 HDFS ...
- 用MySQL log调试程序
打开my.ini文件 在[mysqld]的下面加上log = c:/mysql_query.log.txt重启mysql 以后你用可以用editplus查看你运行的sql了,不用在程序里一句句的用lo ...
- java web 路径 --转载
主题:java(Web)中相对路径,绝对路径问题总结 1.基本概念的理解 绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:C:\xyz\test.txt 代表 ...
- 关于JS异步加载方案
javascript延迟加载的解决方案: 1.使用defer标签 <span style="font-size: small;"><script type=&qu ...