By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

What is the difference between char a[]="arpit" and char *p="arpit"?

P: 1
If there is no difference then why the following statements gives an error.

p[1] = 'a';
Jun 14 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
If there is no difference then why the following statements gives an error.

p[1] = 'a';
There is a difference: array a is initialized using the characters from that string
literal (and it includes a '\0' character too). The pointer is initialized by setting its
value to the address of the literal string. Literal strings are not writable hence
your error diagnostic message.

kind regards,

Jos
Jun 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.