相关疑难解决方法(0)

sizeof与string的行为

?#?include? <stdio.h>
#include <string.h>
int main()
{
    printf("%d\n",sizeof("S\065AB"));
    printf("%d\n",sizeof("S65AB"));
    printf("%d\n",sizeof("S\065\0AB"));
    printf("%d\n",sizeof("S\06\05\0AB"));
    printf("%d\n",sizeof("S6\05AB"));
    printf("%d\n",sizeof("\0S65AB"));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

5
6
6
7
6
7
Run Code Online (Sandbox Code Playgroud)

http://ideone.com/kw23IV

任何人都可以用字符串解释这种行为吗?

在Debian 7.4上使用GCC

c string sizeof

4
推荐指数
1
解决办法
207
查看次数

标签 统计

c ×1

sizeof ×1

string ×1