⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 运算符和表达式(位运算符).htm

📁 单片机教程 用c语言实现编程 可以大大缩短我们的开发周期
💻 HTM
📖 第 1 页 / 共 3 页
字号:
                    <TR>
                      <TD width=21 vborder="0">
                        <P>/=</P></TD>
                      <TD width=77 vborder="0">
                        <P>除法赋值</P></TD>
                      <TD width=42 vborder="0">
                        <P>^=</P></TD>
                      <TD width=91 vborder="0">
                        <P>逻辑异或赋值</P></TD></TR></TBODY></TABLE>
                  <P>%=&nbsp;&nbsp; &nbsp;取模赋值&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  &nbsp;-=&nbsp;&nbsp; &nbsp;逻辑非赋值</P>
                  <P>&lt;&lt;= &nbsp;左移位赋值 复合运算的一般形式为:</P>
                  <P>变量&nbsp;&nbsp; &nbsp;复合赋值运算符&nbsp;&nbsp; &nbsp;表达式 
                  其含义就是变量与表达式先进行运算符所要求的运算,再把运算结果赋值给参与运算的</P>
                  <P>变量。其实这是 C 语言中一种简化程序的一种方法,凡是二目运算都能用复合赋值运算符 去简化表达。例如:</P>
                  <P>a+=56 等价于 a=a+56</P>
                  <P>y/=x+9 &nbsp;等价于 &nbsp;y=y/(x+9) 
                  很明显采用复合赋值运算符会降低程序的可读性,但这样却能使程序代码简单化,并</P>
                  <P>能提高编译的效率。对于开始学习 C 语言的朋友在编程时最好还是根据自己的理解力和习惯去使 
                  用程序表达的方式,不要一味追求程序代码的短小。</P>
                  <P>逗号运算符</P>
                  <P>如果你有编程的经验,那么对逗号的作用也不会陌生了。如在 VB 中“Dim a,b,c”的逗 
                  号就是把多个变量定义为同一类型的变量,在 C 也一样,如“int a,b,c”,这些例子说明逗 号用于分隔表达式用。但在 C 
                  语言中逗号还是一种特殊的运算符,也就是逗号运算符,能 
                  用它将两个或多个表达式连接起来,形成逗号表达式。逗号表达式的一般形式为:</P>
                  <P>表达式 1,表达式 2,表达式 3……表达式 n</P>
                  <P>这样用逗号运算符组成的表达式在程序运行时,是从左到右计算出各个表达式的值,而 
                  整个用逗号运算符组成的表达式的值等于最右边表达式的值,就是“表达式 n”的值。在实 
                  际的应用中,大部分情况下,使用逗号表达式的目的只是为了分别得到名个表达式的值,而 
                  并不一定要得到和使用整个逗号表达式的值。要注意的还有,并不是在程序的任何位置出现 
                  的逗号,都能认为是逗号运算符。如函数中的参数,同类型变量的定义中的逗号只是用来 
                  间隔之用而不是逗号运算符。</P></DIV><BR style="PAGE-BREAK-BEFORE: auto" 
                  clear=all>
                  <DIV class=Section35>
                  <P>条件运算符</P>
                  <P>上面我们说过单片机C语言中有一个三目运算符,它就是“?:”条件运算符,它要求有三个运算对象。它能把三个表达式连接构成一个条件表达式。条件表达式的一般形式如下:</P>
                  <P>逻辑表达式? &nbsp;表达式 1 &nbsp;: &nbsp;表达式 2 
                  条件运算符的作用简单来说就是根据逻辑表达式的值选择使用表达式的值。当逻辑表达</P>
                  <P>式的值为真时(非 0 值)时,整个表达式的值为表达式 1 的值;当逻辑表达式的值为假(值</P>
                  <P>为 0)时,整个表达式的值为表达式 2 的值。要注意的是条件表达式中逻辑表达式的类型可 以与表达式 1 和表达式 2 
                  的类型不一样。下面是一个逻辑表达式的例子。</P>
                  <P>如有 a=1,b=2 这个时候我们要求是取 ab 两数中的较小的值放入 min 变量中,也许你会这样 写:</P>
                  <P>if &nbsp;(a&lt;b)</P>
                  <P>min &nbsp;= &nbsp;a;</P>
                  <P>else</P>
                  <P>min &nbsp;= &nbsp;b; &nbsp;//这一段的意思是当 a&lt;b 时 min 的值为 a 
                  的值,不然为 b 的值。</P>
                  <P>用条件运算符去构成条件表达式就变得简单明了了:</P>
                  <P>min &nbsp;= &nbsp;(a&lt;b)?a &nbsp;: &nbsp;b 
                  很明显它的结果和含意都和上面的一段程序是一样的,但是代码却比上一段程序少很多,编译的效率也相对要高,但有着和复合赋值表达式一样的缺点就是可读性相对效差。在实际应 
                  用时根据自己要习惯使用,就我自己来说我喜欢使用较为好读的方式和加上适当的注解,这 
                  样能有助于程序的调试和编写,也便于日后的修改读写。</P></DIV><BR><BR><!--推荐--></DIV></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=box_common_title align=middle colSpan=2><A 
            href="http://www.5jia1.com/league/blog/show_comm.php?bid=361291">&lt;&lt; 
            上一篇:第七课 运算符和表达式(关系运算符)</A> | <A 
            href="http://www.5jia1.com/league/blog/show_comm.php?bid=361293">下一篇:第九课 
            C51运算符和表达式(指针和地址运算符) &gt;&gt; </A></TD></TR>
        <TR class=box_common_content>
          <TD colSpan=2>
            <TABLE width="100%">
              <TBODY>
              <TR>
                <TD align=left><IMG title=人气 src="8.files/icon_click.gif" 
                  align=absMiddle border=0>人气(144)&nbsp; <IMG title=评论 
                  src="8.files/icon_btn_comment.gif" align=absMiddle 
                  border=0>&nbsp;<A 
                  href="http://www.5jia1.com/league/blog/show_comm.php?bid=361292#reply">评论(0)</A> 
                  <IMG title=转贴 src="8.files/icon_repost.gif" align=absMiddle 
                  border=0>&nbsp;转贴<A 
                  onclick=get_refer_list(514465,361292,400,505) 
                  href="javascript:void(0)">(<SPAN id=refer_361292>0</SPAN>)</A> 
                  <IMG title=收藏 src="8.files/icon_btn_favorite.gif" 
                  align=absMiddle border=0>&nbsp;<A onclick=alert_login(); 
                  href="javascript:void(0);"> 收藏</A></TD>
                <TD align=right></TD></TR></TBODY></TABLE></TD></TR>
        <TR class=box_common_content>
          <TD align=right colSpan=2><INPUT 
            onclick="javascript:alert('对不亲,请您登录!');" type=image 
            src="8.files/button_tuijian.gif"> 
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE class=box_spec cellSpacing=1 cellPadding=5 width="98%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD><STRONG>发表评论</STRONG><A name=reply></A></TD>
    <TD align=middle>&nbsp;</TD></TR>
  <TR class=box_spec_content>
    <TD align=middle>&nbsp;</TD>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 border=0>
        <FORM id=comment name=comment onsubmit="return formsubmit();" 
        action=/league/blog/add_comm.php method=post target=hidden_frame><INPUT 
        id=bid type=hidden value=361292 name=bid> <INPUT id=sid type=hidden 
        name=sid> 
        <TBODY>
        <TR>
          <TD><SPAN 
            class=font_common_title>发表评论</SPAN>(最多可填600个字符,300个汉字)&nbsp;<SPAN 
            class=color_red id=left_num>0</SPAN>/600</TD>
          <TD>&nbsp;</TD></TR>
        <TR>
          <TD><TEXTAREA class=input_box01 onpropertychange="textCounter(comment.content, 600)" name=content rows=10 cols=70></TEXTAREA> 
          </TD>
          <TD vAlign=top>
            <DIV><LABEL>插入表情:</LABEL> 
            <TABLE 
            style="BORDER-RIGHT: #96ae72 1px solid; BORDER-TOP: #96ae72 1px solid; BACKGROUND: #edf8dd; BORDER-LEFT: #96ae72 1px solid; BORDER-BOTTOM: #96ae72 1px solid">
              <TBODY>
              <TR>
                <TD><A onclick="insertSmile('[[::keai::]]');" 
                  href="javascript:void(0)"><IMG title=可爱 height=32 
                  src="8.files/1.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::ciya::]]');" 
                  href="javascript:void(0)"><IMG title=呲牙 height=32 
                  src="8.files/2.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::guilian::]]');" 
                  href="javascript:void(0)"><IMG title=鬼脸 height=32 
                  src="8.files/3.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::deyi::]]');" 
                  href="javascript:void(0)"><IMG title=得意 height=32 
                  src="8.files/4.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::xihuan::]]');" 
                  href="javascript:void(0)"><IMG title=喜欢 height=32 
                  src="8.files/5.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::jie::]]');" 
                  href="javascript:void(0)"><IMG title=饥饿 height=32 
                  src="8.files/6.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::chijing::]]');" 
                  href="javascript:void(0)"><IMG title=吃惊 height=32 
                  src="8.files/7.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::sikao::]]');" 
                  href="javascript:void(0)"><IMG title=思考 height=32 
                  src="8.files/8.gif" width=32 border=0></A></TD></TR>
              <TR>
                <TD><A onclick="insertSmile('[[::haixui::]]');" 
                  href="javascript:void(0)"><IMG title=害羞 height=32 
                  src="8.files/9.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::tongkuliu::]]');" 
                  href="javascript:void(0)"><IMG title=痛哭 height=32 
                  src="8.files/10.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::bizui::]]');" 
                  href="javascript:void(0)"><IMG title=闭嘴 height=32 
                  src="8.files/11.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::kubi::]]');" 
                  href="javascript:void(0)"><IMG title=酷酷 height=32 
                  src="8.files/12.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::liuhan::]]');" 
                  href="javascript:void(0)"><IMG title=流汗 height=32 
                  src="8.files/13.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::konghe::]]');" 
                  href="javascript:void(0)"><IMG title=恐吓 height=32 
                  src="8.files/14.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::gaoxing::]]');" 
                  href="javascript:void(0)"><IMG title=高兴 height=32 
                  src="8.files/15.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::kunjuan::]]');" 
                  href="javascript:void(0)"><IMG title=困倦 height=32 
                  src="8.files/16.gif" width=32 border=0></A></TD></TR>
              <TR>
                <TD><A onclick="insertSmile('[[::yiwen::]]');" 
                  href="javascript:void(0)"><IMG title=疑问 height=32 
                  src="8.files/17.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::zhaoji::]]');" 
                  href="javascript:void(0)"><IMG title=着急 height=32 
                  src="8.files/18.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::nanguo::]]');" 
                  href="javascript:void(0)"><IMG title=难过 height=32 
                  src="8.files/19.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::shenqi::]]');" 
                  href="javascript:void(0)"><IMG title=生气 height=32 
                  src="8.files/20.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::tongku::]]');" 
                  href="javascript:void(0)"><IMG title=痛苦 height=32 
                  src="8.files/21.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::yumen::]]');" 
                  href="javascript:void(0)"><IMG title=郁闷 height=32 
                  src="8.files/22.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::daku::]]');" 
                  href="javascript:void(0)"><IMG title=大哭 height=32 
                  src="8.files/23.gif" width=32 border=0></A></TD>
                <TD><A onclick="insertSmile('[[::jingkong::]]');" 
                  href="javascript:void(0)"><IMG title=惊恐 height=32 
                  src="8.files/24.gif" width=32 
            border=0></A></TD></TR></TBODY></TABLE></DIV></TD></TR>
        <TR>
          <TD><BR><INPUT type=hidden value=do name=submit> <INPUT class=btn01 onclick=alert_login(); type=button value=发表评论 name=submit1> 
