0% found this document useful (0 votes)
2 views

Basic Syntax C

This document is a quick reference cheat sheet for the C programming language, outlining the basic syntax and structure of a C program. It compares algorithmic language syntax with C language syntax, highlighting key elements such as variable declaration, operators, input/output statements, and control structures. The cheat sheet serves as a concise guide for understanding fundamental C programming concepts.

Uploaded by

Zineb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic Syntax C

This document is a quick reference cheat sheet for the C programming language, outlining the basic syntax and structure of a C program. It compares algorithmic language syntax with C language syntax, highlighting key elements such as variable declaration, operators, input/output statements, and control structures. The cheat sheet serves as a concise guide for understanding fundamental C programming concepts.

Uploaded by

Zineb
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C quick reference cheat sheet that provides basic syntax

1. Structure of a C Program
A C program is generally presented in the following form:

pre-processor directives #include <iostream> Algorithm exo;


global declarations using namespace std; constant PI = 3.14;
const float PI = 3.14; Variable S : int;
main() int main() begin
{ {
print( "Hello world" );
local variable deceleration int S ;
statement sequences cout<<" Hello world ";
} return 0;
End.
}

Syntax of Algorithmic Language vs. C Language


Algorithmic Language C Language
Types int, real, char, Boolean int, float, char, Bool
Variables Variable idfs : Type ; Type idfs ;
Declaration Example: Variable x, y, z: int; Example: int x, y, z;

Relational Operator < > <= >= = <> < > <= >= == !=

logic Operator Or and not ||(alt+6) && !

Operator arithmetic + - * / % DIV + - * / %


Assignment  =
Statements
Input Read(list of variables); cin>>variable1 >> variable2;
Example : Read(x,y) ; Example: cin>>x >> y;
Output print("text",expression, variable); cout<<"text" << variable <<expression
Example : Print(" x= ", x, " y", y); Example : cout<<"x= " <<x <<" y= "<<y;

Code block<Begin , <Begin , End> {….}


End>
Comments /**/ /**/
algorithmic Language C Language
if (condition) then action 1 ; if (condition) action 1;
else action 2 ; endif ; else action 2;
max x ; max=x ;
if(y>max) then if(y>max)
max  y; max=y ;
endif ; cout<<" maximum : " << max ;
print("maximum : ", max) ;

if(x>y) then if(x>y) {


maxx ; max = x ;
print(“maximum : “,max); cout<<" maximum: "<< max ;
else }
maxy ; else {
print((“maximum : “, max) ; max = y ;
cout<<" maximum: "<< max ;
Endif ;
}

case choice of switch (choice)


List_val1 : action 1 ; {
List_val2 : action 2 ; case liste_val1 : action 1; break;
…. case liste_val2 : action 2; break;
List_valn : action n ; …..
otherwise : action x ; case liste_val1 : action 1; break;
Endcase ; default : action x;
}
i2 ; i= 2;
case i of switch (i)
1,2 : i2-i; {
3 : i0; case 1:
otherwise : print(" Erreur") ; case 2: i=2-i; break;
Endcase ; case 3: i=0;
default: cout<<" Error" ;
}

You might also like