Introduction to Structured Programming
Introduction to Structured Programming
STRUCTURED.
3.1 INTRODUCTION TO THE PROGRAMMING OF A LANGUAGE
STRUCTURED.
In 1995, Edger W. Dijkstra published the principles of structured programming in his
book 'Notes on Structured Programming', with these notes as the axis, C. Boehm and G.
Jacopini established in 1996 a programming language that would be used as a basis
for most of the development platforms known today,
C language.
The basic concept of structured programming consists of the basic formation of
programming text (programming statements) that when read, can explain the
operation of a program. A sequential program must comply with the following
characteristics:
Process box.
Binary decision.
Repeating mechanism.
Program.
Which states the actions to be taken to satisfy a need and must comply with
the following characteristics:
All functions contain instructions that are executed when the program does
an explicit call to the corresponding function. The functions contain statements
of the variables and definitions of the constants that are used within them.
The program begins by executing the first instruction of the main function.
which establishes its path or logical origin of execution. For this, in the body of the
The main function includes instructions and/or calls to the rest of the functions defined.
in the program.
For example, the general structure of a program written in C would be as follows
shape:
[Link] files.
They are files that include the declaration (association of a data type) of the
variables, constants, and other functions used in the program.
2. Global statements.
Declarations of variables and constants that can be used by all the
functions of the program.
3. Local declarations.
Variable and constant declarations that can only be used within
a determined function.
4. Type fi (list of parameters).
Type: It is the data type of the result that the function provides.
Fi: It is the name of the function i.
•Parameter list: It is the list of parameters or input variables used by the
function. It constitutes the declaration of one or several variables, which function as
local variables.
5. Instructions.
Instructions or statements that are part of the functions. The dot symbol and
a semicolon (;) at the end of a line identifies it as a statement or instruction
of the C language. To make the program easily intangible, it is advisable to write
each instruction on one line.
6. Main type (parameter list).
Definition of the main function of the program: The development tools
often include standard function libraries or
normalized, so that users do not have to program them.
The result would be as follows:
Hello world in C Language
#include <stdio.h> Header
void main() Main function
{
printf("Hello world"); Instructions
}
3.3 TYPES OF DATA.
There are two types of data to be used during a program, variables and constants. The
Variables are a type of data whose value can change over a
Program, constants are the data types that throughout the program remain.
I integrate its contained value.
The type of value that resides in the variable or constant is a way to represent
information for which a memory space is reserved, in accordance with its
Characteristics. The data that a computer processes is classified into simple and
Structured. The main characteristic of simple data types is that they occupy only
a memory cell. Within this group of data are mainly the
integers, real numbers, and characters. The use of memory depends on the correct
selection of the data type assigned to the variables of a program, because in some
In such cases, it usually does not have a high-capacity data or program memory.
In the C language, the five basic data types are defined:
3.4 IDENTIFIERS.
Identifiers (IDs) are lexical symbols that name entities. The concept is
analogous to "information processing names". Naming the entities makes
It may refer to the same, which is essential for any type of processing.
symbolic.
In programming languages, identifiers are textual elements (also
called symbols) that name entities of the language. Some of the entities that
an identifier can denote variables, constants, data types,
labels, subroutines (procedures and functions), and packages.
In many languages, some sequences have the lexical form of an identifier but
they are known as keywords (or reserved words). It is common that if a
the identifier corresponds to a keyword or reserved word, it can no longer
used to refer to other types of entities such as variables or constants (in some
in a few languages, like PL/1, this distinction is not entirely clear.
Programming languages typically impose restrictions on what characters can be used.
appear in an identifier. For example, in the early versions of C and C++, the
identifiers are restricted to be a sequence of one or more letters
ASCII, numeric digits (which should never appear as the first character) and
underscores. Later versions of these languages, as well as many others
modern languages support almost all Unicode characters in an identifier. A
a common restriction is that the use of whitespace or operators is not allowed
of the language.
The main memory of the computer is divided into small units of size
uniform denominated words what they have one address unique.
Each of these words is capable of storing a unit of information (such as,
for example, numerical results), and determines the largest and smallest number
what it can store.
The size of the word depends on the computer, but it is always specified in
multiples of 8 bits. Thus, there are computers with word sizes of 8, 16, 32, and 64
bits. Each word in the main memory has a fixed address that ranges from zero to the
total number of words - 1. Memory addresses are used to identify each
word individually, in such a way that the data contained in it can be accessed. To A
in order to simplify its understanding, memories are considered as a row of
words.
Memory representation
In the case of numerical data, it is necessary to consider the distinction between numbers.
negatives and positives, and the difference between floating point numbers and integers. The signs
they are normally managed by the most significant bit of the word (the one located at the
extreme left), and it is called the sign bit. When the sign bit stores a
zero, the number is considered positive; when it stores a one the number is negative.
This is why, if the word size is m bits, there are m-1 bits left to represent.
the magnitude of the stored number. Floating point numbers are handled in
logarithmic format, with a fixed number of bits for the base and another for the mantissa. The
The standard for floating-point numbers is set by IEEE. Due to the logarithmic format,
The calculations made with floating point types are not as accurate as those that are
they are done with integer types.
They are based on the Multimedia Card (MMC) format. The cards
marked as HC (High Capacity) operate at high speed and have
very high data transfer rates; some cameras
digitals require this type of cards to be able to record video with
fluency or to capture multiple photographs in rapid succession.
Starmedia.
Memory Stick.
The equal sign, "=", in a=b means assigning to the variable a the value that results from
evaluate the allowed expression b. That is, a=b has the meaning a b, which is not the same.
definition used in mathematics for '='.
The same as in other programming languages, in C there are operators.
most common arithmetic (+ addition, - subtraction, * multiplication, / division and % modulo).
The assignment operator is =, for example: i=4; ch='y'; Increment ++ and decrement --
unary. Which are more efficient than the respective assignments.
For example: x++ is faster than x=x+1. The ++ and -- operators can be prefix or
postfix. When they are prefixes, the value is calculated before the expression is
evaluated, and when it is postfix the value is calculated after the expression is
evaluated.
In the following example, ++z is prefix and -- is postfix:
int x,y,z;
main()
{
x=( ( ++z ) - ( y-- ) ) % 100;
}
What is equivalent to:
int x,y,z;
main()
{
z++;
x = ( z - y ) % 100;
y--;
}
The operator % (modulus or remainder) only works with integers, although there is a
function for floats (15.1 mod () ) from the math library.
The division operator / is for integer and floating-point division. Therefore, one must be careful.
careful. The result of x = 3 / 2; is one, even if x is declared as float. The rule is: if
both arguments in a division are integers, then the result is an integer. If you
wants to obtain the division with the fraction, then write it as: x = 3.0 / 2; or x = 3 /
2.0 and even better x = 3.0 / 2.0.
On the other hand, there is a shorter way to express calculations in C. For example, if you
they have expressions like: i = i + 3; or x = x * (y + 2);
Program execution.
The next step is to run the executable program. To run an executable in UNIX,
simply write the name of the file that contains it, in this case program (or
[Link]). With the above, the program is executed, displaying some result on the screen.
In this state, there could be run-time errors, such as
division by zero, or they could become evident when seeing that the program does not produce the
correct output. If the above happens, then the file should be edited again.
program, recompile it, and run it again. However, some information is provided
basic for some C programs. The preprocessor accepts the source code as
entry and is responsible for:
Remove the comments.
• Interpret the preprocessor directives that begin with #.
For example:
#include -- includes the content of the named file. These are usually called
header files.
For example:
#include <math.h> -- Standard library file for mathematics.
#include <stdio.h> -- Standard Input/Output library file.
#define -- defines a symbolic name or constant. Macro substitution.
#define MAX_ARRAY_SIZE 100
C compiler
The C compiler translates the source code into assembly code. The source code
is received from the preprocessor.
Assembler.
The assembler creates the source code or object files. On UNIX systems, it
You will be able to see the files with the suffix .o.
Linker
If any source file references functions from a library or from functions that
are defined in other source files, the Linker combines these functions (with main
() to create an executable file.
Bibliography
The provided URL does not contain text to translate..
Unable to access external links..
[Link]
[Link].
Unable to access the specified URL..
Unable to access external content..
INDEX
3.4 IDENTIFIERS.