john2020
Full Member level 5
hi all,
here's the code.....
char *p;
p="Hello";
cout<<p<<endl; // prints "Hello"
*p='M' ; // giving error
if i want to change the value at the first location ( *(p+0) ) to 'M' instead of 'H', what shud be done so that it prints "Mello";
i think as it is a string literal u cant change it,u declare it as a array and then u change it.so code is as follows:-
char p[] = "hello";
char *g = & p;
*(g + 0) = 'm';
printf("%s", p);
does anyone agree wit me?any suggestions are always welcome.
try it out,but the way u declared is wrong;take it in array and try it out u can.
here's the code.....
char *p;
p="Hello";
cout<<p<<endl; // prints "Hello"
*p='M' ; // giving error
if i want to change the value at the first location ( *(p+0) ) to 'M' instead of 'H', what shud be done so that it prints "Mello";
i think as it is a string literal u cant change it,u declare it as a array and then u change it.so code is as follows:-
char p[] = "hello";
char *g = & p;
*(g + 0) = 'm';
printf("%s", p);
does anyone agree wit me?any suggestions are always welcome.
try it out,but the way u declared is wrong;take it in array and try it out u can.