C Language Variables and Instructions Guide
C Language Variables and Instructions Guide
simple
Module: C Language
Course led by [Link]
1
I. Notion of variable
1- Definition:
A variable is a memory cell or a set of memory cells.
able to contain a data of a certain type at a given time.
2- Declaration:
Declaring a variable is done as follows:
Type name [= initial value];
3- Exemples:
Int x; int y=5; char a, b;
2
I. Notion of variable
With
Type: the type of the variable that can be:
Int or long: Integer, this type is designed to hold values
whole.
Char: Character, this type is designed to hold a character.
Float or Double: Real, this type is designed to hold values
real.
Or other types of course.
3
I. Notion of variable
Remarks:
The semicolon marks the end of each instruction, so it is mandatory;
Initializing a variable upon declaration is not mandatory;
The C language is case-sensitive, so uppercase and lowercase letters
are different;
The keyword unsigned specifies that the value that will be contained by the variable
a positive serum;
A variable can be declared anywhere in the program and
no to a well-reserved place.
4
II. Notion of constant
1- Definition:
Is a variable whose value remains unchanged during execution of the
program.
2- Declaration:
Const type name = value;
3- Example:
Const int x=3;
5
III. The comments
A comment starts with /* and ends with */.
For example, /* This is a comment */
6
IV. The assignment instruction
In C, assignment is a full-fledged operator. It is symbolized
by the sign =.
Its syntax is as follows:
variable=expression;
Example:
I = 5;
X = i + 1;
7
V. The display instruction
1-Displaying simple text:
for this, we use the following syntax:
Print("Text to display");
2- Displaying the value of a variable:
We display the value of a variable according to the following instruction:
Print("Symbol", variable_name);
The symbol is made up of the sign '%' followed by a letter referring to the
type of the variable whose value we need to display.
8
V. The display instruction
Example:
Symbol(%letter) Corresponding type
%d Int
%c character
%lf Long double
%ld Long int
%u Unsigned int in decimal
%o Unsigned int in octal
%x Unsigned int in hexadecimal
9
V. The display instruction
Combined display between text and value:
Just combine the two types of displays and you get the display.
heterogeneous.
10
V. The display instruction
Remarks:
We can display multiple variable values at the same time as follows:
And we can combine the display of multiple variable values with text.
We have the following special characters:
new line carriage return
horizontal tabulation Page break
• vertical tabulation a warning signal
backward
11
VI. The reading instruction
It corresponds to assigning a value to a variable.
This operation is carried out using the following instruction:
We can read several values from several variables of different types such as
suit
SCANF ("%letter1 %letter2 %letter_n", &var1, &var2, .., &var_n);
Note: The space between variables is important.
12
VI. Reading instruction
Examples:
printf("Displaying i: \n");
printf("%d \t %u \t %o \t %x", i, i, i, i);
13
VII. The Arithmetic and Logical Operators
Operators Explanation
Arithmetic The addition '+'
The subtraction '-'
These are the basic arithmetic operations
The Multiplication '*'
The division '/'
The Module ‘%’ It returns the remainder of the integer division of the first operand by the second.
!= It verifies whether the value on the left is different from the value on the right.
! Non-logic allows for obtaining the negation of an expression.
Logics && The 'et' logic allows the conjunction of two expressions.
|| The or logic allows the disjunction of two expressions. 14
VII. The Arithmetic and Logical Operators
Note:
There are mathematical functions that we often use, but first we need to call upon the
math.h library through the include directive <math.h>, these functions are:
Function Explanation
fabs It takes a single variable or value as a parameter and returns its integer value.
Pow It takes two parameters in the following form pow(number, power) and returns as
result the power of the number.
The functions They are the known trigonometric functions, they take a number of parameters such that they
trigonometric are mathematically defined and they are mainly (sin, cos, tan, arcsin....).
The other functions Also known are the other mathematical functions that one might want to use,
same thing for the parameters and they are (exp, log, log10, ………..).
15
VII. The Arithmetic and Logical Operators
There are also shortcuts for writing certain operations such as
what:
Operation Explanation
decrement We subtract 1 from the value of the variable and write: variable--
arithmetic operations Var1 operation=Var2, here one of the operands receives the result.
17