2.2-void
来源:互联网 发布:首次统计网络零售额 编辑:程序博客网 时间:2024/06/04 03:32
void是最易于解释的数据类型,因为void的意思就是“无类型”,因此,void类型不能用来定义变量。
void value; // 错误
void通常用于以下几种情形中:
(1)也是最常用的,表示函数不返回任何值。
void writeValue(int x){ std::cout << "The value of x is: " << x << std::endl; // 无返回语句,因为返回值类型为void}
(2)在C中,用于表示函数不接受任何参数。
int getValue(void) // void 表示无参数{ int x; std::cin >> x; return x;}
注意使用void表示无参数是C中的编程习惯,在C++中应当优先采用如下形式,它与上述代码是等价的:
int getValue(){ int x; std::cin >> x; return x;}
注:C++应采用空参数表代替void表示不接受参数
(3)在C++中,void关键字还有第三种用途,我们会在空指针一节中讲到,因为我们还没有涉及到指针,所以此处知道即可。
0 0
- 2.2-void
- void *
- void
- void
- void
- void
- void
- void*
- void
- void
- void
- void
- void
- void
- void
- (void**)&
- void *
- void
- 【从零单排leetcode】11. Container With Most Water
- nginx系列(八)nginx失效转移与超时处理
- agnus
- 使用pandas读写Excel文件
- Android 官方Sample
- 2.2-void
- android手机的Mic对声音的感知
- 【bzoj3894】文理分科 最小割
- Activity全解(一)
- jdbc
- 微信小程序学习
- arcgis api for js入门开发系列六地图分屏对比(含源代码)
- 2.3-变量的大小与sizeof操作符
- Spring Security初体验