A sample C program

A sample C program

Write an example to help us get started with C.

/* first.c -- The first program */
#include <stdio.h> // preprocessor directive
int main(void) // function, first be called
{ // function define start
    int num; // declaration, int -- keyword, num -- ifentifier
    num = 1; // Assignment expression statement

    printf("I am a simple "); // function call, "I am a simple " -- actual argument
    printf("computer.\n"); // function call, main() is calling function for printf() 
    printf("My favorite number is %d becase it is first.\n", num); // function reference, \n is newline character, newline character is a escape sequence

    return 0; // jump statement
} // function define end

sample analysis

在这里插入图片描述

second sample

/* m2cm.c -- from m to cm */
#include <stdio.h>
int main(void)
{
    int metre, centimetre;

    metre = 2;
    centimetre = metre * 100;
    printf("There are %d centimetres in %d metres!\n", centimetre, metre);
    printf("yes, I said %d centimetres!\n", 100 * metre);

    return 0;
}

third sample

/* two_func.c -- One source code file include two functions. */
#include <stdio.h>
void butler(void); // prototype
int main(void)
{
    printf("I will summon the butler function.\n");
    butler(); // function call
    printf("Yes, Bring me some tea and writeable DVDs.\n");

    return 0;
}

void butler(void) // function definition
{
    printf("You rang, sir?\n");
}

???

What is the basic unit of C language program?
:function

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值