0 0

Types of instructions in C programming

- Advertisement -
Read Time:4 Minute, 9 Second
Types of instructions in C programming
Types of instructions in C programming

Types of instructions in C programming:

C Instructions

C instructions are the commands in the program that instructs the compiler to do certain action. Basically it gives the instruction to the compiler on how to achieve the goal of the program.

For example, if I want to instruct C compiler to perform multiplication of 2 numbers, I can do that with help of C Arithmetic instruction. Similarly, if I want to declare a variable, I should be able to do that using Type declaration instruction in C. Following are the 3 different types of C instructions.

There are three types of instructions in C. They are as follows:

1) Type Declaration Instruction
2) Arithmetic Instruction
3) Control instruction

  • Type Declaration Instruction:

These instructions inform the compiler about the type of variables used. That means, whenever a variable is used in the program, we have to specify what types of data it can hold – like integer, float, double, character etc. This makes the compiler to store only those specific types of values in it. For example, a variable int Var1 declared as int will accept and store only integer values. It will never accept float or character values.

Declaration of variable is done at the beginning, inside the main function. This function is the starting point of any  C program and all the variables used with main function needs to be declared at the beginning of it, before using it in the function. Any other functions in the program can also have variables and they needs to be declared at the beginning of respective functions.

 

  • Arithmetic Instruction

These instructions are used to perform some arithmetic calculation within the program. It uses arithmetic operators like +, -, X, /, %, =, ++,–, +=,-+ etc. The variables that participate in the arithmetic operations are termed as operands. These instructions can have any simple to complex arithmetic calculations using these symbols.

  • Control Instructions

Like the name suggests, these instructions are used to control the flow of the program execution. They maintain certain order in which program needs to be executed. These order of execution may be based on certain conditions or may be based on certain values – may be input values or some result values.

There are four types of control instructions in C.

  1. Sequence Control Instructions
  2. Decision / Selection Control Instructions
  3. Loop Control Instructions
  4. Case Control Instructions

Sequence Control Instructions

These instructions are responsible for executing the instructions one after the other, as they appear in the program. There are not any checks on the condition or values to control the execution. For example, a normal program in which all the arithmetic operation like addition, subtraction, multiplication and division is carried out one after the other. Here there is no check on user option, or any other conditions. It will display results of all the operations in the order they appear in the program.

Decision / Selection Control Instructions

This will have set of conditions to execute the instructions within it. If the condition is true, then it will execute the instructions, else it will execute other set of instructions. This type of instructions use if or while statements to make the decision.

For example, suppose user enters the options like A, S, D or M to indicate addition, subtraction, multiplication and division. Depending on the option entered by the user, the program may add, subtract, multiply or divide the numbers. Here it will not execute all the operation but only one of them entered by the user.

Loop Control Instructions

There will be certain need for executing a set of instruction for certain number of times. This is done by using loop control statement. These loops will have limited number of iterations or will have certain conditions which in turn will give iterations for the instructions to be executed. These instructions will use for loops or while or do/while statements to get the loop iterations.

For example, suppose we have display the first 5 Name of name in the array. This will use for loop to iterate through the array from its beginning till 5th name to display the names in it. Similarly, suppose we need to display all names in sorted array where average marks are not more than 35%. This will use do/while loop to iterate through the array (here we do not know the exact number of iterations) until the condition is matched.

Case Control Instructions

This is similar to decision control instructions where condition will be checked for the execution of the instructions. But this instructions will use switch case statements to check the conditions.

These control instructions cannot be executed without control statements. There are 4 types of control statements :

  • If..Else statement or If..Else If..Else statement
  • While loop or Do/While loop statements
  • Switch Case statements
  • For Loop Statements

WHAT IS EXCEPTION HANDLING IN JAVA?

Basic C Programming Concept and Programs: hello world, Adding two integers, Area of Square and Circle using VS Code

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
- Advertisement -

Follow US!

FansLike
FollowersFollow
FollowersFollow
SubscribersSubscribe

Latest Post

Introduction to Online Analytical Processing and Data Mart

Introduction to Online Analytical Processing and Data Mart

Introduction to Online Analytical Processing and Data Mart Online Analytical Processing OLAP is computer processing that enables a user to easily and selectively extract and view...
A data warehouse is a relational database that is designed for query and analysis rather than for transaction processing

Introduction to Data Warehouse

Introduction to Data Warehouse A data warehouse is a relational database that is designed for query and analysis rather than for transaction processing. It usually...
Introduction to Advance Database System

Introduction to Advance Database System

Introduction to Advance Database System ABSTRACT Data is collection of raw facts and figure which is basic for decision making. Anything which is unorganized is called...
What is Ternary Operator in C programming with example

What is Ternary Operator in C programming with example

What is Ternary Operator in C programming with example Ternary Operator In the C language ternary operator is allowing for executing or running any code based...
C program to check student is pass or fail using if else, nested if and ternary operator.

What is Conditional Statement in C programming

What is Conditional Statement in C programming Conditional Statement Conditional Statements in C programming are used to make decisions based on the different conditions. Conditional statements...
C programming if else statement

C programming if else statement

C programming if else statement Conditional Statements in C programming are used to make decisions based on the conditions. Conditional statements execute sequentially when there...