i have this question in mind since i first found out that you can declare and array like this

<type>* nArray

how does the compiler how much storage to allocate?
i've heard that it doesn't allocate any storage, it just points to some address and when you use index operator like this


it just returns the object n addresses far from the pointer.
if that's so, how does the compiler handle new(exact type of the array) variables declaration without risking an overriding of the memory:

int* nArray; // lets assume that it points to address 0x00000000
int nInt; // has the address of 0x00000004?
// that would mean like nArray + 1 points to nInt witch doesn't seem to be right

Edited by dospy: n/a

5 Years
Discussion Span
Last Post by dospy

Pointers that are not set to NULL or a valid memory address are said to be wild pointers, they may be pointing at anything so are very dangerous.

The general rule is - Set a pointer to a valid memory address or set it to NULL...Always keep your pointers in a known state.

Edited by gerard4143: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.