C++ sizeof

来源:互联网 发布:思快奇软件下载 编辑:程序博客网 时间:2024/06/05 00:59
#include <iostream>using namespace std;void f(char str[]) {    cout << sizeof(str)<<endl;}// error C2084: 函数“void f(char [])”已有主体void f(char str[100]) {    cout << sizeof(str) << endl;}int main(){    char str[] = "http://www.bilibili.com/";    char* p = str;    int n = 10;    cout << sizeof(str)<<endl;    cout << sizeof(p) << endl;    cout << sizeof(n) << endl;    char s[100];    cout << sizeof(s) << endl;    f(str);    f(s);    void *tp = malloc(100);    cout << sizeof(tp) << endl;    return 0;}

x86输出:
25
4
4
100
4
4
4
x64输出:
25
8
4
100
8
8
8

原创粉丝点击