In the following program the string stored is changed using cin
, thus changing address.
The address of the first element of string is represented by s
. The address of the first element is the string itself. Thus it got changed when new string is entered. When I try to output &s[0]
to cout
it gives the whole string.
#include<iostream>
using namespace std;
int main() {
char s[6];
cin >> s; // say abcde
cout << s ;
cout << &s[0] ; // gives abcde
cin >> s; // say stack
cout << s;
cout << &s[0] ; gives stack
}