I have two doubts.
1) I read my textbook and suddenly noted this anomaly.
Code:
int a[5]{1, 2, 3, 4, 5};
int *p = &a[0];
cout<<p<<endl<<*p
gave an output.
0xfffffe (or somthing like this.).
1
But,
Code:
char a[5] = {'0', '1', '2', '3', '\0',};
char *p = a[0];
cout<<p<<endl<<*p;
gave
0123
0
instead of,
0xffffed
0
This happens only with char. I think this is to make couting of strings easier. [b]But why only for char?[b]
_______________________________________
2) (a)Suppose I want to point to a const int or const char.(pointer may change).
(b)And suppose I want to constantly point to ta varying char variable.
(c)And now suppose I want to constantly point to to a constant variable.
What do I do;(a)
Code:
const int a = 10;
int *p = &a;
or
const int *p = &a; //This would be ambiguos with (c).
const
(b)
Code:
int a= 50;
const int *p = &a;
(c)
Code:
const int a = 40;
const int *p = &a; //ambiguity with (a)
or
const int a = 40;
const const int *p = &a; //const two times ;)
No wonder I never messed with pointers.