How do I add pointers and math in C++.
First i am creating an array to hold 5 integers, we know that each integer is stored 4 bytes in the computer is memory, some of the new machines might store 8 or more, but in C++ the default of an integer is 4 bytes.
I will create three pointers which will be added to the address of &laurand, the first element is .
int *landi0 = &laurand;
int *landi1 = &laurand;
int *landi2 = &laurand;
When adding more integers will also add more 4 bytes memory to each address.
cout << "Landi1 is at the address " << landi0 << endl;
cout << "Landi2 is at the address " << landi1 << endl;
cout << "Landi3 is at the address " << landi2 << endl;
I'm adding more two at the address landi0.
landi0 += 2;
Print out on the screen the address of Landi0.
cout << "Landi1 now is at the address " << landi0 << endl;
Watch live in action creating the program, or scroll below to copy the entire code.
Feel free to use the code.
Last update .