上午, 我希望有人在这里 假设我有以下的结构,甚至更好结构的数组的组成员为零
for (counter = 0; counter < 10; ++counter)
memset(bar[counter],0,sizeof(char)*10);
struct foo {
int a;
char b[10];
char c;
};
struct foo* bar;
bar = (struct foo*) malloc(sizeof(struct foo)*10);
memset(bar, -1, sizeof(struct foo)*10);
,而不是如何将在所有数组中的所有char/b成员数组中将b成员设置为0?
基本上我的问题是类似于this一个
'sizeof(char)* 8'?为什么? '8'从哪里来? – AnT
对不起,是的,这只是我的错误 –
你似乎正在用C编写代码。让你的生活更轻松,并使用C++,例如'std :: vector'。那么你将不必玩任何'malloc'和'memset' shenanigans。 –
juanchopanza