Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to C Programming: History, Importance, and Basic Concepts - Prof. Napit, Schemes and Mind Maps of Software Engineering

A comprehensive introduction to the c programming language, covering its history, importance, and fundamental concepts. It explores the evolution of c from its roots in algol to its modern-day influence on other languages. The document highlights the key features of c, including its robustness, efficiency, and versatility, making it suitable for both system and application software development. It delves into the basic structure of c programs, data types, and the fundamental concepts of object-oriented programming (oop).

Typology: Schemes and Mind Maps

2024/2025

Uploaded on 10/11/2024

piyush-napit
piyush-napit 🇮🇳

1 document

1 / 37

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Business Application Programming
Introduction:
C is a general-purpose programming language that is extremely popular, simple
and flexible. It is machine-independent, structured programming language which is used
extensively in various applications.
C was the basic language to write everything from operating systems (Windows and
many others) to complex programs like the Oracle database, Git, Python interpreter and
more.
It is said that 'C' is a god's programming language. One can say, C is a base for the
programming. If you know 'C,' you can easily grasp the knowledge of the other
programming languages that uses the concept of 'C'
It is essential to have a background in computer memory mechanisms because it is an
important aspect when dealing with the C programming language.
History of C language
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download Introduction to C Programming: History, Importance, and Basic Concepts - Prof. Napit and more Schemes and Mind Maps Software Engineering in PDF only on Docsity!

Business Application Programming

Introduction: C is a general-purpose programming language that is extremely popular, simple and flexible. It is machine-independent, structured programming language which is used extensively in various applications. C was the basic language to write everything from operating systems (Windows and many others) to complex programs like the Oracle database, Git, Python interpreter and more. It is said that 'C' is a god's programming language. One can say, C is a base for the programming. If you know 'C,' you can easily grasp the knowledge of the other programming languages that uses the concept of 'C' It is essential to have a background in computer memory mechanisms because it is an important aspect when dealing with the C programming language. History of C language

  1. 1960 - ALGOL - Developed by International Group
  2. 1967 - BCPL - Developed by Martin Richards
  3. 1970 - B - Developed by Ken Thompson
  4. 1972 - C - Developed by Dennis M. Ritchie
  5. 1978 - K&R C - Developed by Brian w. Kernighan and Dennis M. Ritchie
  6. 1989 - ANSI C - Developed by ANSI Committee
  7. 1990 - ANSI/ISO C - Standardaized by ISO

Languages such as C++/Java are developed from 'C'. These languages are widely used in various technologies. Thus, 'C' forms a base for many other languages that are currently in use. The C programming language is developed by Dennis Ritchie at AT&T Bell Laboratories in 1972. It is named C because many features of C were derived from an earlier language called B. The history of C language goes back to 1960’s , when a number of computer languages were being used for various purposes. COBOL (Common Business-Oriented Language) was being used for commercial purposes, FORTRAN (Formula Translation) was being used for scientific and engineering applications and so on. Most of the modern languages including ANSI (American National Standards Institute)/ISO (International Organization for Standardization) C are derived from the algorithmic language called ALGOL which was developed by international group and introduced in 1960’s. Martin Richards in 1967 developed programming language called BCPL (Basic Combined Programming Language) which was derived from ALGOL. Similarly, BCPL influenced development of programming language called B by Ken Thompson in 1970. In 1972, Dennis Ritchie introduced “Traditional C” and it was confined to use within Bell Laboratories until 1978.

Any C program is consists of 6 main sections. Below you will find brief explanation of each of them.

Basic Structure of C Program Documentation Section This section consists of comment lines which include the name of programmer, the author and other details like time and date of writing the program. Documentation section helps anyone to get an overview of the program.

Link Section The link section consists of the header files of the functions that are used in the program. It provides instructions to the compiler to link functions from the system library.

Definition Section

All the symbolic constants are written in definition section. Macros are known as symbolic constants.

Global Declaration Section The global variables that can be used anywhere in the program are declared in global declaration section. This section also declares the user defined functions.

main() Function Section It is necessary have one main() function section in every C program. This section contains two parts, declaration and executable part. The declaration part declares all the variables that are used in executable part. These two parts must be written in between the opening and closing braces. Each statement in the declaration and executable part must end with a semicolon (;). The execution of program starts at opening braces and ends at closing braces.

