解釋 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
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP