lOMoARcPSD|18872401
UNIT-II
BASICS OF C PROGRAMMING
Introduction to programming paradigms – Applications of C Language - Structure of C program - C
programming: Data Types - Constants – Enumeration Constants - Keywords – Operators: Precedence
and Associativity - Expressions - Input/Output statements, Assignment statements – Decision making
statements - Switch statement - Looping statements – Preprocessor directives - Compilation process.
INTRODUCTION TO PROGRAMMING PARADIGMS
Paradigm
Paradigm can also be termed as method to solve some problem or do some task.
Programming paradigms are a way to classify programming languages based on their features.
Programming paradigm
Programming paradigm is an approach to solve problem using some programming language.
It is a method to solve a problem using tools and techniques that are available to us following some approach.
There are lots for programming language that are known but all of them need to follow some strategy when
they are implemented and this methodology/strategy is paradigms.
Apart from varieties of programming language there are lots of paradigms to fulfill each and every demand.
Types of programming paradigms
• Imperative paradigm
• Functional paradigm
• Logic paradigm
• Object-oriented paradigm
, lOMoARcPSD|18872401
Imperative programming paradigm:
• It is one of the oldest programming paradigm.
• It features close relation to machine architecture.
• It is based on Von Neumann architecture. It works by changing the program state through assignment
statements.
• It performs step by step task by changing state.
• The main focus is on how to achieve the goal.
• The paradigm consists of several statements and after execution of all the result is stored.
• Language representatives (FORTRAN, ALGOL, Pascal, Basic, C).
Advantage:
• Very simple to implement
• It contains loops, variables etc.
Disadvantage:
• Complex problem cannot be solved
• Less efficient and less productive
• Parallel programming is not possible
Procedural programming paradigm
• This paradigm emphasizes on procedure in terms of under lying machine model.
• There is no difference in between procedural and imperative approach.
• It has the ability to reuse the code and it was boon at that time when it was in use because of its
reusability.
Object oriented programming
• The program is written as a collection of classes and object which are meant for communication.
• The smallest and basic entity is object and all kind of computation is performed on the objects only.
• More emphasis is on data rather procedure.
• It can handle almost all kind of real life problems which are today in scenario.
Advantages:
• Data security
• Inheritance
• Code reusability
• Flexible and abstraction is also present
Parallel processing approach –
• Parallel processing is the processing of program instructions by dividing them among multiple
processors.
• A parallel processing system posses many numbers of processor with the objective of running a
program in less time by dividing them.
• This approach seems to be like divide and conquer.
• Examples are NESL (one of the oldest one) and C/C++ also supports because of some library
function.
Declarative programming paradigm:
• It is divided as Logic, Functional, and Database.
• In computer science the declarative programming is a style of building programs that expresses logic
of computation without talking about its control flow.
• It often considers programs as theories of some logic.
• It may simplify writing parallel programs. The focus is on what needs to be done rather how it should
be done basically emphasizing on what code is actually doing.
• It just declares the result we want rather how it has be produced.
• This is the only difference between imperative (how to do) and declarative (what to do) programming
paradigms.
• Getting into deeper we would see logic, functional and database.
, lOMoARcPSD|18872401
Logic programming paradigms
• It can be termed as abstract model of computation.
• It would solve logical problems like puzzles, series etc.
• In logic programming we have a knowledge base which we know before and along with the question
and knowledge base which is given to machine, it produces result.
• In normal programming languages, such concept of knowledge base is not available but while using
the concept of artificial intelligence, machine learning we have some models like Perception model
which is using the same mechanism.
• In logical programming the main emphasize is on knowledge base and the problem.
• The execution of the program is very much like proof of mathematical statement, e.g., Prolog
Functional programming paradigms
• The functional programming paradigms have its roots in mathematics and it is language independent.
• The key principal of this paradigms is the execution of series of mathematical functions.
• The central model for the abstraction is the function which are meant for some specific computation
and not the data structure. Data are loosely coupled to functions.
• The function hide their implementation.
• Function can be replaced with their values without changing the meaning of the program.
• Some of the languages like perl, javascript mostly uses this paradigm.
Database/Data driven programming approach
• This programming methodology is based on data and its movement.
• Program statements are defined by data rather than hard-coding a series of steps.
• A database program is the heart of a business information system and provides file creation, data
entry, update, query and reporting functions.
• There are several programming languages that are developed mostly for database application. For
example SQL.
• It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing
statistics), or calling other programs. So it has its own wide application.
HISTORY OF C LANGUAGE
• All modern computer languages are started through the ALGOL language in 1960.
• After, the COBOL was being used for commercial applications.
• FORTRAN was developed for scientific applications.
• A committee was formed to develop a new language called Combined Programming Language (CPL)
at Cambridge University.
• Basic CPL was derived by BCPL. BCPL was developed by Martin Richards at Cambridge University
by 1967.
• At the same time a language called ‘B’ was developed by Ken Thomson at AT & T’s Bell labs in
1970.
• Then C language is developed by Dennis Ritchie in 1972 with some additional features of BCPL and
B which is very simple.
• ANSI C (American National Standard Institute) has begun to work on a standardized definition of the
‘C’ language that makes it still powerful
, lOMoARcPSD|18872401
Types of Languages
Low Level Language (Or) Machine Language
Binary language (0’s & 1’s). It is understandable by computer machine.
High Level Language
Normal English, Human Understandable Language, Machine Independent, C, C++, etc…
Middle Level Language
C Language is also called as Middle Level Language because ‘C’ stands in between Low Level Language
(nor) High Level Language (i.e) it performs task of low level languages as well as high level language.
Application of C Language
Operating Systems. The first operating system to be developed using a high-level programming language was
UNIX, which was designed in the C programming language.
Embedded Systems
The C programming language is considered an optimum choice when it comes to scripting applications and
drivers of embedded systems, as it is closely related to machine hardware.
GUI
GUI stands for Graphical User Interface. Adobe Photoshop, one of the most popularly used photo editors
since olden times, was created with the help of C. Later on, Adobe Premiere and Illustrator were also created
using C.
New Programming Platforms
Not only has C given birth to C++, a programming language including all the features of C in addition to the
concept of object-oriented programming but, various other programming languages that are extensively used
in today’s world like MATLAB and Mathematica. It facilitates the faster computation of programs.
Google
Google file system and Google chromium browser were developed using C/C++. Not only this, the Google
Open Source community has a large number of projects being handled using C/C+
+.
Mozilla Firefox and Thunderbird
Since Mozilla Firefox and Thunderbird were open-source email client projects, they were written in C/C++.
MySQL
MySQL, again being an open-source project, used in Database Management Systems was written in C/C++.
Compiler Design.
Since the C programming language is relatively faster than Java or Python, as it is compiler- based, it finds
several applications in the gaming sector.
UNIT-II
BASICS OF C PROGRAMMING
Introduction to programming paradigms – Applications of C Language - Structure of C program - C
programming: Data Types - Constants – Enumeration Constants - Keywords – Operators: Precedence
and Associativity - Expressions - Input/Output statements, Assignment statements – Decision making
statements - Switch statement - Looping statements – Preprocessor directives - Compilation process.
INTRODUCTION TO PROGRAMMING PARADIGMS
Paradigm
Paradigm can also be termed as method to solve some problem or do some task.
Programming paradigms are a way to classify programming languages based on their features.
Programming paradigm
Programming paradigm is an approach to solve problem using some programming language.
It is a method to solve a problem using tools and techniques that are available to us following some approach.
There are lots for programming language that are known but all of them need to follow some strategy when
they are implemented and this methodology/strategy is paradigms.
Apart from varieties of programming language there are lots of paradigms to fulfill each and every demand.
Types of programming paradigms
• Imperative paradigm
• Functional paradigm
• Logic paradigm
• Object-oriented paradigm
, lOMoARcPSD|18872401
Imperative programming paradigm:
• It is one of the oldest programming paradigm.
• It features close relation to machine architecture.
• It is based on Von Neumann architecture. It works by changing the program state through assignment
statements.
• It performs step by step task by changing state.
• The main focus is on how to achieve the goal.
• The paradigm consists of several statements and after execution of all the result is stored.
• Language representatives (FORTRAN, ALGOL, Pascal, Basic, C).
Advantage:
• Very simple to implement
• It contains loops, variables etc.
Disadvantage:
• Complex problem cannot be solved
• Less efficient and less productive
• Parallel programming is not possible
Procedural programming paradigm
• This paradigm emphasizes on procedure in terms of under lying machine model.
• There is no difference in between procedural and imperative approach.
• It has the ability to reuse the code and it was boon at that time when it was in use because of its
reusability.
Object oriented programming
• The program is written as a collection of classes and object which are meant for communication.
• The smallest and basic entity is object and all kind of computation is performed on the objects only.
• More emphasis is on data rather procedure.
• It can handle almost all kind of real life problems which are today in scenario.
Advantages:
• Data security
• Inheritance
• Code reusability
• Flexible and abstraction is also present
Parallel processing approach –
• Parallel processing is the processing of program instructions by dividing them among multiple
processors.
• A parallel processing system posses many numbers of processor with the objective of running a
program in less time by dividing them.
• This approach seems to be like divide and conquer.
• Examples are NESL (one of the oldest one) and C/C++ also supports because of some library
function.
Declarative programming paradigm:
• It is divided as Logic, Functional, and Database.
• In computer science the declarative programming is a style of building programs that expresses logic
of computation without talking about its control flow.
• It often considers programs as theories of some logic.
• It may simplify writing parallel programs. The focus is on what needs to be done rather how it should
be done basically emphasizing on what code is actually doing.
• It just declares the result we want rather how it has be produced.
• This is the only difference between imperative (how to do) and declarative (what to do) programming
paradigms.
• Getting into deeper we would see logic, functional and database.
, lOMoARcPSD|18872401
Logic programming paradigms
• It can be termed as abstract model of computation.
• It would solve logical problems like puzzles, series etc.
• In logic programming we have a knowledge base which we know before and along with the question
and knowledge base which is given to machine, it produces result.
• In normal programming languages, such concept of knowledge base is not available but while using
the concept of artificial intelligence, machine learning we have some models like Perception model
which is using the same mechanism.
• In logical programming the main emphasize is on knowledge base and the problem.
• The execution of the program is very much like proof of mathematical statement, e.g., Prolog
Functional programming paradigms
• The functional programming paradigms have its roots in mathematics and it is language independent.
• The key principal of this paradigms is the execution of series of mathematical functions.
• The central model for the abstraction is the function which are meant for some specific computation
and not the data structure. Data are loosely coupled to functions.
• The function hide their implementation.
• Function can be replaced with their values without changing the meaning of the program.
• Some of the languages like perl, javascript mostly uses this paradigm.
Database/Data driven programming approach
• This programming methodology is based on data and its movement.
• Program statements are defined by data rather than hard-coding a series of steps.
• A database program is the heart of a business information system and provides file creation, data
entry, update, query and reporting functions.
• There are several programming languages that are developed mostly for database application. For
example SQL.
• It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing
statistics), or calling other programs. So it has its own wide application.
HISTORY OF C LANGUAGE
• All modern computer languages are started through the ALGOL language in 1960.
• After, the COBOL was being used for commercial applications.
• FORTRAN was developed for scientific applications.
• A committee was formed to develop a new language called Combined Programming Language (CPL)
at Cambridge University.
• Basic CPL was derived by BCPL. BCPL was developed by Martin Richards at Cambridge University
by 1967.
• At the same time a language called ‘B’ was developed by Ken Thomson at AT & T’s Bell labs in
1970.
• Then C language is developed by Dennis Ritchie in 1972 with some additional features of BCPL and
B which is very simple.
• ANSI C (American National Standard Institute) has begun to work on a standardized definition of the
‘C’ language that makes it still powerful
, lOMoARcPSD|18872401
Types of Languages
Low Level Language (Or) Machine Language
Binary language (0’s & 1’s). It is understandable by computer machine.
High Level Language
Normal English, Human Understandable Language, Machine Independent, C, C++, etc…
Middle Level Language
C Language is also called as Middle Level Language because ‘C’ stands in between Low Level Language
(nor) High Level Language (i.e) it performs task of low level languages as well as high level language.
Application of C Language
Operating Systems. The first operating system to be developed using a high-level programming language was
UNIX, which was designed in the C programming language.
Embedded Systems
The C programming language is considered an optimum choice when it comes to scripting applications and
drivers of embedded systems, as it is closely related to machine hardware.
GUI
GUI stands for Graphical User Interface. Adobe Photoshop, one of the most popularly used photo editors
since olden times, was created with the help of C. Later on, Adobe Premiere and Illustrator were also created
using C.
New Programming Platforms
Not only has C given birth to C++, a programming language including all the features of C in addition to the
concept of object-oriented programming but, various other programming languages that are extensively used
in today’s world like MATLAB and Mathematica. It facilitates the faster computation of programs.
Google file system and Google chromium browser were developed using C/C++. Not only this, the Google
Open Source community has a large number of projects being handled using C/C+
+.
Mozilla Firefox and Thunderbird
Since Mozilla Firefox and Thunderbird were open-source email client projects, they were written in C/C++.
MySQL
MySQL, again being an open-source project, used in Database Management Systems was written in C/C++.
Compiler Design.
Since the C programming language is relatively faster than Java or Python, as it is compiler- based, it finds
several applications in the gaming sector.