0% found this document useful (0 votes)
7 views30 pages

Overview of C Programming Language

The C programming language was developed in 1972 by Dennis Ritchie at AT&T's Bell Laboratories to address issues in previous languages and is known for its simplicity, portability, and efficiency. It features a rich library, dynamic memory management, and supports structured programming, making it a versatile mid-level language. Additionally, C utilizes tokens such as keywords, identifiers, and operators, and is foundational in algorithm design, serving various applications in computer science and artificial intelligence.

Uploaded by

Preeti Gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views30 pages

Overview of C Programming Language

The C programming language was developed in 1972 by Dennis Ritchie at AT&T's Bell Laboratories to address issues in previous languages and is known for its simplicity, portability, and efficiency. It features a rich library, dynamic memory management, and supports structured programming, making it a versatile mid-level language. Additionally, C utilizes tokens such as keywords, identifiers, and operators, and is foundational in algorithm design, serving various applications in computer science and artificial intelligence.

Uploaded by

Preeti Gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C programming language was developed in

1972 by Dennis Ritchie at bell laboratories of


AT&T (American Telephone & Telegraph),
located in the U.S.A.
Dennis Ritchie is known as the founder of the
c language.
It was developed to overcome the problems
of previous languages such as B, BCPL, etc.
Initially, C language was developed to be used
in UNIX operating system.
It inherits many features of previous
languages such as B and BCPL.

Why Name “C” was given to Language ?


Many of C’s principles and ideas were derived
from the earlier language B
BCPL and CPL are the earlier ancestors of B
Language
• CPL is common Programming [Link]
1967, BCPL Language ( Basic CPL ) was
created as a scaled down version of CPL
• As many of the features were derived
from “B” Language thats why it was named as
“C”.
• After 7-8 years C++ came into existence
which was first example of object oriented
Aprogramming .
Features of C Language

C is the widely used language. It provides


many features that are given below.
1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers

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.

2) Machine Independent or Portable


Unlike assembly language, c
programs can be executed on different
machines with some machine specific
changes. Therefore, C is a machine
independent language.

3) Mid-level programming language


Although, C is intended to do low-level
programming. It is used to develop
system applications such as kernel,
driver, etc. It also supports the features
of a high-level language. That is why it is
known as mid-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. So, it
is easy to understand and modify.
Functions also provide code reusability.

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

A token in C can be defined as the smallest individual element of the C


programming language that is meaningful to the compiler. It is the basic
component of a C program.

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:

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned z
continue for signed void
default goto sizeof volatile
do if static while

2. Identifiers in C are used for naming variables, functions,


arrays, structures, etc. Identifiers in C are the user-defined words. It
can be composed of uppercase letters, lowercase letters,
underscore, or digits, but the starting letter should be either an
underscore or an alphabet. Identifiers cannot be used as keywords.
Rules for constructing identifiers in C are given below:

o The first character of an identifier should be either an alphabet or


an underscore, and then it can be followed by any of the character,
digit, or underscore.
o It should not begin with any numerical digit.
o In identifiers, both uppercase and lowercase letters are distinct.
Therefore, we can say that identifiers are case sensitive.
o Commas or blank spaces cannot be specified within an identifier.
o Keywords cannot be represented as an identifier.
o The length of the identifiers should not be more than 31 characters.
o Identifiers should be written in such a way that it is meaningful,
short, and easy to read.

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

It should be noted that, octal and hexadecimal integer constants are


rarely used in programming.

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

Some special characters are used in C, and they have a


special meaning which cannot be used for another
purpose.
Square brackets [ ]: The opening and closing
brackets represent the single and multidimensional
subscripts.
o Simple brackets ( ): It is used in function

declaration and function calling. For example,


printf() is a pre-defined function.
o Curly braces { }: It is used in the opening and

closing of the code. It is used in the opening and


closing of the loops.
o Comma (,): It is used for separating for more than

one statement and for example, separating


