Friday, July 29, 2016

C Basics - Overview of Instruction in C

There are basically three types of instructions in C:

Type Declaration Instruction is to declare the type of variables used in a C program. Any variable used in the program must be declared before using it in any statement.
Example:

int count ; 
float pi, rate ; 
char name, code ;

While declaring the type of variable we can also initialize it as shown below.

int i = 10, j = 25 ; 
float a = 1.5, b = 1.99 + 2.4 * 1.44 ;

Arithmetic Instruction is to perform arithmetic operations between constants and variables. Arithmetic instruction consists of a variable name on the left hand side of = and variable names & constants on the right hand side of =. The variables and constants appearing on the right hand side of = are connected by arithmetic operators like +, -, *, and /.
Example:

int ad ; 
float kot, deta, alpha, beta, gamma ; 
ad = 3200 ; 
kot = 0.0056 ; 
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;

The variables and constants together are called ‘operands’ that are operated upon by the ‘arithmetic operators’ and the result is assigned, using the assignment operator, to the variable on left-hand side. Arithmetic operations can be performed on ints, floats and chars.

Control Instruction is to control the sequence of execution of various statements in a C program. The control instructions determine the ‘flow of control’ in a program. There are four types of control instructions in C:

Sequence Control Instruction: The Sequence control instruction ensures that the instructions are executed in the same order in which they appear in the program.

Selection or Decision Control Instruction: Decision control instructions allow the computer to take a decision as to which instruction is to be executed next.

Repetition or Loop Control Instruction: The Loop control instruction helps computer to execute a group of statements repeatedly.

Case Control Instruction: Case control instruction helps to execute specific set of statements.



Related topics:
Overview of Storage Class in C   |   Overview of Operators in C   |   Type Conversion in C   |   Expression in C   |   Overview of Statements in C

List of topics: C Programming

No comments:

Post a Comment