Suppose we have a pointer to float data type which contains the memory address
value 100.
If we add the integer value 3 to this pointer, what will be the value of the pointer if float data
types are 4 bytes in length?
#include <iostream>
using namespace std;
int main()
{
cout << "Size of float is " << sizeof(float);
float a = 2;
float *fp=&a;
/*suppose, that address value is 100
Value after adding 3 will be more on 3*sizeof(float),
that is 3*4=12, and ewsukt is 112
Make a real example*/
cout << "\nReal address value is " << fp;
//difference will be 12 bytes
cout << "\nReal address value after adding 3 " << fp+3;
}
Comments
Leave a comment