卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16333本站已运行3317

解释C语言中的不同部分

解释C语言中的不同部分

C程序是由一组协议定义的,程序员在编写代码时必须遵循这些协议。

部分

完整的程序被划分为不同的部分,如下所示:

  • 文档部分 - 在这里,我们可以给出有关程序的命令,如作者姓名、创建或修改日期。在/* */或//之间编写的信息被称为注释行。这些行在执行时不被编译器考虑。

  • 链接部分 - 在这个部分,包含了执行程序所需的头文件。

  • 定义部分 - 在这里,定义和初始化变量。

  • 全局声明部分 - 在这个部分,定义了可以在整个程序中使用的全局变量。

  • 函数原型声明部分 - 这个部分提供了函数的返回类型、参数和函数内部使用的名称等信息。

  • 主函数 - C程序将从这个部分开始编译。通常,它有两个主要部分,称为声明部分和可执行部分。

  • 用户定义部分 - 用户可以定义自己的函数,并根据用户的需求执行特定的任务。

'C'程序的一般形式

C程序的一般形式如下:

/* documentation section */
preprocessor directives
global declaration
main ( ){
   local declaration
   executable statements
}
returntype function name (argument list){
   local declaration
   executable statements
}

示例

以下是使用带参数但没有返回值的函数执行加法的C程序−

在线演示

#include<stdio.h>
void 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,6
Addition of a and b is 11

卓越飞翔博客
上一篇: 如何在PHP中防止敏感数据泄露与非法访问?
下一篇: PHP报错:使用非法数字作为常量名的解决方法!
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