C++ print value of a pointer

十年热恋 提交于 2020-01-02 06:21:51

问题


I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value?

cout << arr[i] ? cout << &arr[i] ? they both print the address

Does anyone know?


回答1:


If it's really an array of (initialized) double pointers, i.e.:

double *arr[] = ...
// Initialize individual values

all you need is:

cout << *arr[i];



回答2:


cout << *(arr[i]) will print the value.




回答3:


cout << *(arr[i]);




回答4:


If "arr" is declared as

double* arr[..];

Then you would use:

cout << *(arr[i])


来源:https://stackoverflow.com/questions/2485565/c-print-value-of-a-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!