当前位置:网站首页>sizeof判断数组大小
sizeof判断数组大小
2022-07-21 15:11:00 【小飞将】
int main()
{
const char *collectionA[] = {
"adef5444" }; // 4
const char *collectionB[] = {
"adef5444", "CDE" }; // 8
const char *str = "abc"; // 4
cout << sizeof(collectionA) << endl;
cout << sizeof(collectionB) << endl;
cout << sizeof(str) << endl;
return 0;
}
使用sizeof运算符是可以获取数组的大小的,但是记得当sizeof作用于指针时,大小是4。
第一个数组之所以size是4,只是因为collectionA中存放的其实不是adef5444
,而是一个const char *指针,指向adef5444
而已。collectionB中存放了两根指针,所以大小是8。
边栏推荐
猜你喜欢
随机推荐
Matlab GUI编程技巧(七):matlablistbox操作-列表框(ListBox)和uilistbox常用操作
ps小白從0開始……
VLOOKUP函数
Foundation of Mathematics: Lagrangian optimization and duality
When running, the object moves, rotates and scales the plug-in, "runtimetransformgizmos plug-in" tutorial (unity3d)
JMeter Association (II)
Love running every day [noip2016 T4]
EventLoop事件循环机制
application.yml 和 application.propertise 配置不生效
FileNotFoundError: [Errno 2] No such file or directory: ‘cmake‘
2019Q1全球智能手机出货量:华为vivo大幅增长,苹果暴跌30.2%!
flask - { “message“: “Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)“ }
Codeforces Round #690 (Div. 3) B. Last Year‘s Substring 常规解法
自定义类加载器实现
Codeforces Round #693 (Div. 3) C. Long Jumps 题解
ENVI shp转roi并对栅格进行掩膜提取
application. YML and application Property configuration does not take effect
Swagger interface importing postman
Matlab写入excel-字符串与数字合并
Codeforces Round #690 (Div. 3) C. Unique Number 常规解法