
C程序是由一组协议定义的,程序员在编写代码时必须遵循这些协议。
部分
完整的程序被划分为不同的部分,如下所示:
文档部分 – 在这里,我们可以给出有关程序的命令,如作者姓名、创建或修改日期。在/* */或//之间编写的信息被称为注释行。这些行在执行时不被编译器考虑。
链接部分 – 在这个部分,包含了执行程序所需的头文件。
立即学习“C语言免费学习笔记(深入)”;
定义部分 – 在这里,定义和初始化变量。
全局声明部分 – 在这个部分,定义了可以在整个程序中使用的全局变量。
函数原型声明部分 – 这个部分提供了函数的返回类型、参数和函数内部使用的名称等信息。
主函数 – C程序将从这个部分开始编译。通常,它有两个主要部分,称为声明部分和可执行部分。
用户定义部分 – 用户可以定义自己的函数,并根据用户的需求执行特定的任务。
‘C’程序的一般形式
C程序的一般形式如下:
/* documentation section */preprocessor directivesglobal declarationmain ( ){ local declaration executable statements}returntype function name (argument list){ local declaration executable statements}
示例
以下是使用带参数但没有返回值的函数执行加法的C程序−
在线演示
#includevoid main(){ //Function declaration - (function has void because we are not returning any values for function)// void sum(int,int); //Declaring actual parameters// int a,b; //Reading User I/p// printf("Enter a,b :"); scanf("%d,%d",&a,&b); //Function calling// sum(a,b);}void sum(int a, int b){//Declaring formal parameters //Declaring variables// int add; //Addition operation// add=a+b; //Printing O/p// printf("Addition of a and b is %d",add);}
输出
你将会看到以下输出 −
Enter a,b :5,6Addition of a and b is 11
以上就是解释C语言中的不同部分的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1443541.html
微信扫一扫
支付宝扫一扫