今日已更新 412 条资讯 | 累计 19972 条内容
关于我们

Dual role of * in C

EffessDev 2026年07月15日 20:22 0 次阅读 来源:Dev.to

Prerequisites Let's create a variable. int myNum = 5 ; Now, myNum refers to the value 5 . However, we can get its memory address using the & operator like this: &myNum . Role 1: Creating pointers A pointer holds a memory address. int * pointerToMyNum = & myNum ; Role 2: Modifying values using a pointer In this case, * works as the dereference operator. * pointerToMyNum = 10 ; Now, if we print myNum , the output will be 10 . Understanding that they are different in each context makes things much easier ✨ Note Both int ptr and int ptr are functionally identical in C.

本文内容来源于互联网,版权归原作者所有
查看原文