首页 > 技术文章 > 点(.)运算符和箭头(->)运算符的区别

cbyzju 2016-03-05 01:33 原文

 本机中,char类型数据占用1byte, unsigned int, int, long int, float类型的数据占用4 bytes, double类型的数据占用8bytes.

至于指向所有基本数据类型的指针(char*, int* , double*等)都是占用4bytes, 可以使用sizeof函数进行测量。

The<< operator on std::cout is overloaded. Its behavior depends on the type of the right operand.

The reason is that std::cout will treat a char* as a pointer to( the first character of) a C-style string and print it as such.

If you want to the address instead, you can just cast it to a pointer that isn't treated that way, something like:

cout<<(void*) terry; 或者cout<<(const void*) terry;

点运算符作用于对象,用于获取对象拥有的字段或方法。

箭头运算符作用于对象指针,先或者指针指向的对象,再隐式调用点运算符,获取对象拥有的字段或方法。

推荐阅读