Programming Language/C
Escaping - Difference '\0' and '\n' in the C programming language?
keepee
2020. 12. 4. 19:01
C에서 '\0'과 '\n'의 다른 점은?
- '\0' : Null character (ASCII 0)으로, string의 terminator이다 (C strings are NULL-terminated)
// char_1은 출력할 때 hello 뒤에 쓰레기값이 같이 출력될 수 있다
char_1[10] = "hello";
// char_2는 출력할 때, string (char array)는 '\0'을 만나면 끝난 것으로 간주하므로
// hello만 잘 출력된다
char_2[10] = "hello\0";
- '\n' : Newline (ASCII 10)으로, 개행문자를 의미한다
출처: What is the difference between '\0' and '\n' in the C programming language?