Operators

C operators are symbols that are used to perform mathematical or logical manipulations. The C programming language is rich with built-in operators. Operators take part in a program for manipulating data and variables and form a part of the mathematical or logical expressions.

Types of operators:-

C programming language offers various types of operators having different functioning capabilities.

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Assignment Operators
  5. Increment and Decrement Operators
  6. Conditional Operator
  7. Bitwise Operators
  8. Special Operators

Arithmetic Operators:-

C supports all the basic arithmetic operators. The following table shows all the basic arithmetic operators.

OperatorDescription
+adds two operands
subtract second operands from first
*multiply two operand
/divide numerator by denominator
%remainder of division
++Increment operator – increases integer value by one
Decrement operator – decreases integer value by one

Relational operators:-

The following table shows all relation operators supported by C.

OperatorDescription
==Check if two operand are equal
!=Check if two operand are not equal.
>Check if operand on the left is greater than operand on the right
<Check operand on the left is smaller than right operand
>=check left operand is greater than or equal to right operand
<=Check if operand on left is smaller than or equal to right operand

Logical operators:-

C language supports following 3 logical operators. Suppose a = 1 and b = 0,

OperatorDescriptionExample
&&Logical AND(a && b) is false
||Logical OR(a || b) is true
!Logical NOT(!a) is false

Bitwise operators:-

Bitwise operators perform manipulations of data at bit level. These operators also perform shifting of bits from right to left. Bitwise operators are not applied to float or double(These are datatypes, we will learn about them in the next tutorial).

OperatorDescription
&Bitwise AND
|Bitwise OR
^Bitwise exclusive OR
<<left shift
>>right shift

Assignment Operators:-

Assignment operators supported by C language are as follows.

OperatorDescriptionExample
=assigns values from right side operands to left side operanda=b
+=adds right operand to the left operand and assign the result to lefta+=b is same as a=a+b
-=subtracts right operand from the left operand and assign the result to left operanda-=b is same as a=a-b
*=mutiply left operand with the right operand and assign the result to left operanda*=b is same as a=a*b
/=divides left operand with the right operand and assign the result to left operanda/=b is same as a=a/b
%=calculate modulus using two operands and assign the result to left operanda%=b is same as a=a%b

Conditional operator:-

The Conditional Operator in C, also called a Ternary operator, is one of the Operators, which used in the decision-making process. The C Programming Conditional Operator returns the statement depends upon the given expression result.

Example:-

Test_expression ? statement1: statement2

Special operator:-

OperatorDescriptionExample
sizeofReturns the size of an variablesizeof(x) return size of the variable x
&Returns the address of an variable&x ; return address of the variable x
*Pointer to a variable*x ; will be pointer to a variable x
Read More

C Language Introduction

C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and clean style, these features make C language suitable for system programmings like an operating system or compiler development.

The structure of a C program is as follows:

C Language Program Structure
C Language Program Structure

The components of the above structure are:

  Header Files Inclusion: The first and foremost component is the inclusion of the Header files in a C program.
A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.

Some of C Header files:

stddef.h – Defines several useful types and macros.
stdint.h – Defines exact width integer types.
stdio.h – Defines core input and output functions.
stdlib.h – Defines numeric conversion functions, pseudo random network generator, memory allocation.
string.h – Defines string handling functions.
math.h – Defines common mathematical functions.

Syntax to include a header file in C:

#include 

Main Method Declaratiometn: The next part of a C program is to declare the main() function. The syntax to declare the main function is:

Syntax to Declare main hod:

int main()
{}

Variable Declaration: The next part of any C program is the variable declaration. It refers to the variables that are to be used in the function. Please note that in the C program, no variable can be used without being declared. Also in a C program, the variables are to be declared before any operation in the function.

Example:

int main()
{
    int a;
.
.

Body: Body of a function in C program, refers to the operations that are performed in the functions. It can be anything like manipulations, searching, sorting, printing, etc.

Example:

int main()
{
    int a;

    printf("%d", a);
.
.

Return Statement: The last part in any C program is the return statement. The return statement refers to the returning of the values from a function. This return statement and return value depend upon the return type of the function. For example, if the return type is void, then there will be no return statement. In any other case, there will be a return statement and the return value will be of the type of the specified return type.

Read More

About C Language

C is a structured general purpose programming language. It was developed to rewrite the unix operating system. Earlier the unix operating system was written in B language. Almost the entire unix operating system and most of the programs run in it are written in C language.
The B language was written by Ken Thompson at Bell Laboratories in 1970. B was a type less language. That is, there was no concept of data types in B. B language did not gain much popularity.
C language was developed by Dennis Ritchie in 1972 at bell laboratories. C is a type full language. C language provides many data types.
C was a very short and simple language. Therefore, in a short time it became very popular and other computer scientists started using it as well.
There is no decrease in the popularity of C language even today. C language is taught before learning any other programming language. Because all the programming languages ​​(C ++, Java, PHP, C # etc) came after C language, they have somehow adopted C’s syntax.

Features of C Language

The reason for the popularity of C language is its features. These features make C language unique and powerful.

Structured

C is a structured programming language. In C, a program is created as small modules, called functions. By doing this, the programs are easy to manage and debug and big problems can also be solved easily.

Small

C provides 32 reserved keywords. These keywords provide programmer control over the language. By understanding the use of these keywords, you can do programming in C language. C language is small because it can be learned easily in a short time. Also, it is also easy to use.

Middle level

C is a middle level language. C is able to create both high level (very close to software) and low level (very close to hardware) applications.

This feature of C language is an advantage for programmers who want to create applications of both low and high levels. This feature makes C language flexible.

Fast

C language is considered the fastest language after assembly language. It is also sometimes called low level language. C language is close to hardware. So it is faster than other programming languages. Processing of applications created in C language is fast.

Case sensitive

C is a case sensitive language. In case sensitive programming languages ​​the capital and small variants of a letter are treated differently. This makes it easier for programmers to create identifiers.

Extendable

C is an extendable programming language. You can add your own libraries to C programs and use them.

Read More