Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

section with the concatenation of several if and -The continue statement causes the program to chars.

to chars. So, this declaration would consume more


else if instructions. skip the rest of the loop in the current iteration as than 3 gigabytes of memory!
-It works in the following way: switch evaluates if the end of the statement block had been Syntax:
-Selection structures are used to perform expression and checks if it is equivalent to reached, causing it to jump to the start of the data_type array_name[array_size1][array_size2];
‘decision making‘and then branch the program constant1, if it is, it executes group of statements following iteration. Example: int grades [2][4];
flow based on the outcome of decision making. 1 until it finds the break statement. When it finds Note: The size 2 indicates the number of rows.
-Selection structures are implemented in C with it, this break statement the program jumps to the -Using break, we can leave a loop even if the The size 4 indicated the number of columns.
if else and switch statements. end of the switch selective structure. condition for its end is not fulfilled. It can be used
-if and if else statements are 2 way branching -If expression was not equal to constant1 it will be to end an infinite loop, or to force it to end before
statements whereas switch is a multi-branching checked against constant2. If it is equal to this, it its natural end.
statement. will execute group of statements 2 until a break Note: The number of pairs of curly braces with
-An if statement can be followed by an optional keyword is found, and then will jump to the end -An array is a series of elements of the same type the main curly brace indicates the number of rows
else statement, which executes when the Boolean of the switch selective structure. placed in contiguous memory locations that can of an array.
expression is false. -Finally, if the value of expression did not match be individually referenced by adding an index to a These inner curly braces must be separated by
-If the Boolean expression evaluates to true, then any of the previously specified constants (you can unique identifier. comma.
the if block will be executed, otherwise, the else include as many case labels as values you want to -An array is variable that can store multiple
block will be executed. check), the program will execute the statements values.
-C programming language assumes any non-zero included after the default: label if it exists (since it -Assume that you were asked to write a program
and non- null values as true, and if it is either zero is optional). that accept 10 student marks, calculating average
or null, then it is assumed as false value. mark, and then print a number of students that
-An if statement can be followed by an optional get more than average mark.
else if...else statement, which is very useful to test
various conditions using single if...else if -A loop structure is used to execute a certain set -Instead of using 10 variables to represent 10
statement. of actions for a predefined number of times or student marks, another technique is using one-
-When using if...else if..else statements, there are until a particular condition is satisfied. dimensional array for storing a list of marks.
few points to keep in mind : -There are 3 control statements available in C/C++ -Array is a collection of memory location that is
* An if can have zero or one else's and it must to implement loop structures: used for storing data from same type. Each
come after any else if' s. *While statement*do while statement*for memory location in array is referred by array’s
* An if can have zero to many else if's and they statement name and location memory index.
must come before the else.
* Once an else if succeeds, none of the remaining Value assignment to array’s element is same as
else if's or else's will be tested. value assign to variable.
- The structure is similar to - Assignment to array can be done element by
single selection (flowchart) element. This can be done by indicating the array
index to assign each array element value.
Syntax: array_name[index] = element_value;
Note: Remember that array always starts with the
index of 0, so the array element 2 is stored in
array grades index 1. You have to use assignment
operator (=) to assign a new value.

- The structure is -In C programming, you can create an array of


similar to double selection (flowchart) - Statements in the arrays; These arrays are known as
- multiple loop are executed first (at multidimensional arrays; Multidimensional arrays
selection on C least once, and condition is are not limited to two indices (i.e., two
- if statement tested last dimensions).
that contains other if / if - else statements -Loop is controlled by a condition, sentinel, or -They can contain as many indices as needed. But
counter be careful! The amount of memory needed for an
-The syntax of the switch statement is a bit Syntax: array rapidly increases with each dimension.
peculiar; Its objective is to check several possible For example:
constant values for an expression; Something char dictionary [100][365][24][60][60];
similar to what we did at the beginning of this -Declares an array with a char element for each
second in a dictionary, that is more than 3 billion

You might also like