You are on page 1of 1

Pointer Arithmetics

POINTER ARITHMETIC DESCRIPTION ptr++ ptr=ptr+sizeof(data_type) use original value of ptr and then ptr is incremented after statement execution. ptr = ptr+sizeof( data_type ) original ptr is incremented before execution of statement. ptr=ptr-sizeof(data_type) use original value of ptr and then ptr is decremented after statement execution. ptr = ptr-sizeof( data_type ) original ptr is decremented before execution of statement. *(ptr++) retrieve the content of the location pointed to by pointer then increment ptr. * (++ptr) increment pointer and then retrieve the content of the location pointed to by ptr. increment the content of the location pointed to by ptr. For pointer type content, use pointer arithmetic else use standard arithmetic. ++ (*ptr) increment the content of the location pointed to by ptr depending on the type of the content. -- (*ptr) decrement the content of the location pointed to by ptr depending on the type of the content. *(ptr--) retrieve the content of the location pointed to by ptr and then decrement pointer * (--ptr) decrement ptr, then retrieve the content of the new location pointed to by ptr. retrieve content *ptr of the location pointed to by ptr, then decrement the content of the location; ptr is not changed.

++ptr

ptr--

--ptr

*ptr++

* ++ptr

(*ptr)++

++ *ptr

-- *ptr

*ptr --

* --ptr

(*ptr)--

You might also like