What is a pointer? Discuss Pointer arithmetic with suitable C code

10.B) What is a pointer? Discuss Pointer arithmetic with suitable C code

Answer:-

A pointer is a variable that holds the address of another variable. The pointer variable
contains only the address of the referenced variable, not the value stored at that address.

Pointer arithmetic is very important to understand if you want to have complete knowledge of
pointer. In this topic, we will study how the memory addresses change when you increment a
pointer.

In a 16 bit machine, the size of all types of the pointer, be it int, float, char*, or double* is always 2
bytes. But when we perform any arithmetic function like increment on a pointer, changes occur as
per the size of their primitive data type.

Examples for Pointer Arithmetic:-

Now let’s take a few examples and understand this more clearly.

int*i;

i++

In the above case, the pointer will be 2 bytes. And when we increment it, it will increment by 2 bytes because int is also of 2 bytes.

float*i;

i++;
In this case, the size of a pointer is still 2 bytes. But now, when we increment it, it will increment by 4 bytes because the float is 4 bytes.
double* i;
i++;
Similarly, in this case, the size of a pointer is still 2 bytes. But now, when we increment it, it will
increment by 8 bytes because its data type is double.


Leave a Reply

Your email address will not be published. Required fields are marked *