I would like to understand how pointers work, so i created this small program. first of all i create a p pointer, which points to a char.
The first question is at this point. If i create a pointer, the value of it is a memoryaddress (if i point it to a non-pointer object), but this time it is "haha" in my example. Why does it work this way in char*? And how i can add value to it with cin >> p?
My second question is that, i created a q char, which has the value of the *p pointer at the point i created it. BUT its value and address are "h" too, but why? It must be the memory address of this char object! It's pointless :D (mingw - gcc)
#include <iostream>
int main()
{
/* char *p;
cin >> p; //forexample: haha */
char * p = "haha";
char q = *p;
std::cout << "&q = " << &q << std::endl; //&q = h
std::cout << "q = " << q << std::endl; //q = h
return 0;
}
MORE: If i allocate memory first with char a[100]; char *p=a; then &q = h»ŢĹ, so "h" and some mess. but it should be a memoryaddress! and my question is, why is not it address then?