国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

C語言菜鳥基礎教程之判斷

2020-01-26 13:53:43
字體:
來源:轉載
供稿:網友

(一)

先動手編寫一個程序:

#include <stdio.h>int main(){  if(1)  {    printf("The condition is true!/n");  }   return 0;}

運行結果:

The condition is true!

再把1依次改為,2,5,100,-10,發現運行結果完全一樣。
再改成if(0),此時發現沒有運行結果,說明printf()語句沒被執行。

C語言把判斷語句中的任何非0或非空的值當作真。所以if(1), if(2), if(5), if(100), if(-10)的效果是一樣的。

(二)

再編寫一個程序:

#include <stdio.h>int main(){  int a = 100;  if(a > 0)  {    printf("The condition value is %d/n", (a > 0));  }   return 0;}

運行結果:

The condition value is 1

分析:
a = 100,a > 0成立 ,所以if( a > 0)等價于if(1)。
在C語言中,判斷語句是有值的,要么為1,要么為0。比如本程序中a > 0的值就是1。

(三)

最后編寫一個程序:

#include <stdio.h>int main(){  char c1 = '/0';  if(c1)  {    printf("The condition is true!/n");  }  else  {    printf("The condition is false!/n");  }    char c2 = ' ';  if(c2)  {    printf("The condition is true!/n");  }  else  {    printf("The condition is false!/n");  }    char c3 = 'A';  if(c3)  {    printf("The condition is true!/n");  }  else  {    printf("The condition is false!/n");  }    return 0;}

運行結果:

The condition is false!The condition is true!The condition is true!

說明:C語言中用'/0'來表示空字符??崭? ‘也是一個字符,這從if(c2)條件為真就可以看出來。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 屯昌县| 水富县| 米脂县| 大理市| 罗甸县| 湖北省| 赣榆县| 同德县| 商河县| 北海市| 共和县| 望城县| 德庆县| 兴安县| 壶关县| 沙湾县| 彩票| 临潭县| 德江县| 桓台县| 勐海县| 赣榆县| 宁德市| 福贡县| 文水县| 鄂温| 安阳市| 蓬安县| 西盟| 常山县| 沂南县| 秭归县| 平江县| 台山市| 松阳县| 临潭县| 临潭县| 上林县| 西乌珠穆沁旗| 扎赉特旗| 三门县|