0% found this document useful (0 votes)
11 views44 pages

Fundamental of Programming CH2

Basic of C++

Uploaded by

Bayisa Gutema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views44 pages

Fundamental of Programming CH2

Basic of C++

Uploaded by

Bayisa Gutema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Computer Programming

Department of Computer Science

Chapter Two: C++ Basic

By: Bayisa G.

09/22/2025 By: Bayisa G. ([email protected]) 1|


CHAPTER TWO
C++ Basics
 A C++ program has the following structure
 Comments, Preprocessor directives, Variable declarations, Functions ...
 C++ IDE (integrated development environments )
 These environments consist of a text editor, compiler, debugger, and other
utilities integrated into a package with a single set of menus.
 Preprocessing, compiling, linking, and even executing a program is done
with a single click of a button, or by selecting a single item from a menu.
 Common elements in programming languages:
• Key Words
• Programmer-Defined Identifiers
• Operators
• Punctuation

09/22/2025
Syntax
2
By: Bayisa G. 2
 Writing a Program
• your compiler may have its own built-in text editor, or you may be using a
commercial text editor that can produce text files
– the editor must have no word processing commands embedded in the
text.
– Eg: Notepad, Visual Studio Code, EMACS, and vi
– The files you create with your editor should be named with the
extension .CPP.
 Compiling
• Your source code file can't be executed, or run, as a program can. To turn
your source code into a program, you use a compiler.
– For example, to compile a program using the g++ compiler, use the
following command line:
– g++ <yourfile.cpp>
09/22/2025 3
By: Bayisa G. 3
 Our first C++ program
 Sample program

 Screen output
Enjoy yourself with C++!
09/22/2025 4
By: Bayisa G. 4
 #include<iostream>
• The two lines that begin the above program are directives.
• The first is a preprocessor directive, and the second is a using directive.
• The first line is not a program statement; It isn’t part of a function body and
doesn’t end with a semicolon, as program statements must.
 Recall that program statements are instructions to the computer to do something, such
as adding two numbers or printing a sentence.
• The first character is the #; this character is a signal to the preprocessor.
• A preprocessor directive, on the other hand, is an instruction to the compiler.
 A part of the compiler called the preprocessor deals with these directives before it
begins the real compilation process.
 The preprocessor directive #include tells the compiler to insert another file into your
source file.
 In effect, the #include directive is replaced by the contents of the file indicated.
 The type file usually included by #include is called a header file.
09/22/2025 5
By: Bayisa G. 5
 #include<iostream>
• The header file iostream comprises conventions for input and output
streams.
• The word stream indicates that the information involved will be treated as a
flow of data.
• This specific file (iostream) includes the declarations of the basic standard
input-output library in C++
• It is included because its functionality is going to be used later in the
program.
• It’s concerned with basic input/output operations, and contains declarations
that are needed by the cout identifier and the << operator.
• Without these declarations, the compiler won’t recognize cout and will think
<< is being used incorrectly.

09/22/2025 6
By: Bayisa G. 6
 using namespace std;
• All the elements of the standard C++ library are declared within what is
called a namespace, the namespace with the name std.
 A C++ program can be divided into different namespaces.
 A namespace is a part of the program in which certain names are recognized; outside of
the namespace they’re unknown.
 C++ uses namespaces to organize the names of program entities.
 So in order to access its functionality we declare with this expression that we will be
using these entities.
• Programs usually contain several items with unique names; Variables,
functions, and objects are examples of program entities that must have
names.
• The above directive says that all the program statements that follow are
within the std namespace.
 Various program components such as cout are declared within this namespace. If we didn’t
09/22/2025
use the using directive, we would need to add the std name to many program elements. 7
By: Bayisa G. 7
 int main()
• This marks the beginning of a function.
 A function can be thought of as a group of one or more programming statements that
collectively has a name.
• The name of this function is main, and the set of parentheses that follows the
name indicates that it is a function.
• The word int stands for “integer.”
 It indicates that the function sends an integer value back to the operating system when it
is finished executing.
• The main function is the point by where all C++ programs start their
execution, independently of its location within the source code.
• It does not matter whether there are other functions with other names defined before or
after it - the instructions contained within this function's definition will always be the first
ones to be executed in any C++ program.
• For that same reason, it is essential that all C++ programs have a main
09/22/2025 function. 8
By: Bayisa G. 8
 int main()
