C: basic

  • 1 output
#include <stdio.h>

int main()
{
    printf("Hello, world!\n");
    return 0;
}
#include <stdio.h>

int main()
{
    printf("Hello, ");
    printf("world!\n");
    return 0;
}

這兩個程序的輸出結(jié)果一樣:

Hello, world!

Each time printf() is called, printing begins at the position where the previous call to printf() left off.

  • 2 symbolic constants
#define PI 3.14159
  • 3 field width
    printf("%c%3c%5c\n", 'A', 'B', 'C');

結(jié)果:

A  B    C

The field width can be specified in a format as an integer occurring between the % and the conversion character.

  • 4 input
  scanf("%d", &x);

The format %d is matched with the expression &x, causing scanf() to interpret characters in the input stream as a decimal integer and to store the result at the address of x.

  • 5 ++/--
    int a, b, c=0, d=0;
    a=++c;
    b=d++;
    printf("a=%d, b=%d\n", a, b);

結(jié)果:

a=1, b=0
  • 6 typedef
//stdint.h
typedef int         int32_t;
  • 7 EOF
//stdio.h
/* End of file character.
   Some things throughout the library rely on this being -1.  */
#ifndef EOF
# define EOF (-1)
#endif
  • 8 continue v.s. break
    for(int i=1; i<10; ++i)
    {
        if(i%3==0)
            continue;
        printf("%d\t", i);
    }

結(jié)果:

1   2   4   5   7   8   

The continue statement causes the current iteration of a loop to stop and causes the next iteration of the loop to begin immediately.

    for(int i=1; i<10; ++i)
    {
        if(i%3==0)
            break;
        printf("%d\t", i);
    }

結(jié)果:

1   2   

The break statement causes an exit from the intermost enclosing loop or switch statement.

  • 9 condition operator
x = (y<z) ? y : z

等價于

if(y<z)
  x=y
else
  x=z
  • 10 switch
    char c='a';

    switch(c)
    {
        case 'a':
            printf("apple\n");
            break;
        case 'b':
            printf("banana\n");
            break;
        case 'c':
            printf("cat\n");
            break;
        case 'd':
            printf("dog\n");
            break;
        default:
            printf("other\n");
    }

結(jié)果:

apple
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 公司:寧波大發(fā)化纖有限公司 姓名:陸小燕 期數(shù):六項精進234期學(xué)員 組號:利他三組 [日精進打卡第28天] [知...
    牛媽牛媽閱讀 137評論 0 0
  • 引: “上陽人,上陽人, 紅顏暗老白發(fā)新。 綠衣監(jiān)使守宮門, ...
    阿憶菇?jīng)?/span>閱讀 284評論 0 1
  • 風(fēng)過留痕,雁過留聲 我在你心中留下幾分 雁過留聲,風(fēng)過留痕 像你刻在我心的傷痕 風(fēng)來過 風(fēng)又吹走了 你來過 你卻離去了
    NAMpenguin閱讀 307評論 0 0

友情鏈接更多精彩內(nèi)容