Pointers -Part 2

Palani
3 min readOct 23, 2021

Hello all, This is part 2 of the Pointers in C. If you came here directly go back and learn about the brief introduction about pointers. After reading that it will be more efficient. Lets get into it

  • Pointers with different Datatypes
  • Typecasting Array to pointers Datatype

Pointers with different Datatypes:

Lets see whats gonna happen when we compile our code

The compiler done a great job. It encounters our error it display the incomplete datatypes LOL :), But the Compiler and Developer knows the incorrect pointer datatype. In compiled code it consider a pointer as a memory address lets go ahead and jump into by running the compiled code.

The above outputs the value stored in the memory address respectively. This means that adding 1 to the pointer will increment the address by 4 each time. Similarly, the char_pointer’s address is only incremented by 1 each time.The 4-byte value of 0x00000001 is actually stored in memory as 0x01, 0x00, 0x00, 0x00.

Typecasting Array to pointers Datatype:

In the above snippet the int_array is typecasted with character (Pointer Datatype) and the int_pointer respectively. If we allow to compile the code it will leads to error in incorrect datatypes by compiler. To rectify this +1 is added with pointer to cast the correct datatype. so the address is incremented by correct amount.

Thats all for this blog. Hope you like this blog. Please share with your friends and needy ones. Until bye bye from Palani.

For your Reference : Github Repo

Feel free to connect me :

--

--