C에서 * 의 이중 역할

작성자

카테고리:

← 피드로
DEV Community · EffessDev · 2026-07-15 개발(SW)

EffessDev

EffessDev

Posted on Jul 15 • Edited on Jul 16

Prerequisites

Let’s create a variable.

int myNum = 5;

Enter fullscreen mode Exit fullscreen mode

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;

Enter fullscreen mode Exit fullscreen mode

Role 2: Modifying values using a pointer

In this case, * works as the dereference operator.

*pointerToMyNum = 10;

Enter fullscreen mode Exit fullscreen mode

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.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다