原:
void func(char string[100])
{
char str[]="Hello";
int n = 10;
char *p = str;
void *p1 = malloc(100);
printf("sizeof(str) = %d, sizeof(n) = %d, sizeof(p) = %d, sizeof(p1) = %d, sizeof(string) = %d",
sizeof(str),
sizeof(n),
sizeof(p),
sizeof(p1),
sizeof(string));
)
}
#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
char string[100];
char str[]="Hello";
int n = 10;
char *p = str;
void *p1 = malloc(100);
printf("sizeof(str) = %d, sizeof(n) = %d, sizeof(p) = %d, sizeof(p1) = %d, sizeof(string) = %d",
sizeof(str),
sizeof(n),
sizeof(p),
sizeof(p1),
sizeof(string));
return 0;
}
结果为:

#include <iostream>
using namespace std;
#include <stdio.h>
void func(char string[100])
{
char str[]="Hello";
int n = 10;
char *p = str;
void *p1 = malloc(100);
printf("sizeof(str) = %d, sizeof(n) = %d, sizeof(p) = %d, sizeof(p1) = %d, sizeof(string) = %d",
sizeof(str),
sizeof(n),
sizeof(p),
sizeof(p1),
sizeof(string));
}
int main()
{
char string[100] = "1001fvgfs";
func(string);
return 0;
}

本文深入探讨了使用C语言进行编程时,不同数据类型及指针变量在内存中所占空间大小的问题。通过实例演示了如何利用sizeof运算符来测量字符串、整型变量、字符指针和空指针的大小,帮助读者理解内存分配机制。
902

被折叠的 条评论
为什么被折叠?



