什么是字符指针数组和二维数组之间的区别是什么? [英] What are the differences between an array of char pointers and a 2D array?
本文介绍了什么是字符指针数组和二维数组之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是字符指针数组和二维数组之间的区别是什么?
解决方案
的char * pasz [3] = {ABC,高清,GHI};
CHAR ASZ [3] [] = {ABC,高清,GHI};
的异同基本相同,这两者之间:
的char * PSZ =JKL;
CHAR SZ [] =JKL;
首先是最初的只读。
PSZ [0] ='A'; //非法的!
第二,你可以修改的,因为你为它分配 []
。
SZ [0] ='B';
// SZ ==BKL
第一,你可以修改它指向:
字符mysz [] =ABC;
PSZ = mysz;PSZ [0] ='B';
// mysz ==BBC
第二,你不能
SZ = mysz; //不能数组分配给一个数组!
What are the differences between an array of char pointers and a 2D array?
解决方案
char* pasz[3] = {"abc", "def", "ghi"};
char asz[3][] = {"abc", "def", "ghi"};
The similarities and differences are basically the same as between these two:
char *psz = "jkl";
char sz[] = "jkl";
The first is originally read-only.
psz[0] = 'a'; // Illegal!!
The second, you can modify, since you allocate it with the []
.
sz[0] = 'b';
// sz == "bkl"
The first, you can modify what it points to:
char mysz[] = "abc";
psz = mysz;
psz[0] = 'b';
// mysz == "bbc"
The second, you cannot:
sz = mysz; // Can't assign an array to an array!!
这篇关于什么是字符指针数组和二维数组之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文