cout
考虑了您给它的类型。
还有的cout
许多不同的重载,此相关的是char
,char *
和PTR这实在是char **ptr
在你的榜样,你有以下数据类型
- PTR - 字符* PTR 3 - 衰减到char ** ptr(Array-to-pointer decay)
- ptr [x] - 它是*(ptr + x)或char *
- * pt [R [X] - 是**(PTR + x)或炭
要了解各后续的行确实
std::cout<<"Contents of *ptr[0]:"<<*ptr[0]<<std::endl;
std::cout<<"Contents of ptr[0] :"<<ptr[0]<<std::endl;
std::cout<<"Contents of ptr :"<<ptr<<std::endl;
当cout
定义是这样的(非常简化的)
class ostream {
public:
ostream& operator<< (const void *);
ostream& operator<< (const char *);
ostream& operator<< (const char);
};
ostream cout;
使用ADL(Argument-Dependent Lookup) or König Lookup我们首先需要找出是什么类型
* PTR [0] - >char
(炭)
的ptr [0] - >char *
(字符指针)
PTR - >char **
(指向字符指针)
现在ADL找到最专门版本,并使用该
所以他们写出来
Contents of *ptr[0]:O
Contents of ptr[0] :OMKAR
Contents of ptr :0x27fe00
是什么'ptr1'呢? – Bathsheba
ptr是char *的数组,因此ptr [0] = * ptr和ptr [1] = *(ptr + 1) –
@Bathsheba ptr1无关,我只是用它进行调试,可以评论 – Omkar