C language
Language : The way of communication between two persons.
Programming language : The way of communication between man and machine.
Communication Man machine
1. English 1. Instruction\commands
2. Hindi 2. Set of instruction
3. Punjabi 3. Program
4. Sign 4. Written in some language is called
programming language .
History:
C language was developed by Dennis M Ritchie At &T Bell labs,USA
in 1972.
year /name full form used for
formula application
fortran(1957)
translation software
commom
cobol (1960) busines
busines
basic combined general
bcpl (1967) programming purpose with
langugae issues
general
b(1970) basic purpose with
issues
general
c(1972) combined purpose no
issues
Why c language is still important even after around 50 years .
C programming language was develop to write UNIX operating system but
after lots of application and system software were written in c language .
For example:
1. Most of libraries of today operating system are written in c language for
ex: UNIX , LINUX , WINDOW,MAC, android etc.
2. Language compilers : C,C++,JAVA ,C# ,etc.
3. Database software: Oracle, My Sql , etc.
4. Text editors: Notepad, Wordpad, Microsoft office etc.
5. Device driver : printer, scanner, phone ,pen drive etc (for output).
6. Major parts of web browser : Google Chrome ,Internet ,Explorer ,Mozilla
Firebox etc.
7. Virus & Antivirus.
8. Robotics ,embedded system and IOT (internet of things).
Features \characteristics of language :-
There are lots of features or character of c language due to which it is
still famous enough even after around 50 years of development and its
main features are :-
1. General purpose programming language .
2. Powerful programming language .
3. Procedure oriented programming language .
4. Structured programming language .
5. Simple and small programming language .
6. Middle level programming language .
7. System programming language .
8. Protable \ machine independent programming language .
9. Extensible programming language .
[Link] free programming language .
[Link] sensitive programming language .
[Link] \statically typed programming language .
Stages to learn any language :-
Any language English language Programming language
1. Letters A to Z or a to z Character
2. Words Cat ,Rat ,Bat Tokens
3. Sentences with What is HTML Instruction
4. Paragraphs ( HTML stands for hyper text Program
Markup language. This is a language to develop a webpage).
C language character set :
C language support total 256 characters it includes .
Four type of character set:-
1. Alphabets :- Uppercase letters A to Z, Lowercase a to z.
2. Decimal digits :- 0 to 9( 1,2,3,4,5,6,7,8,9) .
3. Special symbols :- +, ,-, =, :, ;, (), {},*
4. White space :- Blankspace , tabspace ,/n(use for new line ).
Note :A Character set supports ASCII(American standed code for
information interchange ).
1. For every character in C , there is a unique number given in ASCII
character set .
2. ASCII character is of 8 bit .
3. Some of the mostly used ASCII number are :-
0 null character /0
32 blank space /space
48-57 for 0 to 9
65-90 for A to Z
97-122 for a to z
Tokens
1. The smallest individual unit of any program .
2. We can not split tokens further ,so tokens are individual .
3. Every instruction of a program is collection of tokens .
4. Since tokens are used to construct a program .So they are also called as
building blocks of the programming .
For ex:- int a = 5
Keywords
1. Special predefined words fixed by LA – invento.
2. Keywords can only be issue for by intended purpose .
3. Keywords cannot be re-defined by the programmer .
4. All keywords are written in lowercase .
5. There are total 32 keywords in programming language .
6. Keywords are sometimes also called reserved words .
Identifiers
1. User defined names given to any variable array , function, structure and
union, 12 enumeration files .
Rules for writing identifiers :-
1. All the alphabet(A to Z) are allowed (uppercase or lowercase ).
2. All digit (0-9) are allowed .
3. Only underscore (_) is allowed from special symbols .
4. Identifier can start with either alphabets or underscore .It can not
start with any digit .
5. No space allowed in a identifier .
6. The identifier must not be any keyword or reserved word .
7. Length of an identifier depends on machine to machine (32 bit or 64
bit) but advisable limit is 32 characters .
Constants /literals
It refers to a fixed value that does not change during program execution
.
constants
numberic character
constants constants
double
single
integer real/float charater
character
/string
Defination :-
1. Integer constants :- A sequence of digit without decimal point or
expontial point .
2. Real /float :- A constants which contains either a decimal pointer or
exponent called real /float .
3. Single character :- It contains single character enclosed in single
quotation mark .
4. String /double character :- It contains any number of enclosed or double
quotes .
Ex:- Integer (5,10,-10,) .
Real float :- 7.5 ,10.3,-10.999 .
Single character :- ‘A’.
Double character /string :- “ABC” .
Variables
Variables are used to store values .The value of the variable can be changed as
required by the program .
Data types
Data types are used to define a variable before to use in a program .
4 types of data types in C language . 1. Basic 2. Derived 3. Enumeration 4. Void.
1. Basic data type :- The basic data type are integer based and floating point
based .The memory size of basic data types may change according to 32
or 64 bit operating system .
Data type Memory size Range
Char 1 byte -128 to 127
Int 2 byte -32,768 to 32,767
Float 4 byte
Double 8 byte
Long double 10 byte
2. Derived data type :- The drive that are derived from primitive data type .The
derived data types can be used to represent a single value or multiple values.
Array :-Array is a derived data types used to store more than one value
in asequence memory location . Array can not contain dis-similar type of
data .The size of array index is start with 0 to n-1
Syntax :- Int a(5)
Pointer :- Pointer is a variable that can be able to hold address of
another variable .While working with pointer we need to require two
special operation .
(1) & - address of operator .
(2) *- value at address operator .
Int a = 10
Int *p = &a
Structure :-Structure is a used define name which are used to store a group of
different types of values like int , char , float , struct keyword is used to declare
structure .The size of structure depends on the members of structure . Union :-
Union is a used define name which are used to store a group of different types of
values like int , char , float .
Union keywords is used to declare union , The size of union depends on the
biggest member of union .
[Link] data type :- The enum in C also known as the enumeration
type. It is user defined data types that consist of integer values and it provides
meaningful name to these values .
[Link] data type :- void is an empty data type that has no value , we use void
data type in functions when we don’t want to return any value to the calling
function .
Void sum ( int a , int b ).This function won’t return any values to the calling
function .
Int sum (int a , int b ) This function will return any values to the calling
function .
Basic structure of C program :-
1. Documentation /commenting .
2. Header files inclusion .
3. Macro definition (if any ).
4. Global variable declaration .
Main function ( )
{
printf function
scan of function
} (ending )
Header file:- We start the program with header file .
1. # include < stdio . h >
2. # include < conio . h >
3. # include < math . h >
4. # include < string . h >
Pre processor directive :- Stdio – Standard input /output
header files .
. H – Header files .
#include < stdio . h > :- That means standard input output header files
include in pre processer directive it has information related to input output
functions .
< stdio . h > for scan ( ) and printf ( ) .
#include <conio :- console input /output header file .
. h :- header file .
#include <conio . h > :- C header file used mostly by MS-DOS
compilers to provide console input / output . It is not part of c
standard library .
Getch ( )
Clrscr ( )
#include . math . h .> used for mathematics functions .
Function :-
Main ( )for all program
printf ( ) for print output
scan ( ) for enter input
Printf 9 ) function :- The general form of printf(“ CONTROL STRING >” ,LIST
OF VARIABLES >).
% D= INTEGER VALUE
% F = FLOAT VALUE
%C = CHARACTER VALUE
FOR EX :- A program in c print any output in two lines :
Program :-
#include <stdio.h>
Int main ()
{
printf(“Today is Monday” );
printf(“Number is prime”);
Return 0;
Output :-
Today is Monday .
Number is prime .
Contral N for page
\n for new line
N% address of variable
scanf() function :- scanf () function is used to read the values of variables through
keyword . Format of scanf function is scanf(“<control string”>,&variable,variable);
Program in c using scanf function:-
#include<stdio.h>
{
Int a,b;
printf(“enter the value of A”);
scanf(“%d”,&a);
printf(“Enter the value of B);
scanf(“%d”,&b);
Return 0;
Output :-
Enter the value of A: 15
Enter the value of B= 20
Operator in C language :- Operator is a symbol that tells the compiler to perform
mathematical and logical task .Operator is used to perform operator on a variable
.An operator is used to transform one of more values into a single resultant value.
For ex:-
C= a + b
Types of operator in C language :-
[Link] operator
[Link] operator
[Link] operator
[Link] operator
[Link] operator
[Link] operator
[Link] OPERATOR :- Arithmetic operator are used to performing
mathematical operators such as addition ,subtraction ,multiplication, divison
,moduls etc, on the given operands .
Arithmetic
meaning
operator
+ Addition
- Subtraction
* multipalication
divison
/
% moduls
[Link] OPERATOR :-Relational operators are the operators used to creat a
relation ship and compare the values of two operands .
LOGICAL OPERATOR :-Logical operator in C language used to combine multiple
condition/constraints .Logical operator returns either or 1,it depends on the
expression result true or false .In C programming for decision making ,we use
logical operator we have 3 major logical operators in the C language .
[Link] AND(& &)
[Link] OR (& &)
[Link] NOT (!)
BITWISE OPERATOR :-The bitwise operator are the operators used to perform the
operators on the data at the bit level .
Ternary operator Description Example
& Bitwise AND (10==20&20==33)false
| Bitwise OR (10==20|20==33)false
^ Bitwise XOR (10==20^20==33)false
~ Bitwise NOT (~10)=-10(true)
<< Left shift (10<<2)=40(true)
>> Right shift (10>>2)=20(true)
>>> Right shift with zero (10>>>2)=2(true)
TERNARY OPERATOR :-The conditional or ternary operator is kind of similar to the
if else statement .When we check the condition without if else statement we use
ternary operator .
Ternary operator :- (::)
Example :-
#include<stdio.h>
Int main()
Int a = 10,b = 20;
printf(“%d”, a>b)?
Return 0;
ASSIGNMENT OPERATOR :-The assignment operator is used to assign the value ,
variable and function to another variable .Lets discus the various type of the
assignment operator such as =,+=,-=,*=and %=.
operator description example
= assign 10+10=20
add and
+= .....
asign
subtract
-= .....
and assign
multipaly
*= ...
and assign
....
Write a program of two variable perform addition ,subtraction,multipal,divison
and moduls/arithmetic program .
#include<stdio.h>
Int main()
{
Int a=20,b=5
Int sum,sub,mul,mod;
Float div;
Sum=a+b;
Sub =a-b;
Mul =a*b;
Div =(float)a\b
Mod =a%b;
printf(“The addition of two no is : %d\n”,sum);
printf(“The subtraction of two no is :%d\n”,sub);
printf(“The multipal of two no is : %d\n”,mul);
printf(“Divison of two no is :%d\n”,div);
printf(modulus of two no is :%d\n”,mod);
Return 0;
Output :-The addition of two no is :25
The subtraction of two no is :15
The multipal of two no is :100
The divison of two no is :1.000000
The modulus of two no is :0
Write a program in C to calculate gross salary :-
#include<stdio.h>
Int main()
Int basic , ta , da , gross –salary ;
printf(“Enter the basic salary”);
scanf(“%d”,&basic);
Ta=(12*basic)/100;
Gross-salary=basic+ta+da;
printf(“n gross-salary:%d”,gross-salary)
Return 0;
Output :-Enter the basic salary=24000
Gross salary:29280
[Link] STRUCTURE :-Control statements: A computer program is a set of
instructions ,which is executed to do some intended task , these instruction are
also know as statement .Statements in a program are executed sequentially
under normal situations .
2. BRANCHING CONTROL STATEMENT :-These statement are used to execute a
group of instructions based on the result of same logical condition .These
statements are alsonknw as decision making statements .
Branching control statements:-
1. IF STATEMENT
2. IF-ELSE STATEMENT
3. IF –ELSE –IF STATEMENT
4. SWITCH STATEMENT
LOOPING CONTROL STATEMENT :-These statement are used to
execute a group of instructions repeatedly .Sometimes the required number of
repetitions will be know in advance and sometimes the segment of code will be
repeated until certain condition is satisfied .
1. WHILE LOOP
2. DO LOOP
3. FOR LOOP
4. NESTED LOOP
IF STATEMENT :-If statement is used when we want to test a condition .
Syntax :
If( condition)
Code to be executed
Example:-
#include<stdio.h>
Int main()
Int password ;
printf(“Enter password ……”);
scanf(“%d”,& password);
If (password ==2403)
printf(“welcome/n”);
}
printf(“main function ended “);
Return 0;
Output :- Enter password ……2403
Welcome
Main function ended .
STATEMENT :- It is used to execute two statement either if statement or else
statement for a single condition .
Syntax :
If (condition)
Code to be executed;
Example :-
#include<stdio.h>
Int main ()
Int age;
printf(“Enter age :\n”);
scanf(“%d”,&age);
If (age>=18)
}
else
printf(“Not eligible for vote “);
Return 0;
Output :-Enter age:
50
Eligible for vote
IF ELSE IF LADDER STATEMENT :-If else if ladder statement is used when we have
multiple (more than two) conditions .
Syntax :
Code to be executed;
else if (condition 2)
Code to be execute;
else
{
Code to be executed;
Example :-
#include<stdio.h>
Int main()
Int marks ;
printf(“Enter marks:\n”);
scanf(“%d”,& marks);
If (marks ==100)
printf(“genius”);
else if (marks>=80 & & marks <100)
printf(“topper”);
Else if (marks >=60 & & marks<80)
printf(‘first”);
else
{
printf(“average );
Return 0;
Output :-Enter marks:
80
Topper
NESTED IF ELSE STATEMENT :-Whenever we define called nested if else
statement.
Syntax:-
If (condition)
If(condition 2)
Code to be executed;
else
Code to be executed;
else
{
If (condition 3)
Code to be executed;
else
Code to be executed;
else
Code to be executed ;
SWITCH STATEMENT :-Switch statement used when we want to select anyone
case out of multiple case .
Syntax :-
Switch (example )
Case 1:statement;
Break;
Case 2:statement;
Break;
Default : statement ;
Break;
Example :-
#include<stdio.h>
Int main ()
Int a =30 , b =5 , c ;
Int ch ;
printf(“Enter choice” );
scanf(“%d”,& ch);
Switch (ch)
Case 1: c=a+b;
printf(“%d”,c);
Break ;
Case 2: c=a-b;
printf(“%d”,c);
Break;
Case 3: c=a*b;
printf(“%d”,c);
Break ;
Case 4:c=a\b;
printf(“%d”,c);
Break ;
Default ;
printf(invalid choice )
Break ;
Return 0;
Output :-
Enter choice :4
LOOPING CONTROL STATEMENT :-
WHAT IS LOOP?
Loop used to repeat a block of code until the given condition is true .
Types of loop:- 1. While loop 2. Do while 3. For loop
1. WHILE LOOP :-Loop is a entery control [Link] the condition after that the
statement will be executed.
2. DO WHILE LOOP:-Do while loop is an exit control [Link] while loop has
similar functionality to the while loop .The only difference being that the
condition is placed at the end of the block of statement in a do while loop.
As result the block of code executed at least once.
3. FOR LOOP :-For loop is an entry control loop. For loop is this loop
initialization, condition, increment, decrement perform in single
parenthesis().
NESTED LOOP:-A loop which contain inside another loop is called nested loop .
Syntax :-
For (initialization; condition;increment)
For (initialization; condition; increment)
Code to be executed
What is array ?
Array is a variable which store more than one values of same data type in a
continuous memory location . Array are derived data type in c programming
language which can store primitive data type such as int, char , double ,float etc.
Array can not contain dis similar type of data .Array index always begin with
unique identification a[0] called based index of array .The size of array index is
always 0 to [Link] can perform array in two ways.
1. One dimensional
2. Multi-dimensional arrays
What is string ?
String in c represented by arrays of character .The end of string is marked with a
special character , the null character , which is simply the character with the null
value [Link] other way we can say that string is a sequence of character and it
always ends with null (‘0’) character .
Function :- Function is a block if code which take input from user , processed it
and produce output .
Note :-
1. Functions are runs only when it is called .
2. Function is block of code .
User defined :- Void add(), int sum()
Pre defined :- printf() ,scanf(), strcpy(), puts ()
Call by value :- While calling a function we pass value of variable to it .Such
functions are known as “call by value “ for example – int a , int b
Call by reference :- While calling a function instead of passing the values of
variable , we pass address of variable , to the function are known as “ call by
reference” for ex :- int* a, int*b