数组下标越界引起的问题
一个程序中有指针数据,有数组。
指针初始化后,系统应该分配内存空间。
紧接着初始化数组,但在此时数组初始化时越界,但越界之前分配的内存空间应该是合法的。问题在此时出现了:当越界现象出现时,原来分配的数据段的结构在内存中会不会变化?
指针初始化后,系统应该分配内存空间。
紧接着初始化数组,但在此时数组初始化时越界,但越界之前分配的内存空间应该是合法的。问题在此时出现了:当越界现象出现时,原来分配的数据段的结构在内存中会不会变化?
#include"stdio.h"
#include"stdlib.h"
#define NULL 0
#define N 1
typedef struct _node{
int page;
int flag;
int mem;
int state;
int ci;
char m;
struct _node* next;
}node;
typedef struct _copy{
int pae;
int block;
char n;
struct _copy* next;
}copy;
void show(node* h)
{node *p;
p=h->next;
puts("页号:\n");
printf("%d",p);
while(p)
{printf("%d\n",p->page);
p=p->next;
}
}
void main()
{
int i,n;
node* head;
head=(node*)malloc(sizeof(node));
head->next = NULL;
node *p;
p=(node*)malloc(sizeof(node));
p->page=2;
p->flag=1;
p->mem=1;
p->state=0;
p->ci=0;
p->m=97;
p->next=head->next;
head->next = p;
for(i=0;i<9;i++)
{
end[i].n=97+i;end[i].block=i;//注意当 i = 8 时数组下标越界
end[i].pae=i;
}
show(head);
}
程序是一哥们写的,问题的出现太突然以至于本菜鸟小弟来不及接受。在这里恳请各位大侠慷慨拔刀相助!分会有的!
...全文
相关推荐
PHP程序设计-3期(KC016) 2.7.1索引数组-常见问题.docx
PHP程序设计-3期(KC016) 2.7.1索引数组-常见问题.docx 学习资料 复习资料 教学资源
c语言越界问题(字符串,数组下标)
1,字符串操作越界: void test_char() { char a[] = {'a','s','d','e'}; printf("strlen(a) = %d\n",strlen(a));//strlen 遇到'\0'结束,a没有结束符,此时可能出现越界一般用sizeof而不用strlen } 我们开始看这个例子的时候会不觉得越界,但是仔细想来,strlen 是求解字符串的长度,但是strlen的长度是以‘\0’为结束符之前的字符字数,所以在上面的例子中没有看看a字符串的结束符,所以我们需要
jiancha.rar_数组 越界 检查
设计一个用于检查数组在使用时下标是否越界的类,如越界给出提示。(知识点:下标运算符的重载)。
java 数组下标越界异常(ArrayIndexOutOfBoundsException)
java 数组下标越界异常(ArrayIndexOutOfBoundsException) java 数组下标越界异常(ArrayIndexOutOfBoundsException)
内存越界的可能情况分析,C语言内存越界详解.pdf
。。。


