Breaking News

Instructions in C


Instructions in C by Technotoken





Instructions in C are the commands in the program that will instruct the C compiler to perform specific tasks or actions. Whenever we write a C instruction, we are telling the C compiler to do a task for us.


For example, if I want to instruct the 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. In this article, we will be learning 4 different types of instructions in C Programming Language

To better understand this we will go through each of these 4 categories (types) of instructions in C one by one So let's Get Started.




Catagories : 


1) Type Declaration instruction
2) Input/output instructions 
3) Arithmetic Instructions 
4) Control Instructions




Type Declaration instructions 


Type Declaration instruction is used to declare the types of variables to be used in a C program. Any variable that we want to use in the program must be declared before using it. This declaration is done using type declaration instruction.


Syntax: 

data-type variable_name;
Here,

data-type represents any valid C data type. E.g. int, char, float, double, etc.

variable_name can be any valid name satisfying rules for constructing variables in C.

This declaration is done at the beginning of the main() function as shown below.


Example: 


int main()

{
     int balance, rate;
     float amount;
}


Input/output instructions 



As the name itself indicates the Input/output instructions are used to input as well as output information where an instruction that is used to print something on the screen or any other output device is known as output instruction. Similarly, an instruction that is used to input information from the user is known as input instruction.

C language has standard libraries that allow input and output in a program. The stdio.h or Standard input-output library in C has methods for input and output.



Input Instruction 


In any programming, language input means to feed some data into the program. This can be given in the form of a file or from the command line.  C programming language provides a set of built-in functions to read given input and feed it to the program as per requirements such as scanf() .


scanf() 


The scanf() method, in C, reads the value from the console as per the type specified. 


Syntax:

scanf(“%X”, &variableOfXType);

where %X is the format specifier in C. It is a way to tell the compiler what type of data is in a variable

and

& is the address operator in C, which tells the compiler to change the real value of this variable, stored at this address in the memory.



Output Instruction



printf()


The printf() method, in C, prints the value passed as the parameter to it, on the console screen.


Syntax:

printf(“%X”, variableOfXType);

where %X is the format specifier in C. It is a way to tell the compiler what type of data is in a variable

and 

is the address operator in C, which tells the compiler to change the real value of this variable, stored at this address in the memory.



Example


printf(“Saurabh Shukla”);

printf(“Hello SCA”);



Arithmetic Instructions 

 

Arithmetic instructions are used to perform arithmetic operations on variables and constants. The variables and constants on which arithmetic operations are performed are called operands.


Following are the list of operators that can be used to perform arithmetic operations in C


C Arithmetic Operators	                Description

+	                          addition or unary plus- used to perform addition
–	                          minus or unary minus – used to perform subtraction
*	                          multiplication – used to perform multiplication
/	                          division – used to perform division
%	                          modulo division – returns remainder after division


Example 1: 


int main(){
     int a = 5, b = 10, c;
     c = a + b;
}
Here,

a, b and c are called operands

“=” and “+” are called C operators.

“=” is an assignment operator that is used to assign the value of the operand at 

R.H.S of the “=” sign to variable at L.H.S.

“+” is an addition arithmetic operator that is used to perform addition operations on operands “a” and “b”.


Example 2: 


int main()

{
     int a;
     float b, c, d;
     a = 10;
     b = 0.05;
     c = 1.5;
     d = a +b * c;
}
Here,

“a” is an integer variable.

“b”, “c” and “d” are real variables(float).

“=” is an assignment operator.

“+” and “*” are C arithmetic operators used to perform addition and multiplication arithmetic operations on the operands “a”, “b”, and “c”.


Control Instructions


Control instructions in C are used to control the sequence (flow) of the program execution.

We write a program to perform a particular task. The program might be the addition of two numbers, subtraction of two numbers, or division of two numbers. Let us suppose that we need to write a program to perform all the above three operations i.e. addition, subtraction, and multiplication. Writing three different programs is not feasible. If we do so, then for addition, subtraction, and division we need to run the program separately. Instead of doing this, we can include a decision control statement. Using this we can decide within the program whether to perform addition, subtraction, or division. Thus program becomes efficient and user-friendly too.

Using a decision control statement, we can perform different actions based on the circumstances.

Decision control instructions in C:

1) The if Statement 

2) The if else Statement

3) The conditional Operators

4) The switch statement 



Conclusion

So to sum it all up 

Instructions in C are the commands in the program that will instruct the C compiler to perform specific tasks or actions. Whenever we write a C instruction, we are telling the C compiler to do a task for us.


There are 4 Catagories (Types) of  Instructions in C Language that are :

1) Type Declaration instruction

2) Input/output instructions 

3) Arithmetic Instructions 

4) Control Instructions



So this is it guys if you want us to write more on this topic or have any particular Query regarding this post you can always comment or feel free to mail us at our official mail also follow us on Instagram and Facebook to receive Latest Updates first.


Peace!!!



No comments

If you have any doubts, please let us Know.