渥瑞达 Linux Unix下C语言软件开发视频教程 笔记3

本文介绍了C语言的基本结构,包括如何编写和编译一个简单的C程序,解释了程序的主要组成部分如main函数、注释及屏幕输出的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Chapter 1 Getting Started

1.ASIMPLE EXAMPLE

This program prints out the message “Thisis a C program”

Example1:

#include <stdio.h>

 

int main()

{

         printf(  "This is a C Program\n" );

        

         return  0;

}

Every C program contains a function calledmain , This is the start point of the program.

#include<stdio.h> allows the programto interact with the screen, keyboard and file system of your computer. Youwill find it at the beginning of almost every C program.

Main() declares the start of the function. Whilethe two curly brackets show the start and finish of the function.

Printf(“This is a C program\n”)

Prints the words on the screen . The textto be printed is enclosed in double quotes, The \n at the end of the text tellsthe program to print a newline as part of the output.

C is case sensitive, that is, it recognizesa lower case letter and it’s upper case equivalent as being different.

 

 

Compilingin Linux

Gcc is the compiler from Gnu

$ gcc hello.c

$ gcc –o sample hello.c

The compilation will proceed silently, andmake an executable file called a.out

 

Runningin Linux

./a.out

 

Result:

This is a C program

 

 

2.Comments

Emample2:

#include <stdio.h>

 

int main()

{

         int  Counter=0; /* Initalise Counter */

         /*  a comment */

         /*

          *Another comment

          */

         return  0;

}

A comment starts with a /*and ends with*/

 

Summary:

The basic structure of a one-functionprogram i:

#include <stdio.h>

/*************************************************

 *...Heading comments...*

 *************************************************/

/*Data declaractions*/

 

int main()

{

         /*...Executable  statements...*/

         return  0;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值