• The main function can be made to return a value to the operating system.
• The word main is followed in the code by a pair of parentheses (()).
• That is because it is a function declaration: In C++, what differentiates a
function declaration from other types of expressions are these parentheses
that follow its name.
• Right after these parentheses we can find the body of the main function
enclosed in braces ({ }).
• The opening curly brace “{“signals the beginning of the main function body and
the corresponding closing curly brace “}” signals the end of the main function
body.
• Every opening curly brace needs to have a corresponding closing curly brace.
• The lines we find between the braces are statements or said to be the body of
the function and everything between the two braces is the contents of the
function main.
09/22/2025 9
By: Bayisa G. 9
 cout << "Enjoy yourself with C++!";
• A statement is a computation step which may produce a value or interact
with input and output streams.
• The end of a single statement ends with semicolon (;).
• The statement in the above example causes the string “Enjoy yourself
with C++!” to be sent to the “cout” stream which will display it on the
computer screen.
• To send data to standard output, you use the output operator <<
• With iostream objects, the operator << means “send to.”
• For example: cout << "yes!"; sends the string “yes!” to the object called cout
(which is short for “console output”).
• cout represents the standard output stream in C++
• cout is declared in the iostream standard file within the std namespace, so
that's why we needed to include that specific file and to declare that we were
going to use this specific namespace earlier in our code.
09/22/2025 10
By: Bayisa G. 10
 return 0;
• The return statement causes the main function to finish.
• return may be followed by a return code (in our example is followed by the
return code 0).
• An exit code of 0 for the main function is generally interpreted as the
program worked as expected without any errors during its execution.
 The value 0 usually indicates that a program executed successfully.
• This is the most usual way to end a C++ console program.
• The last line of the program contains the closing brace: “}”
• This brace marks the end of the main function.
• Because main is the only function in this program, it also marks the end of
the program.

09/22/2025 11
By: Bayisa G. 11
Input/Output Streams
 In C++, I/O is a sequence of bytes, called a stream, from the source to the
destination.
 Therefore, a stream is a sequence of characters from the source to the
destination.
 There are two types of streams:
• Input stream: A sequence of characters from an input device to the computer.
• Output stream: A sequence of characters from the computer to an output device.
 Recall that the standard input device is usually the keyboard, and the standard
output device is usually the screen.
 To receive data from the keyboard and send output to the screen, every C++
program must use the header file iostream.
 This header file contains, among other things, the definitions of two data types,
istream (input stream) and ostream (output stream).
• The header file also contains two variable declarations, one for cin (pronounced ‘‘see-in’’),
which stands for console input, and one for cout (pronounced ‘‘see-out’’), which stands for
console output.
09/22/2025 12
By: Bayisa G. 12
Input/Output Streams
 These variable declarations are similar to the following C++ statements:
istream cin;
ostream cout;
To use cin and cout, every C++ program must use the preprocessor directive:
#include <iostream>
 Because cin and cout are already defined and have specific meanings, to avoid
confusion, you should never redefine them in programs.
 The variable cin has access to operators and functions that can be used to
extract data from the standard input device.
 You have briefly used the extraction operator >> to input data from the
standard input device.
 Recall that the syntax of cout when used together with the insertion operator <<
is:
cout << expression or manipulator << expression...;
• Here, expression is evaluated, its value is printed, and manipulator is used to format the
09/22/2025 13
output.
By: Bayisa G. 13
Comment
 A comment is a piece of descriptive text which explains some aspect of a
program.
 Program comments are text totally ignored by the compiler and are only
intended to inform the reader how the source code is working at any particular
point in the program.
 C++ provides two types of comment delimiters:
 Single Line Comment: Anything after // {double forward slash} (until the end
of the line on which it appears) is considered a comment.
• Eg: cout << var1; //this line prints the value of var1
 Multiple Line Comment: Anything enclosed by the pair /* and */ is considered
a comment.
• Eg: /* this is a kind of comment where
Multiple lines can be enclosed in one
C++ program */
09/22/2025 14
By: Bayisa G. 14
 Look at the following program Single line
comment

Multi line
comment

 The output of above program is

09/22/2025 15
By: Bayisa G. 15
 Identifiers
 The name of a variable (or other item you might define in a program) is called an
