-->
Search here and hit enter....

Types of Instructions and if-else Statement in C language??

Hello Viewer! How are you I hope you well? In the previous lesson, we learn Function in C. in this lesson we'll learn If-else Statement, Type of Instruction etc...


if-else statement



Types of Instruction:
there are basically three type of instructions in C

  1. Type Declaration Instruction
  2. Arithmetic Instruction
  3. Control Instruction
Type Declaration Instruction
this instruction is used to declare the type of variables means what type of an object like integer, character etc. it must be declared before use. the type of variable declares after the main ( ) Function.
Example;

int a  ;  
here the meaning of "int" is an integer. it takes 2 byte.

float  b ;
here the meaning of "float" is Decimal value. it takes 4 bytes.

char  c  ;
here the meaning of "char" is Character. it takes 1 byte in memory.

there are several designs for declaration of the type of instruction...

a) We declare the instruction while declaring the variable. show in below.

int i=10 , b=23 ;
float f = 6.7 ;

b) The following statement also correct...

int a, b, c ;
a = b = c = 10 ;

Arithmetic Instruction

An arithmetic statement consists of a variable name on the left-hand side of  "= ( equal to / assign ) and variable name and constant on the right side of " = ( equal to / assign ) ". Understand with the following example.

int add ;
float a, b, c, d, e ;
add = 78 ;
a = 5.6 ;
b = c * d / e + 2.1 * 2 / 8 ;

here,
1.1)  *, +, /, are the Arithmetic Operators.
2.2)  " = " is the Assignment Operator.
3.3)  2, 8, 78 are Integer 
4.4)  5.6, 2.1 are real Constant.
5.5)  " add " is an Integer Variable.
6.6)  a, b, c, d, e are real variables.

The variable and constant together are called " Operands ",

# a C arithmetic statement could be three types ( follows )

1) An arithmetic instruction is at a time is used for storing character constants in character variables.

char a, b, d ;
a = ' F ' ;
b = ' G ' ;
d = ' + ' ;

2) The arithmetic operation can be performed on it, float, and char. understand with example

char x, y ;
int z ;
x = ' a ' ;
y = ' b ' ;
z = x + y ;



Control Instruction in C 

As the name " Control Instruction " means control the instruction in a program are to be executed by the computer. In other words, the controls instruction determines the " Flow of Control " in a program. there is four type of control instruction in C.

1) Sequence Control Instruction
2) Selection or Decision Control Instruction
3) Repetition or Loop Control Instruction
4) Case Control Instruction

The sequence control instruction ensures that the instruction is executed in the same order in which they appear in the program. decision and case control instuction allw the computer to take a decision as to be executed next. the loop control instruction helps computers to execute a group of statements. 

Notes : 
  • Instruction in a program control the behaviour/working of the program.
  • a C program can contain 3 type of instructions.
  • Left to right associativity means that the left operand of an operator must be unambiguous ( explict ), where right to left associativity means that the right operand of a operator must be unambiguous.



Now, We learn about decision statement in C 

Decision Control Instruction

A decision control instruction can be implemented in C using...

  • The if Statement
  • The if-else Statement
  • The Conditional Operators

 The keyword if tells the compiler that what follows in a decision control instruction. the keyword if always close with parenthesis. if the condition is true, then the statement is executed if the statement is not true then the statement is not executed. in the following how they look and how they evaluated in C.

if-else statement


I hope you understand what is the meaning of if & elseIF means if any statement/condition is true then it runs and ELSE means if any statement is wrong then it runs. so basically we said these are the decision-making statement. when it comes to decision that we're going to use If-Else Statement. Suppose you have to create an ODD-EVEN program then we have to add if/else statement in our program. understand with the program.

#include     // Header File
#include   //  Header File
int main()                 // Main Function
{
  int a,b;
  printf("\nEnter Number");
  scanf("%d", &a);
  if ( a%2 = = 0 )     // If condition Statement
  {
  printf("Number is Even");
  }
  else                       // Else condition Statement
  {
  printf("Number is Odd");
  }
}

In the above program, you see when writing if statement it must have to write with what is the condition. when my program is true if we not declare the condition then that given an error you can also see the place of else statement no condition is given because they know if 5%2 is not equal to zero then print Number is Odd. we discussed more example/program on the if-else statement later on other programs tab.


FB COMMENTS ()