Instructions in C Programming Language
Understand C Instructions:
Instructions in C are the commands in the program that will instruct C compiler to perform specific tasks or actions. Whenever we write a C instruction, we are telling C compiler to do a task for us.
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. In this article, I will explain 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 in C
Type Declaration instruction is used to declare the type 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: Type declaration instruction
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; }
Arithmetic instructions in C
Arithmetic instructions are used to perform arithmetic operations on variables and constants.The variables and constants on which arithmetic operations are performed is called operands.
Following are the list of operators that can 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 value of operand at R.H.S of “=” sign to variable at L.H.S.
“+” is an addition arithmetic operator that is used to perform addition operation 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 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 operation on the operands “a”, “b” and “c”.
Control instructions in C
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 addition of two numbers, subtraction of two number 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 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 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
“a is integer variable.
b, c and d are real variables.”
I get why a, b, c and d are all variables. I also understand why a is an integer. Why are b, c and d “real variables”? Wouldn’t they be floats?
Because integer are whole numbers they may positive negative or zero like 1,123,4325,_10 etc and 1.5,0.05 are not integer because they are decimal number and decimal number are not whole number
real is a synonym of float. Hence float can also be called as real variable.
Great site…
nice
Thanks a lot. 🙂
If you like the post then please Tweet it/ Digg it or click on like (Facebook) button above. It would be hight appreciable.
I love this website. Thanks again. Became fan on facebook. Click adds every time I visit a page. Anything else I can do please let me know.
Nothing else… Just spread the name learnCOnline.com 🙂 Thank you
thanks for a lot.i’ve so many confusion before learning c. but it’s o.k for me now.
= is not a assignment variable, but its an assignment operator. right.
Thanks a lot for correcting us. Appreciate it.
tnx man the site helped a lot
a good site i was wondering since so many days for a site like this…
good site…
super……… blog……
Anyone tell me how to download c compiler program for Windows & Ultimate 64-bit ?
Remember C program not C++
I love the content on this site. I have to reference back when I need to see linked lists again. For the users that need a download-able C compiler, I found Tenacious C to be great, and it has a graphical display that shows pointers actually pointing to pieces of memory.
can 2.0 be a float?
superb!!!!!!!!!!!!!!!!!!!!
can i get a help in learning a c program
hello can i get a easy instruction in learning a c program
Anything with a dot within before or after a number is a float (or) real variable I know this sounds stupid since 2.0 is nothing but 2 right but the computer will consider 2.0 as a float variable .
can i get all the notes on c programming.. please
great
Can I get notes of c programming please