Hi
I'm attempting to create a pointer to a memory location for a structure. I am able to create such a pointer for an integer, but having problems with a structure.
The integer example is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
int main () {
int *tacos = newint[10];
*tacos = 0;
*(tacos+3) = 2;
std::cout << "Value of tacos = " << tacos << std::endl;
std::cout << "Value of *tacos = " << *tacos << std::endl;
std::cout << "Value of *(tacos+3) = " << *(tacos+3) << std::endl;
std::cout << "Value of tacos[0] = " << tacos[0] << std::endl;
std::cout << "Value of tacos[3] = " << tacos[3] << std::endl;
delete [] tacos;
return 0;
}
No issues with the above. All works well. But the following causes a compile error for line 22 & 23.
Why is it that for the new pointer to an integer in the first program I listed I have to use the notation *(taccos+3) to get to the value 2, but for the structure, in the second listing, I have to use (citems+1) ?
Output of the first program is:
1 2 3 4
Value of *tacos = 0
Value of *(tacos+3) = 2
Value of tacos[0] = 0
Value of tacos[3] = 2