<정처기> C언어 5. ASCII 코드

빡찌's avatar
Sep 26, 2024
<정처기> C언어 5. ASCII 코드
 
int main() { char c = 'A'; //'문자'넣음 int ascii_value = (int)c; //'문자'를 숫자로 바꿔 넣음 printf("Character: %c\n", c); //%c이기 때문에 문자 출력 printf("ASCII Value: %d\n", ascii_value); //%d라서 숫자 출력 return 0; }
출력값:
Character: A
ASCII Value: 65
 
똑같은 ‘A’를 %d로 뽑으면 숫자 65가 나올까,,
아스키의 핵심은 출력하는 형태를 눈여겨서 봐야한다는 점!!
 

대문자 A = 65 소문자 a = 97 문자 “0” = 48 외우자!!!!!!!!!!!!!!!!!!!

A와 a의 차이는 32.. 이것도 기억해두자
 
int main() { char lower = 'a'; //97 char upper = (char)(lower - 32); //97-32 = 65 > A //문자로 출력 printf("Lowercase: %c\n", lower); printf("Uppercase: %c\n", upper); return 0; }
이런식으로도 나옴
 
숫자는 어짜피 더해지는거니까 ‘0’ 에서 7을 더해도 그냥 7이다
 
실제문제
int main() { char *p = "KOREA"; //ㅇㅋ 포인터 변수 선언정의 printf("%s\n", p); //KOREA printf("%s\n", p+1); //OREA printf("%c\n", *p); //K printf("%c\n", *(p+3)); //K에서 3개 뒤에 있는 값 => E printf("%s\n", *p+4); //*p = K, 알파벳 K에서 4개 뒤 => O
 

“0” + 3 = “3” a + 3 = d

>> a b c d
Share article

prettytree