C/C++에서 sizeof('a')의 차이
조회수 4623회
C/C++에서 char의 크기는 1이라고 배웠는데요 C/C++에서 print('a')한 결과가 달라요
C에서:
#include <stdio.h>
int main() {
printf("Size of char : %d\n",sizeof(char));
return 0;
}
C++에서:
#include <iostream>
int main() {
std::cout<<"Size of char : "<<sizeof(char)<<"\n";
return 0;
}
하면 똑같이 1나오는데
C에서:
#include <stdio.h>
int main() {
char a = 'a';
printf("Size of char : %d\n",sizeof(a));
printf("Size of char : %d\n",sizeof('a'));
return 0;
}
하면
Size of char : 1
Size of char : 4
C++에서:
#include <iostream>
int main() {
char a = 'a';
std::cout<<"Size of char : "<<sizeof(a)<<"\n";
std::cout<<"Size of char : "<<sizeof('a')<<"\n";
return 0;
}
하면
Size of char : 1
Size of char : 1
이 나와요 왜죠? 왜 sizeof('a') 한 결과가 다른거죠?
댓글 입력