转帖地址:http://hi.baidu.com/hikeba/blog/item/68ad9f10a7dd8003213f2ecf.html
char str[]="hello";
char *p1=str;
int n=10;
sizeof(str)=?
sizeof(str)=?
sizeof(str)=?
void Func(char s[100])
{
sizeof(s)=?
}
void *p2=malloc(100);
sizeof(p)=?
///
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
void Func(char s[100]) ;
int main(void)
{
char str[]="hello";
char *p1=str;
char ch='k';
int n=10;
void *p2=malloc(100);
printf("sizeof(str) %d/n",sizeof(str));
printf("sizeof(&str) %d/n",sizeof(&str));
printf("sizeof(p1) %d/n",sizeof(p1));
printf("p1显示x %x/n",p1);
printf("&p1显示x %x/n",&p1);
printf("str显示x %x/n",str);
printf("str显示s %s/n",str);
printf("&str显示x %x/n",&str);
printf("ch显示c %c/n",ch);
printf("ch显示x %x/n",ch);
printf("&ch显示x %x/n/n",&ch);
printf("sizeof(&p1) %d/n",sizeof(&p1));
printf("sizeof(n) %d/n",sizeof(n));
printf("sizeof(&n) %d/n/n",sizeof(&n));
printf("n的显示x %x/n",n);
printf("&n的显示x %x/n",&n);
printf("sizeof(p2) %x/n/n",sizeof(p2));
Func(str);
system("pause");
return 0;
}
void Func(char s[100])
{
// s[100]="hike";
printf("Func sizeof(s) %d/n",sizeof(s));
printf("Func sizeof(&s) %d/n",sizeof(&s));
}
结果:
sizeof(str) 6
sizeof(&str) 6
sizeof(p1) 4
p1显示x 12ff78
&p1显示x 12ff74
str显示x 12ff78
str显示s hello
&str显示x 12ff78
ch显示c k
ch显示x 6b
&ch显示x 12ff70
sizeof(&p1) 4
sizeof(n) 4
sizeof(&n) 4
n的显示x a
&n的显示x 12ff6c
sizeof(p2) 4
Func sizeof(s) 4
Func sizeof(&s) 4
请按任意键继续. . .
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)