I wrote the following program to understand the addition of integer values to pointer values. In my case, the pointers point to integers. I understand that if p is a pointer to an integer, then p+2 is the address of the integer stored "two integers ahead" (or 2*4 bytes = 8 bytes). The program below works as I expect for the integer array, but for a char array it just prints empty lines. Could someone please explain to me why?
#include <iostream>
int main() {
int* v = new int[10];
std::cout << "addresses of ints:" << std::endl;
// works as expected
for (size_t i = 0; i < 10; i++) {
std::cout << v+i << std::endl;
}
char* u = new char[10];
std::cout << "addresses of chars:" << std::endl;
// prints a bunch of empty lines
for (size_t i = 0; i < 10; i++) {
std::cout << u+i << std::endl;
}
return 0;
}