关于C++的一些小知识点

2023-12-14 17:19:22
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);
}

文章来源:https://blog.csdn.net/gaoyuelon/article/details/134998026
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。