identifier.
 A valid identifier is sequence of one or more letters, digits, and underscore
characters that does not begin with a digit
 identifiers that begin with underscore (in many cases) or contain double
underscores are reserved for use by C++ implementation and should be avoided
 An identifier should be very descriptive and relate to the data it stores.
 For example, a variable to store the grade of a student in a class could be
named studentGrade.
 Here are some specific rules that must be followed with all identifiers.
 The first character must be one of the letters a - z, A - Z, or an underscore character (_).
 After the first character you may use the letters a - z or A - Z, the digits 0 -9, or underscores.
 C++ is case sensitive, i.e., uppercase and lowercase characters are distinct. Example
RESULT is not the same as Result nor result.
 Examples of valid variable names: dayOfWeek, _employee_num, June1997, Profit95,...
 Examples of invalid variable names: 3dGraph, Mixture#3, days-in-year, throw, ...
09/22/2025 16
By: Bayisa G. 16
Keywords (reserved words)
 There is a special class of identifiers, called keywords or reserved words
 Reserved/Key words have a unique meaning within a C++ program.
 These symbols, the reserved words, must not be used for any other purposes.
 All reserved words are in lower-case letters.
 The following are some of the reserved words of C++:

09/22/2025 17
By: Bayisa G. 17
 Whitespaces
 Every C++ program contains whitespaces
 Include blanks, tabs, and newline characters
 Used to separate special symbols, reserved words, and identifiers
 Proper utilization of whitespaces is important
 Can be used to make the program readable
 Whitespaces are nonprintable

Statements
 A statement is an instruction to the computer to perform an action.
 A statement may contain keywords, operators, programmer-defined identifiers,
and punctuation.
 A statement may fit on one line, or it may occupy multiple lines.
 Here is a single statement that uses two lines:
double num1 = 5,
num2, sum;
09/22/2025 18
By: Bayisa G. 18
 Fundamental Data Types
 When programming, we store the variables in our computer's memory
 The computer must know what we want to store in them since storing a simple
number, a letter or a large number is not going to occupy the same space in
memory.
 Since a computer uses different methods for processing and saving data, the
data type must be known.
 The type defines
a) the internal representation of the data, and
b) the amount of memory to allocate
 Several data types are built into C++.
 They can be conveniently classified as integer, floating-point or character
variables.
 Floating-point variable types can be expressed as fraction i.e. they are “real
numbers”.boolean, character, and (signed and unsigned) integer types
collectively called integral types
09/22/2025 19
By: Bayisa G. 19
 Fundamental Data Types

09/22/2025 20
By: Bayisa G. 20
 Signed vs Unsigned Integer
 Both integral and floating-point numbers are represented internally as binary
numbers, that is, as sequences of 0 and 1 values.
 However, the formats for representing integral and floating-point numbers differ.
 The binary format of integers is basically the same for the char, short, int and
long types and differs only in
• the number of bytes available for each type and
• whether the number is interpreted as signed or unsigned.
 The bit-pattern of a positive integer can be represented as a base 2 power
series.
 The sign bit 0 additionally indicates that the number is positive in the case of
signed types
 The number 4 can be represented by the following power series:
(0 * 20) + (0 * 21) + (1 * 22) + (0 * 23) + (0 * 24)...
 The binary representation of the number 4 as signed char type value (8 bits) is
thus as follows:
09/22/2025 21
By: Bayisa G. 21
 Signed vs Unsigned Integer

 Two’s complement is used to represent a negative number, for example - 4:


1 1 1 1 1 1 0 0 (unsigned value of 252)
 Sign bits are not required for unsigned types.
 The bit can then be used to represent further positive numbers, doubling the
range of positive numbers that can be represented.
Binary Signed decimal Unsigned decimal Binary Signed decimal Unsigned decimal
0000 0000 0 0 1000 0000 –128 128
0000 0001 1 1 1000 0001 –127 129
0000 0010 2 2 ... ... ...
... ... ... 1111 1110 –2 254
0111 1111
09/22/2025 127 127 1111 1111 –1 255 22
By: Bayisa G. 22
 Expressions
 An expression is any computation which yields a value.
 When discussing expressions, we often use the term evaluation.
 C++ provides operators for composing arithmetic, relational, logical, bitwise, and
conditional expressions.
 It also provides operators which produce useful side effects, such as
