sizeof( char + char ) 는 4byte ?
글쓴이: helloc_ / 작성시간: 목, 2014/01/09 - 2:31오후
강의를 보다 이해가 가지 않는 예제를 보고 질문 올립니다
#include
int main(void)
{
char ch1=1, ch2=2;
printf( "%d\r\n", sizeof( char ) );
printf( "%d\r\n", sizeof( ch1 ) );
printf( "%d\r\n", sizeof( ch2 ) );
printf( "%d\r\n", sizeof( ch1 + ch2 ) );
return 0;
}
위 코드를 작성하고 실행한 결과
1
1
1
4
이런 결과가 나오네요 왜 1byte의 char 변수 ch1, ch2 를 더한 결과가 4byte가 되는건가요 ?
Forums:
ch1 + ch2 = 3 sizeof(3)
ch1 + ch2 = 3
sizeof(3)
sizeof(ch1) + sizeof(ch2) !=
sizeof(ch1) + sizeof(ch2) != sizeof(ch1 + ch2) == sizeof(int)
https://www.securecoding.cert
https://www.securecoding.cert.org/confluence/display/seccode/INT02-C.+Understand+integer+conversion+rules
와우..감사합니다!
와우..감사합니다!
gilgil.net
재미있네요.
char + char의 return type이 char가 아닌 int라는 얘기인가요?
www.gilgil.net
네. 정수 승격(integer
네. 정수 승격(integer promotion)이라고 합니다. 위에 링크한 내용을 참고하세요.
댓글 달기