website designing in meerut
Let's Start

This tutorial is designed for software programmers with a need to understand the C programming language starting from scratch. This C tutorial will give you enough understanding on C programming language from where you can take yourself to higher level of expertise. There are many compilers available for c and c++. You need to download any one. Here, we are going to use Turbo C++. It will work for both C and C++. Click Here To install TURBO C Software

Feature Of C Language

C is the widely used language. It provides many features that are given below.
  • Simple
  • Machine Independent or Portable
  • Mid-level programming language
  • structured programming language
  • Rich Library
  • Memory Management
  • Fast Speed
  • Pointers
  • Recursion
  • Extensible

Before starting the abcd of C language, you need to learn how to write, compile and run the first c program.
To write the first c program, open the C console and write the following code:

#include stdio.h includes the standard input output library functions. The printf() function is defined in stdio.h .
void main() The main() function is the entry point of every program in c language.
printf() The printf() function is used to print data on the console.

How to compile and run the c program

There are 2 ways to compile and run the c program, by menu and by shortcut.
By menu

Now click on the compile menu then compile sub menu to compile the c program. Then click on the run menu then run sub menu to run the c program.

By shortcut

Or, press ctrl+f9 keys compile and run the program directly. You will see the following output on user screen.

What is a compilation?

The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code. Compilation process in c The c compilation process converts the source code taken as input into the object code or machine code. The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and Linking. The preprocessor takes the source code as an input, and it removes all the comments from the source code. The preprocessor takes the preprocessor directive and interprets it. For example, if stdio.h, the directive is available in the program, then the preprocessor interprets the directive and replace this directive with the content of the 'stdio.h' file.

printf() and scanf() in C

The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file). printf() function
The printf() function is used for output. It prints the given statement to the console. printf("format string",argument_list);
scanf() function
The scanf() function is used for input. It reads the input data from the console. scanf("format string",argument_list);

Program to print sum of 2 numbers

Variables in C

A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
Let's see the syntax to declare a variable: The example of declaring the variable is given below: int a; float b; char c;
Rules for defining variables
A variable can have alphabets, digits, and underscore.
A variable name can start with the alphabet, and underscore only. It can't start with a digit.
No whitespace is allowed within the variable name.
A variable name must not be any reserved word or keyword, e.g. int, float, etc.

>Types of Variables in C

There are many types of variables in c: local variable global variable static variable automatic variable external variable

Local Variable

A variable that is declared inside the function or block is called a local variable. void function1(){ int x=10;//local variable }

Global Variable

A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions.

int value=20;//global variable void function1(){
int x=10;      //local variable
}

Static Variable

A variable that is declared with the static keyword is called static variable. It retains its value between multiple function calls.

void function1(){
int x=10;      //local variable
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d,%d",x,y);
}

Automatic Variable

All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using auto keyword.

void main(){
int x=10;       //local variable (also automatic)
auto int y=20;      //automatic variable
}

External Variable

We can share a variable in multiple C source files by using an external variable. To declare an external variable, you need to use extern keyword.

myfile.h
extern int x=10;      //external variable (also global)

C - Storage Classes

A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program −

auto
register
static
extern

C Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −

Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators

Arithmetic Operators

OPERATOR MEANING EXAMPLE
+ Adds two operands A + B = 30
Subtracts second operand from the first A − B = -10
* Multiplies both operands A * B = 200
/ Divides numerator by de-numerator B / A = 2
++ Increment operator increases the integer value by one A++ = 11
-- Decrement operator decreases the integer value by one A-- = 9

Relational Operators

Operator Description Example
== Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true.
!= Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true.
> Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A > B) is not true.
< Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. (A <= B) is true.

Logical Operators

Operator Description Example
&& Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false.
|| Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true.
! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A && B) is true.

Bitwise Operators

Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is as follows −

p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1

We Build Your Business Online

Contact Us

Fell Free And Friendly To Contact Us.

Address

183, Uncha Mohalla Kaseru Khera, Meerut

Phone Number

7017742830