问题描述
亲爱的,
哪个是正确的?
假设我们为100个字节分配内存,
int * PtrMemoryBlock =(int *)malloc(100);
如果我这样做
PtrMemoryBlock = PtrMemoryBlock + 10;
它会指向第10个字节的内存loaction,由
malloc分配的memro或它将指向10 + 100(Byte Allocated by malloc)
记忆力?
提前致谢
Ranjeet
两者都没有,
它指向内存(PtrMemoryBlock只是指向)第N个的确定
byte,
和,N = 10 * sizeof(int)。
pointer" PtrMemoryBlock"声明指向int类型,所以当
对指针添加10时,在* / b $ b事实中添加了10 * sizeof(int)。
Dear All,
Which is correct ?
Let suppose we allocate the memory for the 100 bytes,
int *PtrMemoryBlock = (int *)malloc(100);
If I do
PtrMemoryBlock = PtrMemoryBlock + 10;
will it point to memory loaction of 10th byte, memroy allocated by
malloc OR it will point to the 10 + 100 (Byte Allocated by malloc)
memory loaction ?
Thanks in advance
Ranjeet
No. It will point to the 10th int.
Richard
neither ,
it points to memory (PtrMemoryBlock just points to) loaction of Nth
byte,
and, N = 10 * sizeof(int).
pointer "PtrMemoryBlock" is declared to point to int type, so while
doing an addition of 10 to the pointer , 10 * sizeof(int) is added in
fact.
这篇关于指针增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!