数组初始化有问题
数组初始化总是失败,正常应当每个数都初始化为0,但是还是会掺杂其他的数,是哪里出了问题?急,在线等大佬!代码如下:
----------------------------
#include <stdio.h>
#include <stdlib.h>
#define MaxSize 20
typedef struct
{
int data;
int length;
}SqList;
void InitList(SqList &L)
{
for (int i = 0; i <= L.length; i++)
{
L.data = 0;
}
L.length = 15;
}
int main(void)
{
SqList A;
InitList(A);
SqList B;
InitList(B);
for (int i = 0; i < A.length; i++)
{
printf("data[%d] = %d\n", i, A.data);
}
printf("----------------------------------\n");
for (int i = 0; i < B.length; i++)
{
printf("data[%d] = %d\n", i, B.data);
}
}
-----------------------------------------------------------------
for (int i = 0; i <= L.length; i++)这里的L.length长度未知啊
页:
[1]