sizeof()

来源:互联网 发布:上海心动网络 校招 编辑:程序博客网 时间:2024/06/13 07:45

这里写图片描述

#include <iostream>#include <string>using namespace std;int main(){   char* str = "Hello";   char str1[] = "hello";   int data[] = {1,2};   cout << sizeof(str)<<endl;   cout << sizeof(str1)<<endl;   cout << sizeof(data);    return 0;}

str 指向文字常量区,内容不可修改。
sizeof(str)为指针大小,sizeof(str1)为占用内存大小,sizeof(data)为占用内存大小。

0 0