Explaining Pointers in C

Palani
2 min readSep 20, 2021

--

Hey Amazing D3bugg3rs, Hope you’re doing well. In this we’re gonna disassemble the Pointers into pieces. Consider a Memory chunks to copy which is used by different functions while executing the program and it’s too expensive. For example EIP is a Instruction Pointer which points to another instruction.

According to Definition:

A pointer is a variable whose value is the address of another variable. It stores address in it. Like variable and constant it must be declared. It is declared by adding prefix (asterisk) * before it.

Syntax : dtype *pointer_name;

Where dtype refers to data types like int, float, char, double. Simply finding address of a variable is done by adding prefix & in it

——— Simple Program using Pointers ————

#include <stdio.h>

int main () {

int var = 10;
int *ip; // *ip is integer pointer
ip = &var;

printf(“The address in the int_pointer %x\n which contains the value of %d\n”, ip, var);

return 0;
}

————————————————————— — — — — — — —

Pointers with Arrays

#include <stdio.h>

int main() {
int i;
char char_array[3] = {‘a’,’b’,’c’};
char *char_pointer;

char_pointer = char_array;
for(i=0; i< 3; i++)
{
printf(“[Integer pointer] points to %p, which contains the char ‘%c’\n”, char_pointer, *char_pointer);
char_pointer = char_pointer + 1;
}
return 0;
}

In this program, we have a pointer char_ptr that points to the 0th element of the char_array. Similarly, we can also declare a pointer that can point to whole array instead of only one element of the array. This pointer is useful when talking about multidimensional arrays. In this upcoming blogs we see more about pointers.

Okay i see you in a next intersting blog until then signing off , Bye Bye :) ….

Reach me out on Instagram , Twitter

--

--

Palani
Palani

No responses yet