Overview of C Programming Language
Overview of C Programming Language
1) Simple
C is a simple language in the sense that it
provides a structured approach (to break
the problem into parts), the rich set of
library functions, data types, etc.
5) Rich Library
C provides a lot of inbuilt functions that
make the development fast. Robust
libraries and functions in C help even a
beginner coder to code with ease.
6) Memory Management: It supports the feature of dynamic
memory allocation. In C language, we can free the allocated memory at
any time by calling the free() function.
7) Speed
The compilation and execution time of C language is fast since there are
lesser inbuilt functions and hence the lesser overhead.
8) Pointer
C provides the feature of pointers. We can directly interact with the memory by
using the pointers. We can use pointers for memory, structures, functions,
array, etc.
9) Recursion
In C, we can call the function within the function. It provides code reusability
for every function. Recursion enables us to use the approach of backtracking.
10) Extensible
C language is extensible because it can easily adopt new features. Programs
written in C language can be extended means when a program is already
written in it then some more features and operations can be added to it.
Tokens in C
Types of Tokens in C
The tokens of C language can be classified into six types based on the functions
they are used to perform. The types of C tokens are as follows:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
1. C Token – Keywords
The keywords are pre-defined or reserved words in a programming
language. Each keyword is meant to perform a specific function in a
program. Since keywords are referred names for a compiler, they can’t be
used as variable names because by doing so, we are trying to assign a
new meaning to the keyword which is not allowed. You cannot redefine
keywords. C language supports 32 keywords which are given below:
3. Strings in C
o Strings in C are always represented as an array of characters having null
character '\0' at the end of the string. This null character denotes the end
of the string. Strings in C are enclosed within double quotes, while
characters are enclosed within single characters. The size of a string is a
number of characters that the string contains.
o Now, we describe the strings in different ways:
o char a[10] = "javatpoint"; // The compiler allocates the 10 bytes to the 'a'
array.
o char a[] = "javatpoint"; // The compiler allocates the memory at the run
time.
o char a[10] = {'j','a','v','a','t','p','o','i','n','t','\0'}; // String is represented in the
form of characters.
4. C Constants
C constants refers to the data items that do not change their value
during the program execution. Several types of C constants that are
allowed in C are:
1. Integer Constants
Integer constants are whole numbers without any fractional part. It must
have at least one digit and may contain either + or – sign. A number with
no sign is assumed to be positive.
There are three types of integer constants:
1.1. Decimal Integer Constants
Integer constants consisting of a set of digits, 0 through 9, preceded by
an optional – or + sign.
Example of valid decimal integer constants
341, -341, 0, 8972
1.2. Octal Integer Constants
Integer constants consisting of sequence of digits from the set 0 through
7 starting with 0 is said to be octal integer constants.
Example of valid octal integer constants
010, 0424, 0, 0540
1.3. Hexadecimal Integer Constants
Hexadecimal integer constants are integer constants having sequence
of digits preceded by 0x or 0X. They may also include alphabets from A
to F representing numbers 10 to 15.
Example of valid hexadecimal integer constants
0xD, 0X8d, 0X, 0xbD
3. Real Constants
The numbers having fractional parts are called real or floating point
constants. These may be represented in one of the two forms called
fractional form or the exponent form and may also have either + or – sign
preceding it.
Example of valid real constants in fractional form or decimal notation
0.05, -0.905, 562.05, 0.015
Representing a real constant in exponent form
The general format in which a real number may be represented in
exponential or scientific form is
mantissa e exponent
The mantissa must be either an integer or a real number expressed in
decimal notation.
The letter e separating the mantissa and the exponent can also be
written in uppercase i.e. E
And, the exponent must be an integer.
Examples of valid real constants in exponent form are:
252E85, 0.15E-10, -3e+8
3. Character Constants
A character constant contains one single character enclosed within
single quotes.
Examples of valid character constants
‘a’ , ‘Z’, ‘5’
It should be noted that character constants have numerical values
known as ASCII values, for example, the value of ‘A’ is 65 which is its ASCII
value.
Special characters in C
structure or a union.
0
6. C Token – Operators
Operators are symbols that trigger an action when
applied to C variables and other objects. The data items
on which operators act are called operands.
Depending on the number of operands that an operator
can act upon, operators can be classified as follows:
*Unary Operators: Those operators that require only a
single operand to act upon are known as unary
[Link] Example increment and decrement
operators
*Binary Operators: Those operators that require two
operands to act upon are called binary operators. Binary
operators can further are classified into:
1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operator
*Ternary Operator: The operator that requires three
operands to act upon is called the ternary operator.
Conditional Operator(?) is also called the ternary
operator.
Initialization of Variable
C variables declared can be initialized with the help of assignment operator ‘=’.
Syntax
data_type variable_name=constant/literal/expression;
or
variable_name=constant/literal/expression;
Example
int a=10;
int a=b+c;
a=10;
a=b+c;
Multiple variables can be initialized in a single statement by single value, for example,
a=b=c=d=e=10;
NOTE: C variables must be declared before they are used in the c program. Also, since c is a
case sensitive programming language, therefore the c variables, abc, Abc and ABC are all
different.
A Pseudocode is
An Algorithm is
a step-by-step
used to provide a
description of
solution to a
an algorithm in
particular problem
code-like
in form of a well-
structure using
defined step-based
plain English
form.
text.
Pseudocode
also uses
An algorithm only
reserved
uses simple English
keywords like if-
words
else, for, while,
etc.
writing
pseudocode
Pseudocode
Algorithms can be
cannot be
considered
considered an
pseudocode
algorithm
It is difficult to It is easy to
understand and understand and
interpret interpret
Algorithm:-
” A procedure for solving a mathematical problem in a
finite number of steps that frequently involves recursive
operations”.
Use of the Algorithms: same for pseudocode
Algorithms play a crucial role in various fields and have
many applications. Some of the key areas where
algorithms are used include:
1. Computer Science: Algorithms form the basis of
computer programming and are used to solve
problems ranging from simple sorting and
searching to complex tasks such as artificial
intelligence and machine learning.
2. Mathematics: Algorithms are used to solve
mathematical problems, such as finding the
optimal solution to a system of linear equations or
finding the shortest path in a graph.
3. Operations Research: Algorithms are used to
optimize and make decisions in fields such as
transportation, logistics, and resource allocation.
4. Artificial Intelligence: Algorithms are the
foundation of artificial intelligence and machine
learning, and are used to develop intelligent
systems that can perform tasks such as image
recognition, natural language processing, and
decision-making.
5. Data Science: Algorithms are used to analyze,
process, and extract insights from large amounts of
data in fields such as marketing, finance, and
healthcare.
Properties of Algorithm:
It should terminate after a finite time.
It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same
output for the same input case.
• Every step in the algorithm must be effective i.e.
every step should do some work.
Characteristics:
• Clear and Unambiguous: The algorithm should be
unambiguous. Each of its steps should be clear in
all aspects and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take
inputs, it should be well-defined inputs. It may or
may not take input.
• Well-Defined Outputs: The algorithm must clearly
define what output will be yielded and it should be
well-defined as well. It should produce at least 1
output.
• Finite-ness: The algorithm must be finite, i.e. it
should terminate after a finite time.
• Feasible: The algorithm must be simple, generic,
and practical, such that it can be executed with the
available resources. It must not contain some
future technology or anything.
• Language Independent: The Algorithm designed
must be language-independent, i.e. it must be just
plain instructions that can be implemented in any
language, and yet the output will be the same, as
expected.
• Input: An algorithm has zero or more inputs. Each
that contains a fundamental operator must accept
zero or more inputs.
• Output: An algorithm produces at least one
output. Every instruction that contains a
fundamental operator must accept zero or more
inputs.
OR
Write the characteristics of an Algorithm.
• Input: An algorithm has some input values that can be zero or
more.
• Output: An algorithm produces one or more output values as the
result.
• Unambiguity: An algorithm is clear and simple, with no room for
confusion or interpretation.
• Finiteness: An algorithm stops after a finite number of steps are
executed.
• Effectiveness: An algorithm provides the correct and desired
solution for the problem.
Oper
o Preced ator o Descript o Associa
ence ion tivity
o Parenth
eses
o ()
(functio
n call)
o Array
Subscrip
t
o []
(Square
Brackets
)
o Left-to-
o 1 o Dot
Right
o . Operato
r
o Structur
e
o -> Pointer
Operato
r
o Postfix
o ++ , — increme
nt,
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
decrem
ent
o Prefix
increme
o ++ / — nt,
decrem
ent
o Unary
o +/– plus,
minus
o Logical o Right-to-
o 2
NOT, Bi Left
o !,~ twise
comple
ment
o Cast
o (type) Operato
r
o Derefer
o *
ence
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
Operato
r
o Address
of
o &
Operato
r
o Determi
o sizeof ne size
in bytes
o Multipli
cation,
o Left-to-
o 3 o *,/,% division,
Right
modulu
s
o Additio
n, o Left-to-
o 4 o +/-
subtract Right
ion
o Bitwise o Left-to-
o 5 o << , >>
shift Right
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
left,
Bitwise
shift
right
o Relation
al less
than,
o < , <=
less
than or
equal to
o Left-to-
o 6
o Relation Right
al
greater
o > , >= than,
greater
than or
equal to
o Relation
al is o Left-to-
o 7 o == , !=
equal Right
to, is
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
not
equal to
o Bitwise o Left-to-
o 8 o &
AND Right
o Bitwise
o Left-to-
o 9 o ^ exclusiv
Right
e OR
o Bitwise
o Left-to-
o 10 o | inclusiv
Right
e OR
o Logical o Left-to-
o 11 o &&
AND Right
o Logical o Left-to-
o 12 o ||
OR Right
o Ternary
o Right-to-
o 13 o ?: conditio
Left
nal
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
o Assignm
o =
ent
o Additio
n,
subtract
o += , -=
ion
assignm
ent
o Multipli
cation,
o Right-to-
o 14 o *= , /= division
Left
assignm
ent
o Modulu
s,
o %= , bitwise
&= AND
assignm
ent
o Bitwise
o ^= , |=
exclusiv
o
Oper
o Preced ator o Descript o Associa
ence ion tivity
e,
inclusiv
e OR
assignm
ent
o Bitwise
shift
o <<=, left,
>>= right
assignm
ent
o comma
(express
o Left-to-
o 15 o , ion
Right
separat
or)
o
o TOP
DOWN
APPROACH o BOTTOM UP APPROACH
o In bottom up
approach, we solve
o In this approach We focus
smaller problems
on breaking up the
o 1. and integrate it as
problem into smaller
whole and
parts.
complete the
solution.
o Mainly used by
o Mainly used by structured
object oriented
programming language
o 2. programming
such as COBOL, Fortran, C,
language such as
etc.
C++, C#, Python.
o Redundancy is
o Each part is programmed
minimized by using
o 3. separately therefore
data encapsulation
contain redundancy.
and data hiding.
o It is used in debugging,
o It is basically used
o 5. module documentation,
in testing.
etc.
o TOP
DOWN
APPROACH o BOTTOM UP APPROACH
o In bottom up
o In top down approach,
approach
o 6. decomposition takes
composition takes
place.
place.
o In this sometimes
o In this top function of we can not build a
o 7. system might be hard to program from the
identify. piece we have
started.
o Pros-
o Easier isolation of o Pros-
interface errors
o Easy to create test
o It benefits in the case conditions
error occurs towards the
o Test results are
o 9. top of the program.
easy to observe
o Defects in design get
o It is suited if defects
detected early and can be
occur at the bottom
corrected as an early
of the program.
working module of the
program is available.
o Gen of comp lang from greekforgreek
o Break:- The syntactic form of break statement is:
o break;
o KEY POINTS
o A break statement can appear only inside, or as a body
of, a switch statement or a loop.
o A break statement terminates the execution of the
nearest enclosing switch or the nearest enclosing loop.
o The execution resumes with the statement present next
to the terminated switch statement or terminated loop.
Continue:-
The syntactic form of continue statement is:
• continue;
KEY POINTS
✓ A continue statement can appear only inside, or as
the body of, a loop.
✓ A continue statement terminates the current
iteration of the nearest enclosing loop.
goto statement
This statement is used to transfer control to the
labeled statement in the program. The label is the
valid identifier and placed just before the statement
from where the control is transferred.
• break
• continue
• goto
• return