Array's + Pointer's = ???

im confused on this.

#include <iostream>

using namespace std;

int main()
{
char *c,c1[127];
c = &c1 ;
cin >> c1 ;

cout << c1 ,"\n" ,c ,"\n", *c ;

system("pause");
return 0;
}

ok so the purpose of this was originally to experiment with the capabilities of pointer's but i don't understand how array's and pointer's can be used together.
in other word's if i where to make a int and a pointer then everything is fine but how come it's not the same case when it come's to arrays?
You're making a single pointer c and an array of 127 pointers, c1.
No, no, no! That snippet does this:
1
2
char * c;
char c1[127];


Anyway, the cout line will not behave as expected. Try:
cout << c1 << "\n" << c << "\n" << *c;

Also note that cout (or operator<<, rather) has specializations for C strings.
Last edited on
Topic archived. No new replies allowed.