cpp/c ++获取指针值或反指针化 [英] cpp / c++ get pointer value or depointerize pointer

查看:114
本文介绍了cpp/c ++获取指针值或反指针化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能使指针而不是指针.

I was wondering if it's possible to make a pointer not a pointer..

问题是我有一个函数,该函数接受参数的指针,以便我轻松获得该指针的值.这是一个简单的int,所以我想知道是否可以在不需要将指针传递到任何要传递的指针的地方获取该值.

The problem is I have a function that accepts a pointer for an paramater for me to easily get a value to that pointer. It's a simple int so I was wondering if I could just get that value without needing to send around a pointer wherever I want the value to land.

我不希望函数将值作为int返回,因为它给2个指针赋值!

I don't want the function to return the value as an int as it's giving a value to 2 pointers!

推荐答案

要获取指针的值,只需取消对指针的引用即可.

To get the value of a pointer, just de-reference the pointer.

int *ptr;
int value;
*ptr = 9;

value = *ptr;

值现在是9.

我建议您阅读有关指针的更多信息,这是它们的基本功能.

I suggest you read more about pointers, this is their base functionality.

这篇关于cpp/c ++获取指针值或反指针化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