Monday, July 8, 2013

Mathematical Operators in C

Mathematical Operators are those operators through which we perform some Arithmetic operations in C. These Operators are broadly classified into two types

  1. Unary Operators
  2. Binary Operators
Both the Operators are responsible for performing the Arithmetic Operators, but they are differed based on the number of Operands they use.

Difference between Pre-Increment and Post-Increment Operators

As we already know that Unary Operators are of two types, Increment and Decrement Operators. Increment Operator is used to increment the value by one and the Decrement Operator is used to decrement the value by 1.

Again these Increment and Decrement Operators are divided into two types, pre and post. There is a lot of difference between in this pre and post. ++x comes under Pre-Increment Operator and x++ comes under Post-Increment Operator.

We can understand this difference with an example program. Consider the following program.

Sunday, July 7, 2013

Assignment Operator in C

The assignment operator is used for assigning some value to an operand or a variable. In C, the assignment operator is equal sign (=). In mathematics the significance of the equal to sign is to be sure that both the left and right values of the equal sign have the same value. But in C, its significance is somewhat different.

For example,
x=2+3;
signifies that the expression on the right is evaluated and the resulting value is assigned to the variable on the left side of the equation.

Operators in C

Operators are nothing but symbols which are used to perform some operation on the operands i.e., variables or constants.

If you consider the below example,
2+3
Here,

  • 2 and 3 are operands
  • + is an operator. 
There are four types of operators in C. They are

Return in C

Return Statement is written at the end of a subroutine to get back to the called routine. This return statement is used to return some value to the called function. In C, we use the return statement like this,
return(x) or return x;
Both the usages result the same, they return the value x;

Once a return statement is used, the function gets back to the called function and doesn't execute the lines of code under the return. So return statement is used generally at the bottom of the function.

Printf in a Printf Statement

I think most of you know what an Expression means, if not click here.

So we are moving on to the complex part of the expressions, What happens when a printf() statement is included in a expression???

Before knowing about it, we go on with a simple example of expression

x=3+(y=5+6)
Do you know what would be the result of the expression, it just gives a value of 5+6 i.e., 11 to y and the value of x would be 3+y i.e., 3+11 and the value is 14.

Expressions in C

Expressions are nothing but everything we represent. An expression can be a constant or a variable. The operations performed on these expressions are also considered to be as expressions. Based on the complexity of the expressions, they are divided into two types.

  1. Simple Expressions
  2. Complex Expressions
Expressions plays an important role in building logic to a C program. To perform some operation in C, we need to use these Expressions.