c - 更新指针值会更新它指向的内容吗?

标签 c pointers struct

我有一个指向名为 sp 的结构的指针。

struct thestruct *sp_pointer = NULL;

sp_pointer = sp;

该结构有一个称为单位的字段。即sp->单位

如果我要做sp_ponter->units = sp_pointer->units + 100;

这会更新 sp->units 中的值吗?

最佳答案

if I were to do sp_ponter->units = sp_pointer->units + 100;

would this update the value in sp->units?

是的,会的。分配后,sp_pointer 指向与 sp 相同的内存。假设两个指针的类型相同,那么您所拥有的应该没问题。

关于c - 更新指针值会更新它指向的内容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36292460/

相关文章:

c++ - 为什么我的 C++ 指针突然不同了?

c++ - 指向类的私有(private)数据成员的指针

C 在数组中存储变量的地址

c - 无法释放父结构的 child

c - 在 C 中初始化全局结构

c - 在 C 程序上通过 execve/l 执行 omxplayer 不会在 fork() 之后在子进程的非 X 控制台上输出视频

c++ - C(嵌入式): Code size does not shrink when commenting FreeRTOS' RootTask

c - qsort 和 bsearch 指针数组

c - 声明结构的差异

c - 使用指向指针的指针初始化 C 结构