闡述C語言的重要性及其總體結構
C語言是一種通用的、過程式的、命令式的計算機程式語言。
C語言的重要性
C語言被稱為一種強大的語言,它擁有許多內建函式和操作,可以用來編寫任何複雜的程式。
通常,我們將C語言稱為中級語言。因為C編譯器結合了組合語言的功能和高階語言的特性。因此,它最適合編寫系統軟體和業務軟體包。
C程式高效且快速。
C語言具有很高的可移植性,也就是說,在一臺計算機上編寫的C程式可以在另一臺計算機上執行,只需很少(或沒有)修改。
C語言最適合結構化程式設計,使用者可以將問題分解成函式模組(或)塊。
它具有自我擴充套件的能力。
它被稱為“C”,因為它是由BCPL(Basic Combined Programming Language,基本組合程式語言)衍生而來,BCPL俗稱“B”語言。
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(){ //Syntax for addition (function has int because we are returning values for function// int sum(); int add; add = sum(); printf("Addition of two numbers is : %d",add); } int sum(){ //Declaring actual parameters// int a,b,add; //Reading User I/p// printf("Enter a,b :"); scanf("%d,%d",&a,&b); //Addition operation// add=a+b; //Returning value// return add; }
輸出
執行上述程式後,將產生以下結果:
Enter a,b :4,6 Addition of two numbers is : 10
廣告