- 실행중에 명령어는 바뀌지 않음, 바뀐다면 바이러스
- 메모리는 공유자원, 즉 프로그램 실행시에만 메모리 사용, 이후 비움
- 데이터에는 3가지의 영역이 존재
- 프로그램 종료시까지 남아있어야 하는 데이터 >> Global Data Area
- 자동적으로 생겨났다가 자동적으로 사라지는 데이터 >> stack Area
- 사용자가 작업을 하는 영역, 즉 작업영역에 실행시간(런타임)동안 메모리에서 만들어지거나 지워지는 데이터 >> Heap Area
- malloc가 여기에 해당, free로 메모리를 지움
#include <stdio.h>
#include <stdlib.h>
int main() {
double* pk = malloc(sizeof(double) * 2);
*pk = 100.1;
pk[0]) = 299.2;
free(pk);
//#include <stdio.h>
//#include <stdlib.h>
//
//int main() {
// double d = 5.5;
// double* pk = NULL;
// pk = malloc(sizeof(double) * 2);
// if (pk == NULL) {
// printf("Memory allocation failed\n");
// return -1;
// pk[0] = 1.1;
// pk[1] = 2.2;
// printf("data : %g\n", pk[0]);
// printf("data : %g\n", pk[1]);
// free(pk);
//}
//#include <stdio.h>
//#include <stdlib.h>
//
//int main() {
// int* p = malloc(sizeof(int) * 4); // p는 stack데이터지만, malloc은 heap에 할당
// p[0] = 10;
// p[1] = 20;
// p[2] = 30;
// p[3] = 40;
// printf("data : %d\n", p[0]);
// printf("data : %d\n", p[1]);
// printf("data : %d\n", p[2]);
// printf("data : %d\n", p[3]);
//
// free(p);
//}
//#include <stdio.h>
//#include <stdlib.h>
//
//int main() {
// int* p = malloc(sizeof(int)); // p는 stack데이터지만, malloc은 heap에 할당
// *p = 10;
// printf("data : %d\n", *p);
//
// free(p);
//}
//#include <stdio.h>
//
//
//
//void a() {
// int n1 = 10;
// printf("n1 : %d\n", n1);
//}
//
//void b() {
// int n2 = 10;
// printf("n2 : %d\n", n2);
// a();
//}
//
//void c() {
// int n3 = 10;
// printf("n3 : %d\n", n3);
// a();
// b();
//}
//
//int main() {
// a();
// b();
// c();
//
//}
//#include <stdio.h>
//
//int main() {
// char* s1 = "ABC";
// char s2[] = { 'A', 'B', 'C', '\0' };
// printf("%s %s %s\n", s1, s2, "ABC");
//
//}
//
//#include <stdio.h>
//
//int main() {
// char p[4] = { 'a', 'b', 'c', '\0' };
// printf("string: %s\n", p);
// printf("string: %s\n", &p[0]);
// printf("string: %c\n", p[0]);
// printf("string: %c\n", p[1]);
// printf("string: %c\n", p[2]);
//
//}
//
//#include <stdio.h>
//
//int main() {
// char p[4] = "ABC";
// printf("string: %c\n", p[0]);
// printf("string: %c\n", p[1]);
// printf("string: %c\n", p[2]);
//
//}
//#include <stdio.h>
//
//int main() {
// char* p = "ABC";
// printf("string: %c\n", p[0]);
// printf("string: %c\n", p[1]);
// printf("string: %c\n", p[2]);
//}