
But by convention, if a pointer contains the null (zero) value, it is assumed to point to nothing. However, the memory address 0 has special significance it signals that the pointer is not intended to point to an accessible memory location. In most of the operating systems, programs are not permitted to access memory at address 0 because that memory is reserved by the operating system. Printf("The value of ptr is : %x\n", ptr )

The following example makes use of these operations − This is done by using unary operator * that returns the value of the variable located at the address specified by its operand. (a) We define a pointer variable, (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. There are a few important operations, which we will do with the help of pointers very frequently. The only difference between pointers of different data types is the data type of the variable or constant that the pointer points to. The actual data type of the value of all pointers, whether integer, float, character, or otherwise, is the same, a long hexadecimal number that represents a memory address. Take a look at some of the valid pointer declarations − However, in this statement the asterisk is being used to designate a variable as a pointer. The asterisk * used to declare a pointer is the same asterisk used for multiplication. Here, type is the pointer's base type it must be a valid C data type and var-name is the name of the pointer variable. The general form of a pointer variable declaration is −

Like any variable or constant, you must declare a pointer before using it to store any variable address. When the above code is compiled and executed, it produces the following result −Ī pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Printf("Address of var2 variable: %x\n", &var2 )

Printf("Address of var1 variable: %x\n", &var1 )
