Pseudo code in C is a simple way to write programming code in English. Pseudo-code is informal writing style for program algorithm independent from programming languages to show the basic concept behind the code.
Pseudocode is not an actual programming language. So it cannot be compiled and not be converted into an executable program. It uses short or simple English language syntax to write code for programs before it is converted into a specific programming language.
It is also useful in a program development process and the programmers will ensure that actual programming is likely to match design specifications. The errors finding at the pseudo-code stage is less costly than catching them later in the development process.
It is possible to write programs that will convert a given pseudo-code language into a given programming language. In simple terms, pseudo-code = Natural Language + Programming Language.
The pseudo code in C consists of words and phrases that make pseudo code looks similar to the program but not a program. Pseudo codes are written with respect to a programming language, but programming language syntax or grammar is not strictly followed.
The pseudo-code is neither an algorithm nor a program. pseudo-code is a semi-formal description of the steps to be carried out by the computer, including Steps that are to be repeated and decisions that are to be made but it constructs/models and maybe even look like programming code.
Pseudocode is made up of two words, ‘pseudo’ and ‘code’. Pseudo means imitation and code refer to instructions, written in a programming language.
Pseudocode is also known as Program Design Language (PDL) or Structured has the following characteristics:
A free syntax of natural language that describes a processing feature.
A subprogram definition and calling techniques.
Fixed syntax of keywords that provide for all structured constructs, data declarations and modularity characteristics.
A data declaration facility.
Pseudocode is a set of sequential written human language instructions, usually numbered, that is used to describe the actions a program will take when it is coded in a programming language.
The pseudo-code notation specifies operations that a machine can perform in as human-friendly (e.g., easy to read) way as possible while avoiding ambiguity.
Pseudo code allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax.
Pseudocode describes the entire logic of the algorithm so that the implementation becomes a mere mechanical task of translating line by line into source code.
Pseudocode is a generic way of describing an algorithm without using any specific programming language-related notations.
Simply put, pseudo-code is an outline of a program, written in a form that can be easily converted into real programming statements.
The Pseudocode uses plain English statements rather than symbols, to present the processes of a computer system.
The ‘structured’ part of pseudo-code is a notation for representing three general programming constructs or structures namely sequence, selection and repetition (looping). These constructs represent the logic or flow of control in an algorithm.
As the name implies, in a sequence structure (construct), the instructions to be computed simply follow one another in a logical progression. The sequence construct indicates a processing step in a program.
Sequence construct is a linear progression where one task is performed sequentially after another. Sequential control is indicated by writing one action after another, each action on a line by itself and all actions aligned with the logical indent.
The actions are performed in the same sequence (top to bottom) in which they are written.
For Example:
Selection is a process of deciding which choice is made between two or more alternative courses of action. In the selection construct, the execution of a set of statements is done according to a pre-specified condition.
The selection structure is also known as decision-making structure because the decision to execute a particular set of the statement is made on the basis of the conditional statement.
The selection structure is categorized into the following three types:
This construct uses if and Then clauses to represent a condition as well as a set of statements. In the If clause, the conditional statement is written, while in Then clause the set of statements to be executed are specified.
The execution of the statements specified in the Then clause occurs only if the condition is true.
This construct is very much similar to the If-Then selection structure. The only difference between the two is that in If-Then-Else selection structure two sets of statements are specified.
One set of statements is represented in the Then clause and another is represented in the Else clause. If the condition is given in If the clause is true, then all the statements specified in the Then clause is executed, otherwise, statements given in the Else clause are executed.
A selection structure allows the program to make a choice between two alternate paths, whether it is true or false. The first statement of a selection structure is a conditional statement.
Pseudocode:
IF (condition is True) THEN
List of Actions
ELSE
List of Different Actions
ENDIF
.
.
It is clear that if the condition is true, Action1 will be performed otherwise Action2 will be performed. After performing the list of actions, the control of the program moves on to the other actions in the process flow.
In this selection construct, multiple sets of statements are specified. Each block of statements is associated with a value. The selection of a particular set of statements is made on the basis of the value of the variable given at the beginning of the selection structure.
A case construct indicates a multiway branch based on many conditions. Case construct uses for keywords, Case Of, Others and EndCase, along with conditions that are used to indicate the various alternative.
Pseudocode:
CASE Expression OF
1 Condition:Sequence 1
2 Condition:Sequence 2
.
.
.
N Condition: Sequence N
OTHERS:
Default Sequence
ENDCASE
Looping construct in pseudo-code is used when some particular task is to be repeated for a number of times according to the specified condition.
When a sequence of statements is repeated against a condition, it is said to be in the loop. Using looping, the programmer avoids writing the same set of instructions again. The looping process can either be one time or multiple times until the desired output is obtained within a single program.
In the repetition construct, only one set of multiple statements is specified. The same set of the statement is executed several times on the basis of the condition specified along with the structure.
The various type of repetition structure is explained below:
In the Do-While looping construct, a set of statements is given in the Do block and a condition is given in the Do block are executed till the given condition is true. At each instance of execution of block statements, the condition is checked.
If the condition is true, then only the block statements are executed, otherwise, the repetition structure is terminated.
Pseudocode:
DO WHILE Condition is True
1st Statement
2nd Statement
.
.
Nth Statement
ENDDO
The Repeat-Until looping construct is similar to the Do-While repetition structure. In this structure, the repetitive execution of statements given in the Repeat clause occurs only when the condition given in the Until clause is false.
Pseudocode:
REPEAT
1st Sequence
2nd Sequence
.
.
Nth Sequence
UNTIL Condition is False
Pseudo code is easier and simpler to understood by the programmers of all types.
It cannot be compiled into an executable program.
Compared to a flowchart, it is easier to modify the pseudo-code of program logic whenever program modifications are necessary.
Converting a pseudo code to a programming language is very easy as compared with converting flowchart to a programming language.
To develop a pseudo-code it requires less time and effort than other programming tools such as flowchart.
pseudo-code is easier to write than writing a program in a programming language because pseudo-code as a method has only a few rules to follow.
Pseudocode is textual representation of an algorithm. It does not provide a graphical or visual representation.
Therefore, sometimes, it becomes difficult to understand the complex written in Pseudocode.
There are no standard rules to follow in using the Pseudo code in C.
Different programmers use their own style of writing pseudo code and hence communication problems occur due to lack of standardization.
For a beginner, it is more difficult to follow the logic or write pseudo code as compared to the flowchart.