转帖地址: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) 6sizeof(&str) 6sizeof(p1) 4p1显示x 12ff78&p1显示x 12ff74str显示x 12ff78str显示s hello&str显示x 12ff78ch显示c kch显示x 6b&ch显示x 12ff70
sizeof(&p1) 4sizeof(n) 4sizeof(&n) 4
n的显示x a&n的显示x 12ff6csizeof(p2) 4
Func sizeof(s) 4Func sizeof(&s) 4请按任意键继续. . .