Subprogram Section The subprogram section contains all the user defined functions that are used to perform a specific task. These user defined functions are called in the main() function.

Variable, Data types, Constants Variable A variable is an identifier which is used to store some value. Constants can never change at the time of execution. Variables can change during the execution of a program and update the value stored inside it. A single variable can be used at multiple locations in a program. A variable name must be meaningful. It should represent the purpose of the variable. Example: Height, age, are the meaningful variables that represent the purpose it is being used for. Height variable can be used to store a height value. Age variable can be used to store the age of a person

  1. Primitive data types
  2. Derived data types
  3. User-defined data types There are five primary fundamental data types,
  4. int for integer data
  5. char for character data
  6. float for floating point numbers
  7. double for double precision floating point numbers
  8. void Array, functions, pointers, structures are derived data types. 'C' language provides more extended versions of the above mentioned primary data types. Each data type differs from one another in size and range. Following table displays the size and range of each data type.

Data type Size in bytes Range

Char or signed char 1 -128 to 127

Unsigned char^1 0 to 255

int or signed int 2 -32768 to 32767

Unsigned int^2 0 to 65535

Short int or Unsigned short int 2 0 to 255

Signed short int 2 -128 to 127

Long int or Signed long int^4 - 2147483648 to 2147483647

Unsigned long int 4 0 to 4294967295

float^4 3.4E-38 to 3.4E+

double 8 1.7E-308 to 1.7E+

Long double 10 3.4E-4932 to 1.1E+

Note : In C, there is no Boolean data type.

Integer data type Integer is nothing but a whole number. The range for an integer data type varies from machine to machine. The standard range for an integer data type is -32768 to 32767. An integer typically is of 2 bytes which means it consumes a total of 16 bits in memory. A single integer value takes 2 bytes of memory. An integer data type is further divided into other data types such as short int, int, and long int. Each data type differs in range even though it belongs to the integer data type family. The size may not change for each data type of integer family. The short int is mostly used for storing small numbers, int is used for storing averagely sized integer values, and long int is used for storing large integer values. Whenever we want to use an integer data type, we have place int before the identifier such as, int age; Here, age is a variable of an integer data type which can be used to store integer values. Floating point data type Like integers, in 'C' program we can also make use of floating point data types. The 'float' keyword is used to represent the floating point data type. It can hold a floating point value which means a number is having a fraction and a decimal part. A floating point value is a real number that contains a decimal point. Integer data type doesn't store the decimal part hence we can use floats to store decimal part of a value. Generally, a float can hold up to 6 precision values. If the float is not sufficient, then we can make use of other data types that can hold large floating point values. The data type double and long double are used to store real numbers with precision up to 14 and 80 bits respectively. While using a floating point number a keyword float/double/long double must be placed before an identifier. The valid examples are, float division; double BankBalance; Character data type Character data types are used to store a single character value enclosed in single quotes.

Constants Constants are the fixed values that never change during the execution of a program. Following are the various types of constants: Integer constants An integer constant is nothing but a value consisting of digits or numbers. These values never change during the execution of a program. Integer constants can be octal, decimal and hexadecimal.

  1. Decimal constant contains digits from 0-9 such as, Example, 111, 1234 Above are the valid decimal constants.
  2. Octal constant contains digits from 0-7, and these types of constants are always preceded by 0. Example, 012, 065 Above are the valid decimal constants.
  3. Hexadecimal constant contains a digit from 0-9 as well as characters from A-F. Hexadecimal constants are always preceded by 0X. Example, 0X2, 0Xbcd Above are the valid hexadecimal constants. The octal and hexadecimal integer constants are very rarely used in programming with 'C'. Character constants A character constant contains only a single character enclosed within a single quote (''). We can also represent character constant by providing ASCII value of it. Example, 'A', '9' Above are the examples of valid character constants. String constants A string constant contains a sequence of characters enclosed within double quotes (""). Example, "Hello", "Programming" These are the examples of valid string constants.

