gpt4 book ai didi

c++ - 地址 (&) 和间接运算符的正确格式是什么

转载 作者:行者123 更新时间:2023-11-30 05:14:49 25 4
gpt4 key购买 nike

<分区>

我见过许多不同的写寻址运算符 (&) 和间接运算符 (*) 的方法

如果我没记错的话应该是这样的:

//examples
int var = 5;
int *pVar = var;

cout << var << endl; //this prints the value of var which is 5

cout << &var << endl; //this should print the memory address of var

cout << *&var << endl; //this should print the value at the memory address of var

cout << *pVar << endl; //this should print the value in whatever the pointer is pointing to

cout << &*var << endl; //I've heard that this would cancel the two out

例如,如果您将 &var 写成 & var,两者之间有一个空格,会发生什么情况?我见过的常见语法:char* line = var;char * line = var;char *line = var;

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com