assignment, increment, and decrement.
 E.g. the statement 3 + 2; returns the value 5 and thus is an expression.
• 3.2 returns the value 3.2
• PI float constant that returns the value 3.14 if the constant is defined.
• secondsPerMinute integer constant that returns 60 if the constantis declared
• x = a + b;
• y = x = a + b;
 The second line is evaluated in the following order:
1. add a to b.
2. assign the result of the expression a + b to x.
09/22/2025
3. assign the result of the assignment expression x = a + b to y. 23
By: Bayisa G. 23
 Literals
 Literals are constant values, such as 1 or 3.14159.
 literal constant is value written exactly as it is meant to be interpreted
 Example of literals:

 Character literals are written between single quotes. Special characters can be
represented with the backslash character \
 String literals are stored as a series of characters terminated with the null
character, whose value is 0.
09/22/2025 24
By: Bayisa G. 24
 Character Literals
 Character literal consists of optional prefix followed by one or more characters
enclosed in single quotes
 Nonprintable characters are represented using escape sequences. Example:
• '\n' new line
• '\r' carriage return
• '\t' horizontal tab
• '\v' vertical tab
• '\b' backspace
• '\f' formfeed
• '\a' alert
 Single and double quotes and the backslash character can also use the escape
notation:
• '\'' // single quote (')
• '\"' // double quote (")
• '\\' // backslash (\)
09/22/2025 25
By: Bayisa G. 25
 Character Literals
 Character literal consists of optional prefix followed by one or more characters
enclosed in single quotes

 Output:
This is a string
09/22/2025
with "many" escape sequences! 26
By: Bayisa G. 26
 Declaration of Variables
 In order to use a variable in C++, we must first declare it specifying which of the
data types above we want it to be.
 The syntax to declare a new variable is to write the data type specifier that we
want (like int, short, float...) followed by a valid variable identifier.
 For example:
int a;
float mynumber;
 The first one declares a variable of type int with the identifier a.
 The second one declares a variable of type float with the identifier mynumber.
 If you need to declare several variables of the same type:
int a, b, c;
 This declares three variables (a, b and c) of type int , and has exactly the same
meaning as if we had written:
int a;
int b;
int c;
09/22/2025 27
By: Bayisa G. 27
 Declaration of Variables
 Integer data types (char, short, long and int) can be signed or unsigned
according to the range of numbers that we need to represent.
 Thus to specify an integer data type we do it by putting the keyword signed or
unsigned before the data type itself. For example:
unsigned short NumberOfSons;
signed int MyAccountBalance;
 By default, if we do not specify signed or unsigned it will be assumed that the
type is signed
 thus in the second declaration we could have written:
int MyAccountBalance;
 Finally, signed and unsigned may also be used as a simple types, meaning the
same as signed int and unsigned int respectivelly.
 The following two declarations are equivalent: unsigned MyBirthYear; &
unsigned int MyBirthYear;
09/22/2025 28
By: Bayisa G. 28
 Initialization of Variables
 When declaring a local variable, its value is undetermined by default.
 But you may want that a variable stores a concrete value since the moment in
which it is declared.
 In order to do that, you have to append an equal sign followed by the value
wanted to the variable declaration:
type identifier = initial_value;
 For example, if we want to declare an int variable called a that contains the
value 10 since the moment in which it is declared, we could write:
 int a = 10;

09/22/2025 29
By: Bayisa G. 29
 Operating with variables
#include <iostream>
using namespace std;
int main ()
{
int a, b; // declaring two variables: a, b of type int
int result; // declaring result variables of type int
a = 5;
b = 2;
a = a + 1;
result = a - b;
cout << result; // print out the result:

return 0; // terminate the program:


}
 The output of the above program is 4

09/22/2025 30
By: Bayisa G. 30
Assignment operator
 The assignment operator causes the operand on the left side of the assignment
statement to have its value changed to the value on the right side of the
statement.
 In C++, = is called the assignment operator.
 Syntax: Operand1 = Operand2;
 Operand1 is always a variable
 Operand2 can be one or combination of:
• A literal constant: Eg: x = 12;
• A variable: Eg: x = y;
• An expression: Eg: x = y+2;
 Example num = num + 2; means ‘‘evaluate whatever is in num, add 2 to it,
and assign the new value to the memory location num.’’
 The expression on the right side must be evaluated first; that value is then assigned to the
