Instructions in C programming Language | Types of Instructions in C Programming

Instructions are commands in C programming that instruct the compiler to perform a specific action. In C Programming Instructions are classified in mainly three types.

  1. Type Declaration Instruction
  2. Arithmetic Instructions
  3. Control Instructions

Type Declaration Instruction in C

Type declaration instruction is used to specify the type of variable that will be used in the C program. It was used after the main function. Users need to instruct the compiler which type of variable will be used in a C program. So, Type declaration instruction is used to do it. Let’s take a look at an example for a better understanding.

#include <stdio.h>

int main()  
{
    int a=4; // Here int is a type declaration instruction
    printf("Value of a=%d",a);

    return 0;
}

Arithmetic Instructions in C

Arithmetic Instructions are used to perform arithmetic operations on variables & constants. Variables and Constants on which these operations are applied are knowns as Operands. Here are some most used arithmetic operations in C.

Arithmetic OperationsDescriptions
+Addition: used to the sum n numbers
Subtraction: used to minus n numbers
*Multiplication: used to multiply n numbers
/Division: used to perform division
%Modulo: return reminder
Arithmetic Operators in C

Let’s create a program and understand how arithmetic operators are used in C Programming.

#include<stdio.h>
#include<conio.h>
void main()
{
    
    int a;
    int b;
    printf("Enter value of a & b \n");
    scanf("%d %d",&a,&b);
    // Addition operator
    printf("Sum=%d\n",a+b);
    // Subtraction Operator
    printf("Subtraction=%d\n",a-b);
    // Multiplication Operator
    printf("Multiplication=%d\n",a*b);
    // Division Operator
    printf("Division=%d\n",a/b);
    // Modulo Operator
    printf("Modulo=%d\n",a%b);
    getch();
}

Control Instructions

Control instructions are used to control the flow of execution of a program. Using the Decision control statement we can control and perform specific actions in the program. Control Instructions build a logic in which the user can create logical statements. Here are some decision control statements in C Programming.

  • If Statement
  • If Else Statement
  • Conditional Operators
  • Switch Statement

If Statement in C

#include<stdio.h>
#include<conio.h>
void main()
{
    
    int a;
    int b;
    printf("Enter value of a & b \n");
    scanf("%d %d",&a,&b);
   if(a%b==0)
   {
       printf("a is multiple of b");
   }
    getch();
}

If Else Statement

#include<stdio.h>
#include<conio.h>
void main()
{
    
    int a;
    int b;
    printf("Enter value of a & b \n");
    scanf("%d %d",&a,&b);
   if(a%b==0)
   {
       printf("a is multiple of b");
   }
   else
   {
       printf("a is not multiple of b");
   }
    getch();
}

Conditional Statement

#include<stdio.h>
#include<conio.h>
void main()
{
    int a = 10, b = 11;
    int c;
    c = (a < b)? a : b;
    printf(ā€œ%dā€, c);
}

Switch Statement

#include<stdio.h>
int main() {
char operation;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operation);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);

switch(operation)
{
    case '+':
        printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
        break;

    case '-':
        printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
        break;

    case '*':
        printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
        break;

    case '/':
        printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
        break;

    // operator doesn't match any case constant +, -, *, /
    default:
        printf("Error! operator is not correct");
}

return 0;
}

I hope you all enjoy this tutorial of instructions in C Programming. If you enjoy it share it with your friends. Read More by checking more articles given below.

Leave a Comment