• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
火磷
Memory will fade,but not notes.
博客园    首页    新随笔    联系   管理    订阅  订阅
指针与地址
 1 #include <iostream>
 2 using namespace std;
 3 int main() {
 4     char s1[] = "Hello World";      //字母10位,空格1位,结尾'\0'占一位
 5     char *s2 = "Hello World";      //一个指针占4位
 6     cout << "size of s1: " << sizeof(s1) << endl;       //12
 7     cout << "size of *s1: " << sizeof(*s1) << endl;    //*s1='H',长度为1
 8     cout << "size of &s1: " << sizeof(&s1) << endl;    //4
 9     cout << "size of s2: " << sizeof(s2) << endl;      //4
10     cout << "size of *s2: " << sizeof(*s2) << endl;     //1
11     cout << "size of &s2: " << sizeof(&s2) << endl;     //4
12 }
posted on 2015-11-04 20:49  火磷  阅读(231)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3