C programes

Arithmetic Operators in C

Arithmetic Operators in C

These operators give the ability to do the arithmetical operations like

a. Addition

By using this operator it will allow the user to add two or more operands and to get the sum.
Ex: Please consider the bellow mentioned program
/*Addition operator Explanation*/
#include<stdio.h> // Preprocessor to include the stdio.h
int main()
// Main function which will return integer value
// Starting of the program/ function
int a=10;
// Initializing the variables a,b and declaring variable c
int b=20;
//Addition of a and b
printf(“Addition of the two numbers is c=%d\n”,c);
// Subtraction of a from b
printf(“Difference of the two numbers is c=%d\n”,c);
//Product of a and b
printf(“Product of the two numbers is c=%d\n”,c);
//Dividing b by a
printf(“Division of the two numbers is c=%d\n”,c);
// finding the modulus of b by a
printf(“Modulus of the two numbers is c=%d\n”,c);
printf(“Pre-increment of the two numbers is ++a=%d\n”,++a); //Pre-incrementing the value by 1
printf(“Pre-decrement of the two numbers is –a=%d\n”,–a); // Pre-decrementing the value by 1
printf(“Post-increment of the two numbers is a++=%d\n”,a++); // Post-incrementing the value by 1
printf(“Post-decrement of the two numbers is a–=%d\n”,a–); // Post-decrementing the value by 1
return 0;
Addition of the two numbers is c=30
Difference of the two numbers is c=10
Product of the two numbers is c=200
Division of the two numbers is c=2
Modulus of the two numbers is c=0
Pre-increment of the two numbers is ++a=11
Pre-decrement of the two numbers is –a=10
Post-increment of the two numbers is a++=10
Post-decrement of the two numbers is a–=11

Explanation :

In the above program we are trying to explain the working of arithmetic operators. There are 7 diffent types of arithmetic operators.
In this program after including the standard input /output header file to the program by using #include preprocessor, we are initializing the variables a,b and declaring the variable C. All these variables are integer data types. Next line onwards we are executing the operation.

Addition:

Adding the two values which are stored in the two variables a and b and saving the sum value to variable c. Using printf function we printing the value on the console (output screen).

Subtraction:

We are finding the difference between two values which are stored in the two variables a and b saving the difference value to variable c. Using printf function we printing the value on the console (output screen).

Division:

Dividing one value with another which are stored in the two variables a and b and saving the quotient value to variable c. Using printf function we printing the value on the console (output screen).

Modulus:

Dividing one value with another which are stored in the two variables a and b and saving the remainder value to variable c. Using printf function we printing the value on the console output screen)

Pre-increment:

This increment operator first increments the value stored in variable ‘ a’ by 1 and store it back in the same variable.

Pre-decrement:

This decrement operator first decrements the value stored in variable ’ a’ by 1 and store it back in the same variable.

Post-increment:

This increment operator increments the value stored in the variable ‘a’ by 1 and stores it back in the same variable. But it will get in effect in the next instruction only.

Post-decrement:

This decrement operator increments the value stored in the variable ‘a’ by 1 and stores it back in the same variable. But it will get in effect in the next instruction only.
After the execution of the program, it will return 0 back to the main function (Because we used int main (), the return type of main() is an integer type only).

Operators in C

Operators in C :

There are a lot of symbols in C. One set of them we can call as operators. Operators are symbols which tell the computer to do some specific task. C is Rich with operators. They are mentioned below.
Before we proceed further consider A+B=C
Here A, B, C are the operands and ‘+’ is the operator. A+B=C is the operation.

a) Arithmetic Operators

All the arithmetic operations we can do with the arithmetic operators.

b) Relational Operators

These operators will check the relation between the two operands. Its output will come as true or false. If it is true it will execute the following code otherwise not.

c) Logical Operators

It will check the logical relationship between the two cases. Depending upon the logical operators we used and its condition it will give the result.

d) Bitwise Operators

As the name suggests bitwise operators work on bits and will do the operations on the bits.

e) Assignment Operators

Assignment operators will assign the value of an operand to another operand after the operation.

f) Misc Operators

These also called as special purpose operators. They also have a special function to complete.
All these operators above mentioned will explain in detailed in the next topics.

Pointers and Addresses

Pointers and Addresses:

When we are talking about the program and its execution we will come up with addresses. All the variables, functions, arrays, etc like whatever we are using to write and execute a program all are saved in memory. Memory will be starting and ending with some memory address. The accessibility to these memories we can do only with memory addresses only. It will give the privilege to the programmer to make changes from a very base level.

Address:

It is the information about the data, where it is saved in memory. If you want the address of a variable
you can use the ’&’ address of the operator.

Pointer:

It is the ability of the variable to hold the address of another variable(Points to the address of another variable). The pointer is denoted ‘*’ Asteric symbol. One of the major advantages of the pointer is it will give direct access to the memory address of the variables, functions, arrays, strings, linked list etc..
The size of the pointer is depending upon the size of the memory. For eg, if the memory is 8-bit memory the pointer size will be 8 bit. If it is 16 bit then the pointer will be 16-bit memory.
Let us check an example program.
#include<stdio.h>
Int main()
{
Int a=90;
//integer variable definition
Int *p;
// pointer declaration
P=&a;
// Assigning the address of a to the pointer p.
Printf(“Value of integer a =%d”,a);
Printf(“Value of integer pointer p =%d”,p);
Printf(“Address of integer a =%d”,&a);
Printf(“Address of integer pointer p =%d”,&p);
Printf(“De-referenced value of integer pointer p =%d”,*p);
Return 0;
}

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*