Assigning NULL to a pointer, NULL pointer that point to no object in C programming

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info:

To do: Assigning NULL to a pointer, generating NULL pointer in C program

To show: How to use pointer's format specifier demonstrated using the NULL pointer in C program

 

 

// Using pointer's format specifier

#include <stdio.h>

 

int main(void)

{

int *thepointer;

 

// NULL pointer should be assigned to any pointer where the pointer have nothing to point to yet

thepointer = NULL;

 

// do some testing....

printf("The thepointer pointer is pointing to = %0X\n", thepointer);

// Should use this one...

printf("The thepointer pointer is pointing to = %p\n", thepointer);

printf("The thepointer pointer is pointing to = %d\n", thepointer);

return 0;

}

 

Output example:

 

The thepointer pointer is pointing to = 0

The thepointer pointer is pointing to = 00000000

The thepointer pointer is pointing to = 0

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index