T000ny

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
sizeof考虑“\0”,strlen不考虑“\0”
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(){
    enum m{a,b,c,d,e,f,g,h,i,j,k,l};
    cout << sizeof(m) <<endl;//4             枚举类型类似于指针
    cout << sizeof("\0\0\0") <<endl;//4      3个\0 + 末尾的\0 = 4
    cout << sizeof("\01234") <<endl;//4      \012被认为是8进制所以是一个字符 + (3) + (4) + (\0) = 4
    cout << strlen("\0") << endl;//0      
    char str[]="ab\n\012\\\"";  //              a,b,\n,\012,\\,\",\0 = 7
    cout << sizeof(str) << endl;//7
    cout << sizeof("\x12345656777777");//2这里的\x后面的4个数被认为是16进制,后面的被认为是16进制越界了。不做处理
    return 0;
}

 

posted on 2013-05-04 22:35  T000ny  阅读(231)  评论(0编辑  收藏  举报