0

In my system, an undefined pointer has a default value of 0x00000000.

void Demo()
{
    char cData;
    char *pExamplePtr;
    char pExampleArray[4];

    &cData <--- Address is 0x12345678
    pExamplePtr  <--- Value of pointer is 0x00000000
    pExampleArray[0] <--- Address is ???
}

What is the default address of pExampleArray? Is it 0x00000000 or does it have some valid address like cData?

user1172282
  • 527
  • 1
  • 9
  • 19

3 Answers3

2
  1. pExamplePtr is uninitialized, so it doesn't necessarily point to 0.

  2. pExampleArray is an array, not a pointer, so it doesn't "point" anywhere either. If you were to use pExampleArray in an expression, it would decay into a pointer to its first element - the equivalent of &pExampleArray[0].

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
2

The pointer pExamplePtr does indeed have a valid address. Maybe what you meant to say is that it is not pointing to anything and hence the 0x00000000 but that's not necessarily the case.

Also in regards with pExampleArray[4], this is an array, not a pointer and it does indeed have a vaild address as is the case with your first variable.

Florin Stingaciu
  • 8,085
  • 2
  • 24
  • 45
1

The address of pExampleArray object declared below:

char pExampleArray[4];

is &pExampleArray and it is a valid address.

The address of pExamplePtr object declared below:

char *pExamplePtr;

is &pExamplePtr and it is a valid address, different than NULL. You seem to confuse the pointer value, which is pExamplePtr and is indeterminate before initialization or assignment and the address of the pointer object.

ouah
  • 142,963
  • 15
  • 272
  • 331