My Basket
You have nothing in your shopping cart yet.
Title: Full C language
Description: All detailed notes of C language with programs and examples
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
HI - TECH COMPUTERS
C Programming
The C Language is developed by Dennis Ritchie for creating
system applications that directly interact with the hardware
devices such as drivers, kernels, etc
...
Mother language
TE
CH
It can be defined by the following ways:
System programming language
Procedure-oriented programming language
Structured programming language
Mid-level programming language
1) C as a mother language
C language is considered as the mother language of all the
modern programming languages because most of the compilers,
JVMs, Kernels, etc
...
It
provides
-
programming languages follow C syntax, for example, C++, Java,
the
core
concepts
like
the
array,
strings,
functions, file handling, etc
...
2) C as a system programming language
A
system
programming
language
is
used
to
create
system
software
...
It is generally used to create hardware devices,
OS,
drivers,
kernels,
etc
...
It can't be used for internet programming like Java,
...
C - LANGUAGE
1
HI - TECH COMPUTERS
3) C as a procedural language
A
procedure
is
known
as
a
function,
method,
routine,
subroutine, etc
...
A procedural language breaks the program into functions, data
structures, etc
...
In
C,
variables
and
function
prototypes must be declared before being used
...
Structure means to break a program into
parts or blocks so that it may be easy to understand
...
It
makes
modify
...
C
-
language program is converted into assembly code, it supports
pointer arithmetic (low-level), but it is machine independent
(a feature of high-level)
...
e
...
It is machine dependent, fast to run
...
A High-Level language is not specific to one machine, i
...
,
machine independent
...
C Program
#include
...
S
...
Dennis Ritchie is known as the founder of the c language
...
operating
C
language
system
...
Let's see the programming languages that were developed before
C language
...
It provides many features that
are given below
...
Simple
2
...
Mid-level programming language
4
...
Memory Management
7
...
Pointers
9
...
Extensible
1) Simple
C
is
a
simple
language
TE
CH
5
...
Unlike
-
2) Machine Independent or Portable
assembly
different
language,
machines
with
c
programs
some
machine
can
be
executed
specific
on
changes
...
HI
3) Mid-level programming language
Although, C is intended to do low-level programming
...
It also supports the features of a high-level language
...
4) Structured programming language
C is a structured programming language in the sense that we
can break the program into parts using functions
...
Functions also provide code
reusability
...
6) Memory Management
It supports the feature of dynamic memory allocation
...
7) Speed
there
are
lesser
TE
CH
The compilation and execution time of C language is fast since
inbuilt
overhead
...
We can directly interact
with the memory by using the pointers
...
9) Recursion
In
C,
we
provides
can
code
call
the
function
reusability
for
within
every
the
function
...
It
Recursion
10) Extensible
C
language
-
enables us to use the approach of backtracking
...
First C Program
Before starting the abcd of C language, you need to learn how
to write, compile and run the first c program
...
h>
int main(){
printf("Hello C Language");
return 0;
}
C - LANGUAGE
5
HI - TECH COMPUTERS
#include
...
The printf() function is defined in stdio
...
int main() The main() function is the entry point of every
program in c language
...
return 0 The return 0 statement, returns execution status to
unsuccessful execution
...
The 0 value is used for successful execution and 1 for
How to compile and run the c program
By menu
Now click on the compile menu then compile sub menu to compile
the c program
...
By shortcut
Or, press ctrl+f9 keys compile and run the program directly
...
-
c program output
You can view the user screen any time by pressing the alt+f5
keys
...
What is a compilation?
The compilation is a process of converting the source code
into object code
...
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
...
The compilation
process can be divided into four steps, i
...
, Pre-processing,
Compiling, Assembling, and Linking
...
The
preprocessor takes the preprocessor directive and interprets
it
...
h>, the directive is available in
the program, then the preprocessor interprets the directive
and replace this directive with the content of the 'stdio
...
TE
CH
The following are the phases through which our program passes
before being transformed into an executable form:
● Preprocessor
● Compiler
● Assembler
● Linker
Preprocessor
The source code is the code which is written in a text editor
and the source code file is given an extension "
...
This
source code is first passed to the preprocessor, and then the
-
preprocessor expands this code
...
Compiler
The code which is expanded by the preprocessor is passed to
HI
the compiler
...
Or
we
can
say
that
the
C
compiler
converts
the
pre-processed code into assembly code
...
The
name
of
the
object
file
generated
by
the
assembler is the same as the source file
...
obj,' and in UNIX, the extension is
'o'
...
c', then the
name of the object file would be 'hello
...
C - LANGUAGE
7
HI - TECH COMPUTERS
Linker
Mainly, all the programs written in C use library functions
...
lib'
(or
'
...
The main working of the linker is to combine the
object
code
program
...
It links the object code
of these files to our program
...
The
output of the linker is the executable file
...
In
DOS,
the
extension
of
the
executable file is '
...
out'
...
Let's understand through an example
...
c
HI
1
...
h>
2
...
{
4
...
return 0;
6
...
e
...
c, is passed to the
preprocessor,
code
into
and
the preprocessor converts the source
expanded
source
code
...
i
...
The extension of the assembly code would
be hello
...
TE
CH
● This assembly code is then sent to the assembler, which
converts the assembly code into object code
...
The
loader
will
then
load
the
executable file for the execution
...
Both functions are inbuilt library
functions, defined in stdio
...
-
printf() function
The printf() function is used for output
...
The syntax of printf() function is given below:
HI
printf("format string",argument_list);
The
format
string
can be %d (integer), %c (character), %s
(string), %f (float) etc
...
It reads the input
data from the console
...
C - LANGUAGE
9
HI - TECH COMPUTERS
#include
...
The
printf("cube
of
number
is:%d
",number*number*number)
statement prints the cube of number on the console
...
#include
...
It is used to
many times
...
Its value can be changed, and it can be reused
It is a way to represent memory location through symbol so
that it can be easily identified
...
The int, float, char are the data
types
...
8;
char c='A';
Rules for defining variables
A variable can have alphabets, digits, and underscore
...
It can't start with a digit
...
C - LANGUAGE
11
HI - TECH COMPUTERS
A variable name must not be any reserved word or keyword, e
...
int, float, etc
...
It must be declared at the start of the block
...
C - LANGUAGE
12
HI - TECH COMPUTERS
Global Variable
A variable that is declared outside the function or block is
called a global variable
...
It is available to all the functions
...
int value=20;//global variable
int x=10;//local variable
}
Static Variable
TE
CH
void function1(){
A variable that is declared with the static keyword is called
static variable
...
void function1(){
int x=10;//local variable
-
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d,%d",x,y);
HI
}
If you call this function many times, the local variable will
print the same value for each function call, e
...
But
the static variable will print the incremented
value in each function call, e
...
11, 12, 13 and so on
...
We can explicitly declare an
automatic variable using auto keyword
...
TE
CH
external variable
...
c
#include "myfile
...
h>
void printValue(){
printf("Global variable: %d", global_variable);
}
-
Data Types in C
A data type specifies the type of data that a variable can
store such as integer, floating, character, etc
...
Data Types
Basic Data Type
int, char, float, double
Derived Data Type
array, pointer, structure, union
Enumeration Data Type
enum
Void Data Type
void
HI
Types
C - LANGUAGE
14
HI - TECH COMPUTERS
Basic Data Types
The
basic
data
types
are
integer-based
and
floating-point
based
...
The memory size of the basic data types may change according
to 32 or 64-bit operating system
...
Its size is given according to
32-bit architecture
...
You cannot use it as a variable
name, constant name, etc
...
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
HI
auto
-
A list of 32 keywords in the c language is given below:
C - LANGUAGE
16
HI - TECH COMPUTERS
C Identifiers
C
identifiers
example,
represent
variables,
the
name
functions,
in
the
arrays,
C
program,
structures,
for
unions,
labels, etc
...
If the identifier is not used in the external linkage, then it
is called as an internal identifier
...
We can say that an identifier is a collection of alphanumeric
characters that begins either with an alphabetical character
or
an
underscore,
programming
elements
structures,
unions,
characters
which
such
are
as
labels,
(uppercase
and
used
to
represent
various
variables,
functions,
arrays,
etc
...
is
a
total
of
63
alphanumerical
characters
-
There
represent the identifiers
...
is
simply
There
can
a
symbol
that
is
be
many
types
of
used
to
perform
operations
like
arithmetic, logical, bitwise, etc
...
● Arithmetic Operators
● Shift Operators
● Logical Operators
● Bitwise Operators
TE
CH
● Relational Operators
● Ternary or Conditional Operators
● Assignment Operator
Precedence of Operators in C
The precedence of operator species that which operator will be
evaluated
first
and
next
...
-
operator direction to be evaluated; it may be left to right or
Let's understand the precedence by the example given below:
1
...
The
precedence
and
associativity
of
C
operators
is
below:
C - LANGUAGE
18
given
HI - TECH COMPUTERS
Category
Operator
Associativity
Postfix
() [] ->
...
, on the given operands
...
are the
examples of arithmetic operators
...
(+)
Operator
used
to
add
two
given
operands
...
Syntax
C = A + B;
For example, there are two operands, 5 and 6, and we want to
the
sum
of
these
numbers
...
#include
...
h>
int main ()
{
// declare integer variables
int num1, num2, res;
// declare float data type number
float f1, f2, res1;
// declare double variables
double d1, d2, res2;
printf (" Enter two integer numbers: ");
scanf ("%d %d", &num1, &num2);
res = num1 + num2; // use + operator
C - LANGUAGE
20
HI - TECH COMPUTERS
printf (" Enter two float numbers: \n ");
scanf ("%f %f", &f1, &f2);
res1 = f1 + f2; // use + operator
printf (" Enter two double data type numbers: \n ");
scanf ("%lf %lf", &d1, &d2);
res2 = d1 + d2; // use + operator
TE
CH
printf (" The sum of two integer numbers: %d \n", res);
printf (" The sum of two float numbers: %f \n ", res1);
printf (" The sum of two double numbers: %lf", res2);
return 0;
}
Output
Enter two integer numbers: 25
35
Enter two float numbers:
79
...
79
Enter two double data type numbers:
234
...
341
The sum of two integer numbers: 60
The sum of two float numbers: 147
...
464000
Minus Operator
The minus operator is denoted by the minus (-) symbol
...
different
The
types,
data
such
as
type
int,
of
the
float,
given
number
double,
long
can
double,
etc
...
C - LANGUAGE
be
21
HI - TECH COMPUTERS
Syntax
C = A - B;
For example, there are two operands, 15 and 6, and we want
their subtraction result
...
/* program to subtract the two numbers using minus operator */
#include
...
h>
// declare integer variables
int num1, num2, res;
// declare float data type number
float f1, f2, res1;
// declare double variables
double d1, d2, res2;
printf (" Enter two integer numbers: ");
-
scanf ("%d %d", &num1, &num2);
res = num1 - num2; // use + operator
printf (" Enter two float numbers: \n ");
HI
scanf ("%f %f", &f1, &f2);
res1 = f1 - f2; // use + operator
printf (" Enter two double data type numbers: \n ");
scanf ("%lf %lf", &d1, &d2);
res2 = d1 - d2; // use + operator
printf
("
The
subtraction of two integer numbers: %d \n",
("
The
subtraction
res);
printf
of
two
float
numbers: %f \n ",
res1);
printf (" The subtraction of two double numbers: %lf", res2);
return 0;
}
C - LANGUAGE
22
HI - TECH COMPUTERS
Output
Enter two integer numbers: 56
11
Enter two float numbers:
78
...
45
Enter two double data type numbers:
1234
...
7149
The subtraction of two integer numbers: 45
The subtraction of two float numbers: 22
...
916200
Multiplication Operator
The multiplication operator is represented as an asterisk (*)
symbol, and it is used to return the product of n1 and n2
numbers
...
C = A * B;
HI
For example, there are two operands 15 and 6, and we want to
get their product
...
/* program to multiply two numbers using astrisk (*) operator
...
h>
#include
...
5
3
...
324
798
...
750000
C - LANGUAGE
24
%lf",
HI - TECH COMPUTERS
The multiplication of two double numbers: 187019
...
Using
division
operator (/), we can divide the int, float, double and long
Syntax
C = A / B;
TE
CH
data types variables
...
5 and 5
...
So, we use the '/' Operator
between the given numbers that return float data 5
...
/* program to divide the first number by second number using
division (/) operator
...
h>
#include
...
32
248
...
7691
687
...
862247
The division of two double numbers: 6
...
Syntax
C = A % B;
For example, there are two operands 25 and 4, and we want to
get
their
modulus
result
...
/*
program
to
return
the
remainder
of
two
numbers
modulus (%) operator
...
h>
#include
...
It
is
used
A
is
10,
to
increase the integer value by 1
...
C - LANGUAGE
27
HI - TECH COMPUTERS
/* program to demonstrate the increment (++) operator
...
h>
#include
...
Syntax
B = A--;
For
example,
decrement
suppose
operator
the
integer
decreases
the
value
operand
of
A
value
is
by
10,
the
1
that
returns 9
...
*/
#include
...
h>
int main ()
C - LANGUAGE
28
HI - TECH COMPUTERS
{
// declare integer variables
int num1, res;
printf (" Enter the positive number: ");
scanf ("%d", &num1);
res = num1--; // use decrement operator
printf (" The decremented value is: %d ", num1);
TE
CH
return 0;
}
Output
Enter the positive number: 10
HI
-
The decremented value is: 9
C - LANGUAGE
29
HI - TECH COMPUTERS
Relational Operator in C
Relational
Operators
are
the
operators
used
to
create
a
relationship and compare the values of two operands
...
Equal To Operator (==)
TE
CH
Types of Relational Operators
It is used to compare both operands and returns 1 if both are
equal or the same, and 0 represents the operands that are not
equal
...
#include
...
h>
int main ()
HI
{
int a = 5;
int b = 10;
// Use Equal To Operator
printf (" a == b : %d", (a == b));
if (a == b)
printf ("\n %d is equal to %d", a, b);
else
printf (" \n %d is not equal to %d", a, b);
C - LANGUAGE
30
HI - TECH COMPUTERS
int x = 5;
int y = 5;
// Use Equal To Operator
printf (" \n x == y : %d", (x == y));
if (a == b)
printf (" \n %d is equal to %d", x, y);
else
return 0;
}
Output
a == b : 0
5 is not equal to 10
x == y : 1
5 is not equal to 5
TE
CH
printf ("\n %d is not equal to %d", x, y);
-
Not Equal To Operator (!=)
The Not Equal To Operator is the opposite of the Equal To
Operator
and
is
represented as the (!=) operator
...
Syntax:
Opr1 != Opr2;
Let's create a simple program to use the Not equal to (!=)
operator for comparing the values of variable in C
...
h>
#include