Like the character pointer, when we increment the float pointer then it points to the next float location without impacting the stored data. Let us see an example where pfData is a float pointer and we performing an arithmetic operation on it.
When we increment the pfData then it points to the next float location without impacting the stored data. Here we are assuming float size is 4 bytes. So when we increment the float pointer by 1 then it will point to the address which will be just 4 bytes more to the current pointing address.
So let us see how is the above technique work here to calculate the next pointing address for the float pointer.
Similar to that If we add 2 to the pfData (float pointer size 4 byte ) then pfData will point to the next 8 bytes of the current pointing position.
In this table, we have summarized the arithmetic operation on the float pointer. So pfData is a float pointer and supposes that initially, it points to an address “2000”.
Pointer Expression |
How it is evaluated ? |
pfData + 1 |
pfData = pfData + 1 => 2000 + 1*4 => 2004 |
pfData++ or ++pfData |
pfData++ => pfData + 1 => 2000 + 1*4 => 2004 |
pfData = pfData + 5 |
pfData => pfData + 5 => 2000 + 5*4 => 2020 |
pfData = pfData – 2 |
pfData => pfData – 2 => 2000-2*4 => 1992 |
pfData– or –pfData |
pfData => pfData – 1 => 2000-1*4 => 1996 |