取消引用结构指针中的指针 [英] Dereference a pointer inside a structure pointer

查看:76
本文介绍了取消引用结构指针中的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构:

struct mystruct
{
    int* pointer;
};

structure mystruct* struct_inst;

现在,我想更改struct_inst->pointer指向的值.我该怎么办?

Now I want to change the value pointed to by struct_inst->pointer. How can I do that?

编辑

我没有写它,但是pointer已经指向用malloc分配的内存区域.

I didn't write it, but pointer already points to an area of memory allocated with malloc.

推荐答案

与任何指针一样.要更改地址,它指向:

As with any pointer. To change the address it points to:

struct_inst->pointer = &var;

要更改其指向的地址上的:

To change the value at the address to which it points:

*(struct_inst->pointer) = var;

这篇关于取消引用结构指针中的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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