// 소스

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

int main()

{

  char* test_str = (char*)malloc(sizeof(char)*100);  /// heap 에 만듬

  test_str = 0;

  for (int i=0; i < 100; i++) printf(test_str[i]);

}

// 결과

Process returned -107341819 (0x00000005)  // 런타임 에러




// 소스

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

int main()

{

  char* test_str = (char*)malloc(sizeof(char)*100);  /// heap 에 만듬

  strcpy(test_str, "");

  for (int i=0; i < 100; i++) printf(test_str[i]);

}

// 결과

00-11502420-115000000000000000000000000000000000000000000

// memcpy 같은 함수 인자로 못주고, strncpy 함수 두번째 인자로 못줄정도로 안전성이 떨어짐





// 소스

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

int main()

{

  char* test_str = (char*)malloc(sizeof(char)*100);  /// heap 에 만듬

  strcpy(test_str, "");

  for (int i=0; i < 100; i++) printf(test_str[i]);

}

// 결과

00-11102420-00....

// 위와 비슷한 결과





안해봐도 뻔한걸 왜 햇을까..

빡대가리라는 소리가 억울하였는듯..