-
[c++] unsigned int + int실수모음 2022. 12. 21. 12:40
c++ implicit type casting
어지간하면 unsigned 쓰지 말자
unsigned int 가 음수가 되지 않게하는 이상 계산값은 잘 나오긴 함
- 부호가 없는게 있는걸로 바뀜
- 사용하는 메모리 작은 자료형이 큰 자료형으로 바뀜(데이터 손실 막기 위함)
int -3 즉, 11111111111111111111111111111101(2) 이 unsigned int 가 되어 4294967293가 됨
요기에 1이 더해져서 4294967294 가 나오는거int -1 즉, 11111111111111111111111111111111(2) 이 unsigned int 가 되어 4294967295가 됨
요기에 3이 더해져서 2가 나오는거11111111111111111111111111111111 + 1 = 00000000000000000000000000000000
00000000000000000000000000000000 + 1 = 00000000000000000000000000000001
00000000000000000000000000000001 + 1 = 00000000000000000000000000000010
즉 2가 됨'실수모음' 카테고리의 다른 글
[c++] 실수 & 코너케이스(수정 24.03.26.) (1) 2022.12.22 bitwise operator는 사칙연산 + 나눗셈 연산보다 우선순위 낮음 (0) 2022.12.21 [c++] % 연산시 주의할 점 (0) 2022.12.20 와이라노?? (0) 2022.12.19 python 은 정수나눗셈이 // ! (0) 2022.12.18