I thought I had a decent knowledge of pointers until I decided to consider some of the so-called trivial examples.
One thing I know is that when declaring an array they say:
int arr[2] {3, 5};
arr
will hold the value of the first element in the array, so trying to print it ( cout << arr
) gives, obviously, an address arr[0]
. Even if my program uses pointers, it is still similar.
My question is why I can print h
and have bonjour
as output, but I can not do the same with p
?
It also looks when I enlarge h++
and print it again. I get it onjour
. How do different pointers differ from char
?
#include <iostream>
#include <string>
int main()
{
char* h = "bonjour";
int k[4]{3, 4, 5, 6};
int * p = k;
std::cout << "Hello, "<< h << "!\n";
}