Real Constants Like integer constants that always contains an integer value. 'C' also provides real constants that contain a decimal point or a fraction value. The real constants are also called as floating point constants. The real constant contains a decimal point and a fractional value. Example, 202.15, 300. These are the valid real constants in 'C'. A real constant can also be written as, Mantissa e Exponent For example, to declare a value that does not change like the classic circle constant PI, there are two ways to declare this constant

  1. By using the const keyword in a variable declaration which will reserve a storage memory #include <stdio.h> int main() { const double PI = 3.14; printf("%f", PI); //PI++; // This will generate an error as constants cannot be changed return 0;}
  2. By using the #define pre-processor directive which doesn't use memory for storage and without putting a semicolon character at the end of that statement #include <stdio.h> #define PI 3. int main() { printf("%f", PI); return 0;}

Object-Oriented Programming

OOP stands for Object-Oriented Programming.

It is an entity that is self-contained. It consists of data as well as procedures. Polymorphism It refers to a programming language’s ability to process objects uniquely according to their data type and/or class. Procedure It is a part of a program performing a specific task. Message Passing It is a form of communication that is used in parallel programming and OOP.

Advantages of OOP

Re-usability: “Write once and use it multiple times” you can achieve this by using class.

Redundancy: Inheritance is the good feature for data redundancy. If you need a same functionality in multiple class you can write a common class for the same functionality and inherit that class to sub class.

Easy Maintenance: It is easy to maintain and modify existing code as new objects can be created with small differences to existing ones.

Security: Using data hiding and abstraction only necessary data will be provided thus maintains the security of data.

Disadvantages of OOP

Size: Object Oriented Programs are much larger than other programs.

Effort: Object Oriented Programs require a lot of work to create.

Speed: Object Oriented Programs are slower than other programs, because of their size.

Advantages of OOP

  1. Re-usability
  2. Data Redundancy
  3. Code Maintenance
  4. Security
  5. Design Benefits
  6. Better productivity
  7. Easy troubleshooting
  8. Polymorphism Flexibility
  9. Problems solving

Object-Oriented Programming Paradigm

Object-oriented programming (OOP) is a programming paradigm based upon objects (having both data and methods) that aims to incorporate the advantages of modularity and reusability. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs. The important features of object–oriented programming are −

  • Bottom–up approach in program design
  • Programs organized around objects, grouped in classes
  • Focus on data with methods to operate upon object’s data
  • Interaction between objects through functions
  • Reusability of design through creation of new classes by adding features to existing classes Some examples of object-oriented programming languages are C++, Java, Smalltalk, Delphi, C#, Perl, Python, Ruby, and PHP.
  • User interface design such as windows, menu.
  • Real Time Systems
  • Simulation and Modeling
  • Object oriented databases
  • AI and Expert System
  • Neural Networks and parallel programming
  • Decision support and office automation systems etc.

Benefits of OOP

  • It is easy to model a real system as real objects are represented by programming objects in OOP.
  • The objects are processed by their member data and functions.
  • It is easy to analyze the user requirements.
  • With the help of i nheritance , we can reuse the existing class to derive a new class. This saves time and cost of program.
  • In OOP, data can be made private to a class such that only member functions of the class can access the data.
  • This principle of data hiding helps the programmer to build a secure program.
  • With the help of polymorphism , the same function or same operator can be used for different purposes. This helps to manage software complexity easily.
  • Large problems can be reduced to smaller and more manageable problems.
  • It is easy to partition the work in a project based on objects.
  • It is possible to have multiple instances of an object to co-exist without any interference i.e. each object has its own separate member data and function.

Structure of C++ program

Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program:

Syntax:

**include<iostream.h>

int main() {**

return 0; }

Example:

**include<iostream.h>

//main() is where program execution begins. int main() { cout << "This is my first C++ Program!"; return 0; }**

Output:

Command Prompt

This is my first C++ Program!

  1. The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, #include<iostream.h> header is needed. this header file is included for Standard I/O (input output) function.
  2. The next line //main() is where program execution begins. is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line.
  3. The line int main() is the main function where program execution begins.
  4. The next line cout << "This is my first C++ program!"; causes the message "This is my first C++ program" to be displayed on the screen.
  5. The next line return 0; terminates main() function and causes it to return the value 0 to the calling process.

PPT CONSTRUCTOR and DESTRUCTOR