Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C-Pointers

askembcaskembc Member Posts: 2
HI

IAm new to C

I have a basic doubt. please clarify

int* iptr = NULL;

is the way os declaring a pointer .

Will the pointer point to Address 0 in memory ?

If so what adrees 0 will contain ?

Thanks



Comments

  • LundinLundin Member Posts: 3,711
    NULL can either be defined as 0, or as (void*)0. The latter is a typecast from an integer to a pointer. In both cases it will indeed point at address 0.

    The C standard states that address NULL is not allowed to point at a valid object or function. Yet, some hardware has registers at address 0, which makes NULL problematic in embedded systems.

    One must therefore be extra careful and check that no null pointer access in done anywhere in the code. On a PC program, this will just crash the program. On an embedded system, it could lead to complete disaster.

    This is a serious flaw of most embedded CPUs. All manufacturers proudly claim that their new microcontrollers are adapted to suit the C language, yet they put registers at address 0. Maybe they will realize how dangerous this is at some point. Give them more time, C has only been around for 30 years...
Sign In or Register to comment.