码迷,mamicode.com
首页 > 其他好文 > 详细

difference between char *s and char s[ ]

时间:2015-02-24 22:13:31      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

The difference here is that :

    char *s = "hello,world!";

will place hello,world in read-only part of the memmory and makes s a pointer to that. making any writing operation on this illigal.

while:

    char s[] = "hello,world!";

will puts the hello,world in read-only memmory and copies the string to newly allocated memmory thus making :

    s[0] = ‘j‘;

legal.

 

from:http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c

difference between char *s and char s[ ]

标签:

原文地址:http://www.cnblogs.com/yongjiuzhizhen/p/4298966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!