指针和数组之间的区别 [英] Difference between pointer and array

查看:45
本文介绍了指针和数组之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复项:
char之间的差异* str =“ STRING”和char str [] ="STRING"?
C:指针与数组之间的差异

有人可以告诉我以下陈述之间的区别吗?

Can anybody tell me the difference between the statements below?

char *p = "This is a test";

char a[] = "This is a test";

推荐答案

当声明char p []时,您将声明一个char数组(可读取和写入均可访问),并且此数组已初始化为一些字符序列(即这是测试")被复制到此数组中的元素.

When you declare char p[] you are declaring an array of chars (which is accessible to be both read and written), and this array is initialized to some sequence of characters i.e. "This is test" is copied to the elements in this array.

当声明char * p时,就是在声明一个直接指向某个常量文字而不是副本的指针.这些只能读取.

When you declare char* p, you are declaring a pointer that points directly to some constant literal - not a copy. These can only be read.

这篇关于指针和数组之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