+ 2

We known that the * operator is used for declaration of pointer and we can only put the address in the pointer eg int *p=&a;

why this code running char*c="c+"; //pointer only takes address cout<<c<<endl; c++; cout<<c; /*output c+ + */

30th Jan 2018, 7:19 PM
Ankit Rathore
Ankit Rathore - avatar
5 Answers
+ 9
pointer can be used to declare arrays and strings and it always points to the first element in that array or string.
30th Jan 2018, 7:27 PM
Mazin Ayash
Mazin Ayash - avatar
+ 4
Yes, we pass to cout, but if cout sees it is a pointer to a character array (a.k.a string) it will print that string. If you want to determine how a pointer should be shown you can use printf(), you can print its address with something like %d, the first character with %c and the whole string with %s.
30th Jan 2018, 7:29 PM
Vlad Serbu
Vlad Serbu - avatar
+ 3
Because it is a pointer to a two character array. When you increment the pointer you move it to the next value in the array.
30th Jan 2018, 7:21 PM
Vlad Serbu
Vlad Serbu - avatar
+ 1
thanks #vlad and #mazen...
30th Jan 2018, 7:31 PM
Ankit Rathore
Ankit Rathore - avatar
0
if its pointer to char array then we will only pass the address to the pointer but in this program we r passing the string that contains two character..
30th Jan 2018, 7:26 PM
Ankit Rathore
Ankit Rathore - avatar