[root@localhost smb1]# cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void func(char str[100])
{
printf("func:%d\n",sizeof(str));
}
int main(int arc, char ** argv)
{
char str[]="hello";
char *p=str;
int n = 10;
char test[100]="xxxxyyyy11112222";
func(test);
printf("main,*p:%d\n",sizeof(p));
printf("main,n:%d\n",sizeof(n));
printf("main,sizeof:%d\n",sizeof(str));
printf("main,strlen:%d\n",strlen(str));
return 0;
}
[root@localhost smb1]# gcc -o main main.c
[root@localhost smb1]# ./main
func:8
main,*p:8
main,n:4
main,sizeof:6
main,strlen:5
[root@localhost smb1]# uname -a
Linux localhost.localdomain 4.3.0-rc1+ #2 SMP Sat Feb 13 21:55:55 CST 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost smb1]#
c中的一些变量大小
最新推荐文章于 2022-12-25 22:16:25 发布