就我对语言的理解而言,缓冲区是内存的任何部分,其中数据存储就像int,float变量,字符数组等.但是,我正在阅读缓冲区溢出并在阅读堆栈http时遇到此链接://www.tenouk.com/Bufferoverflowc/Bufferoverflow2a.html 此链接中的图表将缓冲区与函数的局部变量分开.它是否正确?什么是缓冲呢?
我正在从一本书中学习排队.作者解释了使用以下代码在队列中插入元素的操作.
#define MAX 100
char *p[MAX];
int spos = 0; // spos: holds the index of the **next free** storage location
int rpos = 0;// rpos: holds the index of the next item to retrieve
void qstore(char *q)
{
if(spos==MAX) {
printf("List Full\n");
return;
}
p[spos] = q;
spos++;
}
Run Code Online (Sandbox Code Playgroud)
因此,根据上面的代码,如果spos = 100,即队列中的最后一个元素,则队列已满.现在,由于spos保存下一个空闲存储位置的索引,因此当spos = 100时,数组中的最后一个位置为空.那么为什么它被解释为List full?不应修改此代码,以便它允许填充数组中的最后一个位置,或者我错过了一些非常明显的东西?
谢谢.