memory location specified by the variable on the left side. Thus, the sequence of C++
statements:
num = 6;
09/22/2025 31
num = num + 2;
By: Bayisa G. 31
Assignment operator
 Example:
int num1, num2;
double sale;
char first;
string str;
num1 = 4;
cout << "num1 = " << num1 << endl;
num2 = 4 * 5 - 11;
Sample Run:
cout << "num2 = " << num2 << endl;
num1 = 4
sale = 0.02 * 1000; num2 = 9
cout << "sale = " << sale << endl; sale = 20
first = 'D'; first = D
cout << "first = " << first << endl; str = It is a sunny
day.
str = "It is a sunny day.";
cout << "str = " << str << endl;
09/22/2025 32
By: Bayisa G. 32
Arithmetic Operators
 You can use the standard arithmetic operators to manipulate integral and
floating-point data types.
 There are five arithmetic operators.
• + (addition), - (subtraction or negation), * (multiplication), / (division), % (mod, (modulus or
remainder))
 You can use the operators +, -, *, and / with both integral and floating-point data
types.
 You use % with only the integral data type to find the remainder in ordinary
division.
 When you use / with the integral data type, it gives the quotient in ordinary
division.
 That is, integral division truncates any fractional part; there is no rounding.
 Unary operator: An operator that has only one operand.
 Binary operator: An operator that has two operands.
• - and + are both unary and binary arithmetic operators. However, as arithmetic operators,
*, /, and % are binary and so must have two operands.
09/22/2025 33
By: Bayisa G. 33
Arithmetic Operators
 2+5 7
 13 + 89 102
 34 – 20 14
 45 – 90 - 45
 2*7 14
 5/2 2 In the division 5 / 2, the quotient is 2 and the
remainder is 1. Therefore, 5 / 2 with the integral operands
evaluates to the quotient, which is 2.
 14 / 7 2
 34 % 5 4 In the division 34 / 5, the quotient is 6 and the
remainder is 4. Therefore, 34 % 5 evaluates to the remainder,
which is 4.
 4%6 4 In the division 4 / 6, the quotient is 0 and the
remainder is 4. Therefore, 4 % 6 evaluates to the remainder,
09/22/2025
which is 4. 34
By: Bayisa G. 34
Relational Operators
 In C++, a condition is represented by a logical (Boolean) expression.
 An expression that has a value of either true or false is called a logical (Boolean)
expression.
 Moreover, true and false are logical (Boolean) values.
 In order to evaluate a comparison between two expressions, we can use the
relational operator.
• == (equal), != (not equal), < (less than), <= (less than or equal), > (greater than), >= (greater
than or equal)
 The result of a relational operator is a bool value that can only be true or false
according to the result of the comparison.
 E.g.: (7 == 5) would return false or returns 0
(5 > 4) would return true or returns 1
 The operands of a relational operator must evaluate to a number.
 Characters are valid operands since they are represented by numeric values.
 For E.g.:
‘A’ < ‘F’ would return true or 1. it is like (65 < 70)
09/22/2025 35
By: Bayisa G. 35
The ASCII character set

09/22/2025 36
By: Bayisa G. 36
Relational Operators
 Example
8 < 15 8 is less than 15 true
6 != 6 6 is not equal to 6 false
6 <= 6 6 is less than or equal to 6 true
2.5 > 5.8 2.5 is greater than 5.8 false
5.9 <= 7.5 5.9 is less than or equal to 7.5 true
 Now, because 32 < 97, and the ASCII value of ' ' is 32 and the ASCII value of
'a' is 97, it follows that ' ' < 'a' is true. Similarly, using the previous ASCII
values:
'R' > 'T' is false '+' < '*' is false 'A' <= 'a' is true
• Note that comparing values of different data types may produce unpredictable results.
• For example, the following expression compares an integer and a character:
8 < '5'
• In this expression, on a particular machine, 8 would be compared with the collating
sequence of '5', which is 53.
• That is, 8 is compared with 53, which makes this particular expression evaluate to true.
09/22/2025 37
By: Bayisa G. 37
Logical (Boolean) Operators
 Logical (Boolean) operators enable you to combine logical expressions.
• ! (boolean negation or not), && (and), || (or)
 Logical negation (!) is a unary operator, which negates the logical value of its
