⯈Algorithm and its Characteristics

⯈Elementary Problems

- Addition of two numbers
- Calculate area and circumference of circle
- Calculate area of triangle
- Calculate simple interest
- Calculate slope and distance between two points
- Convert length in feet to inches
- Weighted score in exam
- Convert temperature in degree Celsius to Fahrenheit
- Swap two numbers
- Swap two numbers without using extra variable

- Overview of C Programming Language
- Getting started with C Programming Language
- Keywords
- Identifiers
- Constants
- Operators
- Expression Evaluation
- Mathematical expression to C equivalent expressions
- Datatypes
- Variables
- Integer representation in C
- Character representation in C
- Type conversion in C
- sizeof operator
- Comments
- Mathematical Functions
- input output statements
- width specifiers in C
- structure of a C program
- header files
- Compilation process of a C program
- Types of initializations.

⯈Basic C Programs

- C program to add two numbers
- C program to find area and circumference of circle
- C program to swap two numbers
- C program to swap two numbers without using extra variable
- C program to swap two numbers using bitwise XOR
- C program to convert temperature in Celsius to Fahrenheit
- C program to calculate gross salary of an employee
- C program to count number of digits in a positive integer
- C program to count number of digits in binary representation
- C program to count number of digits in base ‘K’
- C program to convert kilometer to meter, feet, inches and centimeters
- C program to find first and last digit of a number
- C program to find minimum number of currency denominations
- C program to convert cartesian coordinates to polar coordinates
- C program to find distance between two places on earth in nautical miles
- C program to find slope and distance between two points
- C program to add 1 to the number using ‘+’ operator
- C program to find maximum of two numbers using ternary operator
- C program to find maximum of three numbers using ternary operator
- C program to find kth bit of a number
- C program to find last four bits of a byte
- C Program to reset right most set bit of a number

## Unary operators in C

The operators which act on single operand to give the result is called as unary operator. We shall discuss the following unary operators here.

- Unary plus ( + )
- Unary minus ( – )
- Increment operator ( ++ )
- Decrement operator ( — )
- Address operator ( & )
- Dereference operator ( * )
- Negation operator ( ~ )
- sizeof operator

You may refer to the video posted at the end of this page.

### Unary plus (+)

This operator is used to represent the positive numbers.

Ex: +3, +a

### Unary minus (-)

This operator is used to represent the negative numbers.

Ex: -1, -a

### Increment operator (++)

This operator means add one to the given number.

**This operator can only be used with the variables**.

They cannot be used with the constants.

There are two types of increment operators.

#### Pre increment

In pre-increment, the operator appears before the operand.

++a (we can see that the operator ++, is before the operand ‘a’)

if a = 5

then ++a, will make a = 6

add one to the number.

if a = -1

then ++a, will make a = 0

add one to the number.

Pre-increment means increment first then assign. What does that mean let us see by some examples.

if, a = 4 and

b = ++a,

first increment the value of ‘a’, a becomes 5, then assign 5 to b.

Therefore, a = 5 and b = 5

if, a = -1 and

b = ++a,

first increment the value of ‘a’, a becomes 0, then assign 0 to b.

Therefore, a = 0 and b = 0

#### Post Increment

In post-increment, the operator appears after the operand.

a++ (we can see that the operator ++, is after the operand ‘a’)

if a = 5

then a++, will make a = 6

add one to the number.

if a = -1

then a++, will make a = 0

add one to the number.

At this point, we see that both the pre-increment and post-increment produces the same result. But there is difference when we assign the result to another variable.

Post-increment means assign first then increment. Let us understand this by some examples.

if, a = 4 and

b = a++,

Assign the value a to b first then increment the value of a.

Therefore, a = 5 and b = 4

if, a = -1 and

b = a++,

Assign the value a to b first then increment the value of a.

Therefore, a = 0 and b = -1

##### The following are ** invalid.**

++3, 4++ (increment operators can only be applied on variables, cannot be applied on constants)

++3, 4++ (increment operators can only be applied on variables, cannot be applied on constants)

**
**
##### The following are

### Decrement operator (--)

This operator means subtract one from the given number.

T**his operator can only be used with the variables**.

They cannot be used with the constants.

There are two types of decrement operators.

#### Pre decrement

In pre-decrement, the operator appears before the operand.

–a (we can see that the operator –, is before the operand ‘a’)

if a = 5

then –a, will make a = 4

subtract one from the number.

if a = -1

then –a, will make a = -2

subtract one from the number.

Pre-decrement means decrement first then assign. What does that mean let us see by some examples.

if, a = 4 and

b = –a,

first decrement the value of ‘a’, a becomes 3, then assign 3 to b.

Therefore, a = 3 and b = 3

if, a = -1 and

b = –a,

first decrement the value of ‘a’, a becomes -2, then assign -2 to b.

Therefore, a = -2 and b = -2

#### Post decrement

In post-decrement, the operator appears after the operand.

a– (we can see that the operator –, is after the operand ‘a’)

if a = 5

then a–, will make a = 4

Subtract one from the number.

if a = 0

then a–, will make a = -1

Subtract one from the number.

At this point, we see that both the pre-decrement and post-decrement produces the same result. But there is difference when we assign the result to another variable.

Post-decrement means assign first then decrement. Let us understand this by some examples.

if, a = 4 and

b = a–,

Assign the value a to b first then decrement the value of a.

Therefore, a = 3 and b = 4

if, a = 0 and

b = a–,

Assign the value a to b first then decrement the value of a.

Therefore, a = -1 and b = 0

##### The following are **invalid.**

--3, 4-- (decrement operators can only be applied on variables, cannot be applied on constants)

--3, 4-- (decrement operators can only be applied on variables, cannot be applied on constants)

**
**
### Address operator (&)

This operator is used to get the address of the variable. This operator we will discuss in detail in the scanf statement and the pointers chapter.

### Dereference operator (*)

This operator is used to get the value at the given address. We shall discuss this operator in detail in the pointers chapter.

### Negation operator (~)

This operator flip the bits of a given number.

**This operator can only be applied on integers.**

We will discuss this operator in the bitwise operator section.

### sizeof

This operator gives the size taken by the datatype or a variable or a constant. We will discuss this in detail after the datatypes and variables.

**
**