function parameters in a function call, separating
the variable when printing the value of more than
one variable using a single printf statement.
o Hash/pre-processor (#): It is used for pre-processor

directive. It basically denotes that we are using the


header file.
o Asterisk (*): This symbol is used to represent

pointers and also used as an operator for


multiplication.
o Tilde (~): It is used as a destructor to free memory.

o Period (.): It is used to access a member of a

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.

C Variables: Declaration & Initialization of C Variables


C variables are names used for storing a data value to locations in memory. The value stored
in the c variables may be changed during program execution.
Declaration of Variable
Declaration of variable in c can be done using following syntax:
data_type variable_name;
or
data_type variable1, variable2,…,variablen;
where data_type is any valid c data type and variable_name is any valid identifier.
For example,
int a;
float variable;
float a, b;

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.

Constant and Volatile Variables


Constant Variables
C variables having same or unchanged value during the
execution of a program are called constant variables. A variable
can be declared as constant using keyword const.
For example,
1 const int a=100;
Now, if we try to change its value, then it is invalid.
Volatile Variables
Those variables that can be changed at any time by some
external sources from outside or same program are called
volatile variables.
Any variable in c can be declared as volatile using keyword
volatile.
Syntax
volatile data_type variable_name;

*Datatype from mam ppt


*INPUT-OUTPUT IN C from mam ppt
*Difference between #include and
#include” ” from mam ppt
What is PseudoCode
A Pseudocode is defined as a step-by-step description of
an algorithm. Pseudocode does not use any
programming language in its representation instead it
uses the simple English language text as it is intended
for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea
and its implementation(code) in a high-level language.

What is the need for Pseudocode


Pseudocode is an important part of designing an
algorithm, it helps the programmer in planning the
solution to the problem as well as the reader in
understanding the approach to the problem.
Pseudocode is an intermediate state between algorithm
and program that plays supports the transition of the
algorithm into the program.
Algorithm Pseudocode

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.

These are fake


codes as the
These are a word pseudo
sequence of steps means fake,
of a solution to a using code like
problem structure and
plain English
text

There are no rules


There are
to writing
certain rules for
algorithms
Algorithm Pseudocode

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.

Write an algorithm to find the largest among three different


numbers entered by user.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b If a>c Display a is the largest number. Else Display
c is the largest number. Else If b>c Display b is the largest
number. Else Display c is the greatest number.
Step 5: Stop
Write the advantages of FlowCharts.
Following are the various advantages of
flowchart:
o Communication: A flowchart is a better way of
communicating the logic of a program.
o Synthesis: Flowchart is used as working
smodels in designing new programs and
software systems.
o Efficient Coding: Flowcharts act as a guide for
a programmer in writing the actual code in a
high-level language.
o Proper Debugging: Flowcharts help in the
debugging process.
o Effective Analysis: Effective analysis of logical
programs can be easily done with the help of
a related flowchart.
o Proper Documentation: Flowchart provides
better and proper documentation. It consists
of various activities such as collecting,
organizing, storing, and maintaining all related
program records.
o Testing: A flowchart helps in the testing
process.
Efficient program maintenance: The
maintenance of the program becomes easy
with the help of a flowchart.
Flowchart:
Flowcharts are nothing but the graphical representation
of the data or the algorithm for a better understanding
of the code visually. It is a pictorial way of representing
steps that are preferred by most beginner-level
programmers to understand algorithms of computer
science
Flowchart symbols:
The different flowchart symbols have different
conventional meanings.
The various symbols used in Flowchart Designs are
given below.
o Terminal Symbol: In the flowchart, it is

represented with the help of a circle for denoting


the start and stop symbol. The symbol given below
is used to represent the terminal symbol.

o Input/output Symbol: The input symbol is used to


represent the input data, and the output symbol is
used to display the output operation. The symbol
given below is used for representing the
Input/output symbol.

o Processing Symbol:It is represented in a flowchart


with the help of a rectangle box used to represent
the arithmetic and data movement instructions.
The symbol given below is used to represent the
processing symbol.

o Decision Symbol: Diamond symbol is used for


represents decision-making statements. The
symbol given below is used to represent the
decision symbol.

o Connector Symbol:The connector symbol is used if


flows discontinued at some point and continued
again at another place. The following symbol is the
representation of the connector symbol.

o Flow lines: It represents the exact sequence in


which instructions are executed. Arrows are used
to represent the flow lines in a flowchart. The
symbol given below is used for representing the
flow lines:

operators: From greekforgreek


o

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 In this the o In this module must


o 4. communications is less have
among modules. communication.

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 This is not natural


o In this implementation
o 8. for people to
details may differ.
assemble.

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.

Jump statements are used to transfer control from one


point to another point in the program due to some
specified code while executing the program. There are
five keywords in the Jump Statements:

• break
• continue
• goto
• return

if -else/loop/switch diff of entry &exit-from


greekgreek

You might also like