当前位置:网站首页>Problems when signed and unsigned numbers are involved in operations
Problems when signed and unsigned numbers are involved in operations
2022-08-08 07:06:00 【night cat xu】
trap topic:
下面的代码输出是( )
#include<stdio.h>
int main(int argc, const char *argv[])
{
unsigned int a=6;
int b=-20;
(a+b>6)?printf(">6\n"):printf("<=6\n");
return 0;
}
A > 6
B <= 6
C 无
The final result after execution isA
So what is this asking?
b=-20;相加时,先转换成(unsigned int)-20 + 2^32-1=4,294,967,275;在与aThe result of the addition must be greater than 6.
总结:When signed and unsigned numbers are involved in operations,Converts signed numbers to unsigned numbers for operation.
举个例子:
#include <stdio.h>
int main(int argc, const char *argv[])
{
unsigned int a = 10;
int b = -20;
if(a+b > 0){
printf("yes\n");//会打印yes
}else{
printf("no\n");
}
return 0;
}
The final result is printed“yes”Prove that the above is correct.
边栏推荐
猜你喜欢
随机推荐
深度神经网络的训练过程,深度神经网络训练方法
【图形学】四元数(二)
【图形学】01 数学部分(一、集合和三角函数)
RCNN目标检测原文理解
firefly rk3399 硬件解码,多通道解码
NVIDIA CUDA 高度并行处理器编程(六):并行模式:卷积
神经网络的图像识别技术,神经网络的层数怎么看
leetcode每日一题8.6(持续更新)
状态机控制移位寄存器multisim仿真过程中出现的状态变量和状态转移条件不匹配的问题
深度学习中的优化问题(Optimization)
C语言实现冒泡排序及对冒泡排序的优化处理
ACM latex
Google Colab 快速上手
C语言实现顺序表的九个常用接口
NVIDIA CUDA 高度并行处理器编程(八):并行模式:直方图计算
Dropout、剪枝、正则化有什么关系?什么是Dropout?
File IO realizes the encryption operation of pictures
传统图像特征提取方法:边缘与角点
P03 线程安全 synchronized Lock
【图形学】08 3D坐标系的变换(一)