operand. If its operand is non zero, it produce 0, and if it is 0 it produce 1.
 Logical AND (&&) produces 0 if one or both of its operands evaluate to 0
otherwise it produces 1.
 Logical OR (||) produces 0 if both of its operands evaluate to 0 otherwise, it
produces 1.
 Example
!20 //gives 0
10 && 5 //gives 1
10 || 5.5 //gives 1
10 && 0 // gives 0
 N.B. In general, any non-zero value can be used to represent the logical true,
whereas only zero represents the logical false.
09/22/2025 38
By: Bayisa G. 38
Logical (Boolean) Operators
 Example
• !('A' > 'B') true Because 'A' > 'B' is false, !('A' > 'B') is true.
• !(6 <= 7) false Because 6 <= 7 is true, !(6 <= 7) is false.
• (14 >= 5) && ('A' < 'B') true Because (14 >= 5) is true, ('A' < 'B') is
true, and true && true is true, the expression evaluates to true.
• (24 >= 35) && ('A' < 'B') false Because (24 >= 35) is false, ('A' < 'B')
is true, and false && true is false, the expression evaluates to false.
• (14 >= 5) || ('A' > 'B') true Because (14 >= 5) is true, ('A' > 'B') is
false, and true || false is true, the expression evaluates to true.
• (24 >= 35) || ('A' > 'B') false Because (24 >= 35) is false, ('A' > 'B') is
false, and false || false is false, the expression evaluates to false.
• ('A' <= 'a') || (7 != 7) true Because ('A' <= 'a') is true, (7 != 7) is
false, and true || false is true, the expression evaluates to true.

09/22/2025 39
By: Bayisa G. 39
Compound Assignment Operators
 Compound assignment operator is the combination of the assignment operator
with other operators like arithmetic and bit wise operators.
 The assignment operator has a number of variants, obtained by combining it
with other operators.
 +=, -=, *=, /=, %=...
 Example
• value += increase; is equivalent to value = value + increase;
• a -= 5; is equivalent to a = a – 5;
• a /= b; is equivalent to a = a / b;
• price *= units + 1 is equivalent to price = price * (units + 1);
 And the same is true for the rest.

09/22/2025 40
By: Bayisa G. 40
Increment/Decrement Operators
 The auto increment (++) and auto decrement (--) operators provide a convenient
way of, respectively, adding and subtracting 1 from a numeric variable.
 Example:
• if a was 10 and if a++ is executed then a will automatically changed to 11
 Prefix and Postfix
 The prefix type is written before the variable. E.g. (++ myAge), whereas the
postfix type appears after the variable name (myAge ++).
 Prefix and postfix operators can not be used at once on a single variable: E.g.:
++age-- or --age++ or ++age++ or - - age - - is invalid
 Example
• int k = 5;
• y = ++k + 10; //gives y == 16
• y = k++ + 10; //gives y == 15
• y = --k + 10; //gives y == 14
• y = k-- + 10; //gives y == 15
09/22/2025 41
By: Bayisa G. 41
Operator Precedence
 The order in which operators are evaluated in an expression is significant and is
determined by precedence rules.
 Operators in higher levels take precedence over operators in lower levels.
1. [ ] ( ) (Array indexing & function call) Highest precedence
2. ++ – – (postfix)
3. ++ – – ! (prefix & negation)
4. * / % (Multiply, divide and remainder (modulo))
5. + − (Addition & subtraction)
6. << >> (Insertion & extraction operator)
7. < <= > >=
8. == !=
9. & ^ |
10. &&
11. ||
12. = += −= *= /= etc. Lowest precedence
09/22/2025 42
By: Bayisa G. 42
Operator Precedence
 Example:
a == b + c * d
 c * d is evaluated first because * has a higher precedence than + and = =.
 The result is then added to b because + has a higher precedence than = =
 And then == is evaluated.
 Precedence rules can be overridden by using brackets.
 Example:
 Rewriting the above expression as:
a = = (b + c) * d causes + to be evaluated before *.
 Operators with the same precedence level are evaluated in the order specified
by the column on the table of precedence rule.
 Example:
a = b += c the evaluation order is right to left, so the first b += c is
evaluated followed by a = b.
09/22/2025 43
By: Bayisa G. 43
THE END
THANK YOU!

«NEXT»
ΞControl Statements

Kenesa B. 44

You might also like