in Technology by
How is Pointer Arithmetic works on Float Pointer?

1 Answer

0 votes
by

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.

float *pfData = NULL;

 

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.

pfData++;

 

So let us see how is the above technique work here to calculate the next pointing address for the float pointer.

addr( pfData + 1 ) = addr( pfData ) + [ sizeof( float) * 1 ];
addr( pfData + 1 ) = addr( pfData ) + [ 4 * 1 ];
addr( pfData + 1 ) = addr( pfData ) + 4;

 

arithmatic operation on 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.

float *pfData = NULL;
pfData = pfData + 2;

 

pointer arithmetic

 

 

 

 

 

 

 

 

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

Related questions

0 votes
    How is Pointer Arithmetic work on Character Pointer?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    How does pointer arithmetic work?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    Can we perform arithmetic operation on pointers?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    1.In a CPU. does the complex arithmetic and logical calculations on data. 2. The disk drive is a collection of ... of the digital dama Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    B. Fill in the blanks. 1. In a CPU, does the complex arithmetic and logical calculations on data. 2. ... thin circular discs called Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
0 votes
    Hi, I am a relatively new programmer and my teacher gave us this problem to fix. Thing is, I have no idea ... wrong with this problem? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can math operations be performed on a void pointer?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is a pointer on pointer?...
asked Jan 17, 2021 in Technology by JackTerrance
0 votes
    What happens when we invoke a method on a nil pointer?...
asked Nov 10, 2020 in Technology by JackTerrance
+1 vote
    What is a pointer on pointer?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    What is a pointer on a pointer in C programming language?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    How will you convert a string to a float in python?...
asked Nov 24, 2020 in Technology by JackTerrance
0 votes
    The current copy of the database is identified by a pointer, called ____________ which is stored on disk. ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...