<INPUT class=btn01 type=reset value=重新填写 name=重置> 
        </TD></TR></FORM></TBODY></TABLE></TD></TR></TBODY></TABLE><BR><!--<table width="100%"  border="0" cellpadding="5" cellspacing="1" class="box_common">
			<tr valign="top">
             <td>&nbsp;</td>
           </tr>
		   <tr><td class="box_content">
		   
		 <A name="reply"></A></td>
		   </tr>
		   </table>--></TD></TR></TABLE></DIV></DIV></DIV>
<TABLE class=module_content cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD class=corner_lb>
      <DIV class=mainLayer_lb>
      <DIV class=subLayer_lb></DIV></DIV></TD>
    <TD class=corner_cb><IMG height=1 width=1></TD>
    <TD class=corner_rb>
      <DIV class=mainLayer_rb>
      <DIV class=subLayer_rb></DIV></DIV></TD></TR></TBODY></TABLE></DIV></DIV><!--底部公用文件-->
<DIV id=copyright><A href="http://www.5jia1.com/main/aboutus/?t=1" 
target=_blank>关于5jia1</A> | <A 
href="http://www.5jia1.com/personal/member/index.php?member_id=100773" 
target=_blank>客户服务</A> | <A href="http://www.5jia1.com/aboutus/?t=4" 
target=_blank>联系我们</A> | <A 
href="http://www.5jia1.com/league/index.php?gid=329849" target=_blank>意见留言板</A> 
| <A href="http://www.5jia1.com/personal/member/index.php?member_id=100773" 
target=_blank>帮助</A><BR>北京美嘉文化有限公司版权所有&nbsp;&nbsp; Copyright &copy; 2005 5jia1.com 
All rights reserved<BR>京ICP证 050254</DIV>
<SCRIPT src="8.files/urchin.js" type=text/javascript></SCRIPT>

