C++中赋值运算符与逗号运算符的用法详解

论坛 期权论坛     
选择匿名的用户   2021-5-23 02:02   31   0
<p><br> </p>
<p><br> </p>
<p></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> <strong>赋值运算符</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 赋值符号“&#61;”就是赋值运算符,它的作用是将一个数据赋给一个变量。如“a&#61;3”的作用是执行一次赋值操作(或称赋值运算)。把常量3赋给变量a。也可以将一个表达式的值赋给一个变量。<br> <strong>赋值过程中的类型转换</strong></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 如果赋值运算符两侧的类型不一致,但都是数值型或字符型时,在赋值时会自动进行类型转换。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 1)  <span style="color:#ff0000">将浮点型数据(包括单、双精度)赋给整型变量时,舍弃其小数部分</span>。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 2)  <span style="color:#ff0000">将整型数据赋给浮点型变量时,数值不变,但以指数形式存储到变量中</span>。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 3) <span style="color:#ff0000">将一个double型数据赋给float变量时,要注意数值范围不能溢出</span>。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 4)  <span style="color:#ff0000">字符型数据赋给整型变量,将字符的ASCII码赋给整型变量</span>。</p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:5px; padding-bottom:5px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif; line-height:25px"> 5) <span style="color:#ff0000">将一个int、short或long型数据赋给一个char型变量,只将其低8位原封不动地送到char型变量(发生截断)</span>。例如<br>   </p>
<div class="jb51code" style="line-height:25px; font-size:14px; font-family:Tahoma,Helvetica,Arial,宋体,sans-serif">
<div class="syntaxhighlighter  cpp" id="highlighter_714637" style="width:653px; margin:1em 0px!important; position:relative!important; overflow:auto!important">
  <div class="toolbar" style="line-height:13.1875px; background-color:rgb(108,226,108)!important; border:none!important; bottom:auto!important; float:none!important; height:11px!important; left:auto!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:absolute!important; right:1px!important; top:1px!important; vertical-align:baseline!important; width:11px!important; font-family:Consolas,&#39;Bitstream Vera Sans Mono&#39;,&#39;Courier New&#39;,Courier,monospace!important; min-height:inherit!important; z-index:10!important; color:white!important">
   <span style="line-height:25px"><a class="toolbar_item command_help help" href="http://www.jb51.net/article/71991.htm#" rel="noopener noreferrer" style="text-decoration:none; color:rgb(0,102,153); border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:1px 0px 0px!important; position:static!important; right:auto!important; text-align:center!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:inherit!important; display:block!important" target="_blank">?</a></span>
  </div>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse; border-spacing:0px; width:653px; clear:both; padding:0px!important; margin:0px!important; font-size:1em!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; font-family:Consolas,&#39;Bitstream Vera Sans Mono&#39;,&#39;Courier New&#39;,Courier,monospace!important; min-height:inherit!important"><tbody style="border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; padding:0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:1em!important; min-height:inherit!important"><tr style="border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; p
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP