What happens if I assign a negative value to an unsigned variable?

前端 未结 6 970
旧巷少年郎
旧巷少年郎 2020-11-22 07:31

I was curious to know what would happen if I assign a negative value to an unsigned variable.

The code will look somewhat like this.

unsigned int nVa         


        
6条回答
  •  醉梦人生
    2020-11-22 08:12

    It will show as a positive integer of value of max unsigned integer - 4 (value depends on computer architecture and compiler).

    BTW
    You can check this by writing a simple C++ "hello world" type program and see for yourself

提交回复
热议问题