void fun1(const char *p) { p[0] = 'a'; // x p = "hello"; } void fun2(char * const p) { p[0] = 'a'; p = "hello"; //x } void fun3(const char * const p) { p[0] = 'a'; //x p = "hello"; //x } //const只和*的前后位置有关,与类型无任何关系。
class Point { public: Point() : x(0), y(0) {} ~Point() {} Point(const Point&) {} Point& operator=(const Point&) {} Point(Point &&){} Point& operator=(Point &&) {} friend ostream & operator<<(ostream &out, Point &p); private: int x, y; }; ostream & operator<<(ostream &out, Point &p) { out << p.x << " " << p.y; return out; } int main() { Point p; std::cout << p << p; }
int main() { char *p = (char*)malloc(5); memcpy(p, "hello", 5); printf("%c %c\n", *p++, *p); //h e printf("%c %c\n", ++(*p), *p); //printf("%c %c\n", (*p)++, *p); }