<SCRIPT type=text/javascript>
  _uacct="UA-177986-4";
  urchinTracker();
</SCRIPT>
</CENTER><IFRAME id=hidden_frame name=hidden_frame src="about:blank" 
frameBorder=0 width=0 scrolling=no height=0></IFRAME><IFRAME marginWidth=0 
marginHeight=0 src="8.files/update_online.htm" frameBorder=0 width=0 
scrolling=no height=0></IFRAME><!--default_run//-->
<SCRIPT language=JavaScript type=text/JavaScript>

function set_comment(bid,sid)
{
	document.comment.bid.value = bid;
	document.comment.sid.value = sid;
	
}
function formsubmit()
{
	if (document.comment.content.value.trim() == "")
	{
		showAlert("评论内容不能为空!");
		document.comment.content.focus();
		return false;
	}
	var cdw = check_deny_word(document.comment) ;
	if (cdw != false)
	{
		showAlert(cdw);
		return false;
	}
	return true;
}

// 弹出收藏页面
function add_favorite(uid,url)
{
	window.open("/personal/favorite/add.php?member_id="+uid+"&url="+url,'_blank','width=400,height=220,toolbar=0,locationbar=0,menubar=0,statbar=0'); 
	return false;
}

// 提示登录
function alert_login()
{
	showAlert('对不起,您目前没有权限,请先登录!');
	document.login_form1.account.focus();
}
</SCRIPT>
</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -