#include <stdio.h>
#include <stdlib.h>

int main() {
    int a = 10;
    int *p = &a;
    printf("%d\n", a);
    printf("%p\n", &a);      // 주소(&)를 출력할 때는 %p!
    printf("%d\n", *p);
    *p = *p + 20;
    printf("%d\n", a);
    int b[3] = {1, 2, 3};
    int *p1 = &a;
    printf("*p = %d\n", *p);   // 배열일때는 *p = a1[0], *p+1 = a1[1], *p+2  = a[2]!
    printf("*p+1 = %d\n", *p+1);
    printf("*p+2 = %d\n", *p+2);
    int *p2 = malloc(sizeof(int)*100);    // 4*100바이트 메모리 만들기(100개 저장 가능!)
    if(p2 ==NULL) return 1;
    p2[1] = 10;
    p2[2] = 11;
    printf("%d\n", p2[1]);
    printf("%d\n", p2[2]);
    free(p2);       // 공간 비우기
    p2 = NULL;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: