<aside> ๐ก
C Pointer is..
The derived data type that is used to store the address of another variable and can also used to access and mainpulate the variableโs data stored at that location.
*From. https://www.tutorialspoint.com/cprogramming/c_pointers.htm*
</aside>
์ผ๋ฐ์ ์ผ๋ก๋ dereferencing operator : *
์ ์ฌ์ฉํจ
type *var_name;
๋ณ์์ ์ฃผ์๋ฅผ ์ด๊ธฐํ ํ ๋๋ referencing a pointer : &
์ ์ฌ์ฉ
pointer_variable = &variable;
ํํ
int a = 5;
// ์ ์ํ ํฌ์ธํฐ p ์ ์ธ
int *p;
// a์ ์ฃผ์๋ฅผ p์ ์ ์ฅ
p = &a;
๋ฉค๋ฒ ๋ณ์
// ์ (.) ์ฌ์ฉ: ๊ตฌ์กฐ์ฒด ๋ณ์ ์ ๊ทผ
ListNode node;
node.item = 10;
// ํ์ดํ(->) ์ฌ์ฉ: ๊ตฌ์กฐ์ฒด ํฌ์ธํฐ ์ ๊ทผ
ListNode *ptr = &node;
ptr->item = 20;
ll->head == (*ll).head
#include <stdio.h>
int main() {
int x = 10;
// Pointer declaration and initialization
int * ptr = & x;
// Printing the current value
printf("Value of x = %d\\n", * ptr);
// Changing the value
* ptr = 20;
// Printing the updated value
printf("Value of x = %d\\n", * ptr);
return 0;
}
// Output
// Value of x = 10
// Value of x = 20
// ์: 8 (64๋นํธ ์์คํ
)
printf("%lu\\n", sizeof(int*));
// ์: 8 (64๋นํธ ์์คํ
)
printf("%lu\\n", sizeof(char*));