0% found this document useful (0 votes)
2 views

UNIT I

C language Notes pdf

Uploaded by

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

UNIT I

C language Notes pdf

Uploaded by

sakshipawar5668
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT I

C Language Introduction
C is a procedural programming language initially developed by Dennis Ritchie in the
year 1972 at Bell Laboratories of AT&T Labs. It was mainly developed as a system
programming language to write the UNIX operating system.

Advantages of C Language

1. Simple: C is a simple language as it offers a structured approach to solve problems. It


also has a rich set of library functions and data types. C is usually taught as an
introductory programming language as it is a well-established fact that it becomes
easier to learn any other programming language if a person already knows the C
language.
2. Portable: C programs can be written on one platform and can be executed in the
same way on another operating system. C is a machine-independent language.
3. Structured programming language: C provides different functions that enable us to
break the code into small parts, that is why C programs are easy to understand and
modify. Functions also offer code reusability.
4. Fast and Efficient: Other programming languages, such as Python and Java offer
more features than C language but their performance rate gets down due to additional
processing. C programming language provides programmers access to direct
manipulation with the computer hardware. The compilation and execution time of the
C language is also fast.
5. Extensible: C programming can easily adopt new features.
6. Helps understand the fundamentals of Computer Theories: Many computer
theories like operating systems, computer networks, compiler designing, and
computer architecture are based on the C programming language and need a good
knowledge of C programming to work on them.

These features make the C language suitable for system programming like an operating
system or compiler development.
History of C Language

History of C language is interesting to know. Here we are going to discuss a brief history of
the c language.
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.

Let's see the programming languages that were developed before C language.

Language Year Developed By

Algol 1960 International Group

BCPL 1967 Martin Richard

B 1970 Ken Thompson

Traditional C 1972 Dennis Ritchie

K&RC 1978 Kernighan & Dennis Ritchie

ANSI C 1989 ANSI Committee

ANSI/ISO C 1990 ISO Committee

Procedural Programming

Procedural Programming can be defined as a programming model which is derived from


structured programming, based upon the concept of calling procedure. Procedures, also
known as routines, subroutines or functions, simply consist of a series of computational
steps to be carried out. During a program’s execution, any given procedure might be called
at any point, including by other procedures or itself.
Languages used in Procedural Programming:
FORTRAN, ALGOL, COBOL,
BASIC, Pascal and C.

Object-Oriented Programming

Object-oriented programming can be defined as a programming model which is based upon


the concept of objects. Objects contain data in the form of attributes and code in the form of
methods. In object-oriented programming, computer programs are designed using the
concept of objects that interact with the real world. Object-oriented programming languages
are various but the most popular ones are class-based, meaning that objects are instances of
classes, which also determine their types.
Languages used in Object-Oriented Programming:
Java, C++, C#, Python,
PHP, JavaScript, Ruby, Perl,
Objective-C, Dart, Swift, Scala.

Procedural Oriented Programming Object-Oriented Programming

In object-oriented programming, the


In procedural programming, the program is
program is divided into small parts
divided into small parts called functions.
called objects.

Procedural programming follows a top-down Object-oriented programming follows


approach. a bottom-up approach.

Object-oriented programming has access


There is no access specifier in procedural
specifiers like private, public, protected,
programming.
etc.

Adding new data and functions is not easy. Adding new data and function is easy.

Procedural programming does not have any


Object-oriented programming provides
proper way of hiding data so it is less
data hiding so it is more secure.
secure.

In procedural programming, overloading is Overloading is possible in object-oriented


not possible. programming.

In object-oriented programming, the


In procedural programming, there is no
concept of data hiding and inheritance is
concept of data hiding and inheritance.
used.

Structure of a C program

The structure of a C program means the specific structure to start the programming in the C
language. Without a proper structure, it becomes difficult to analyze the problem and the
solution. It also gives us a reference to write more complex programs.

Let's first discuss about C programming.


Sections of a C program

The sections of a C program are listed below:

1. Documentation section
2. Preprocessor section
3. Definition section
4. Global declaration
5. Main function
6. User defined functions

1. Documentation

This section consists of the description of the program, the name of the program, and the
creation date and time of the program. It is specified at the start of the program in the form
of comments. Documentation can be represented as:
// description, name of the program, programmer name, date, time etc.
Anything written as comments will be treated as documentation of the program and this
will not interfere with the given code. Basically, it gives an overview to the reader of the
program.
2. Preprocessor Section

All the header files of the program will be declared in the preprocessor section of the
program. Header files help us to access other’s improved code into our code. A copy of
these multiple files is inserted into our program before the process of compilation.

Example:
#include<stdio.h>
#include<math.h>

3. Definition

Preprocessors are the programs that process our source code before the process of
compilation. There are multiple steps which are involved in the writing and execution of the
program. Preprocessor directives start with the ‘#’ symbol. The #define preprocessor is
used to create a constant throughout the program. Whenever this name is encountered by
the compiler, it is replaced by the actual piece of defined code.
Example:
#define long long ll

4. Global Declaration

The global declaration section contains global variables, function declaration, and static
variables. Variables and functions which are declared in this scope can be used anywhere in
the program.
Example:
int num = 18;

5. Main() Function

Every C program must have a main function. The main() function of the program is written
in this section. Operations like declaration and execution are performed inside the curly
braces of the main program. The return type of the main() function can be int as well as
void too. void() main tells the compiler that the program will not return any value. The int
main() tells the compiler that the program will return an integer value.
Example:
void main()
or
int main()
6. Sub Programs

User-defined functions are called in this section of the program. The control of the program
is shifted to the called function whenever they are called from the main or outside the
main() function. These are specified as per the requirements of the programmer.

Example:
int sum(int x, int y)
{
return x+y;
}
What is Top-Down Approach?
Top-Down Approach is an approach to design algorithms in which a bigger problem is
broken down into smaller parts. Thus, it uses the decomposition approach. This approach is
generally used by structured programming languages such as C, COBOL, FORTRAN.

The drawback of using the top-down approach is that it may have redundancy since every
part of the code is developed separately. Also, there is less interaction and communication
between the modules in this approach.

The implementation of algorithm using top-down approach depends on the programming


language and platform. Top-down approach is generally used with documentation of module
and debugging code.

What is Bottom-Up Approach?


Bottom-Up Approach is one in which the smaller problems are solved, and then these
solved problems are integrated to find the solution to a bigger problem. Therefore, it uses
composition approach.
It requires a significant amount of communication among different modules. It is generally
used with object oriented programming paradigm such as C++, Java, and Python. Data
encapsulation and data hiding is also implemented in this approach. The bottom-up approach
is generally used in testing modules.
Structured Programming

1. Definition: Structured programming is a programming paradigm that emphasizes a


logical structure in the program's flow. It promotes the use of control structures
such as sequences, selections (if-else), and iterations (loops) to manage the flow of
control.
2. Key Features:
- Control Flow: Uses structured control flow constructs rather than arbitrary jumps
(like GOTO statements).
- Top-Down Design: Encourages breaking down a program into smaller,
manageable functions or procedures.
- Single Entry and Exit: Each function has a single entry point and a single exit
point, making it easier to understand and debug.
3. Advantages:
- Improved readability and maintainability.
- Easier debugging due to the structured flow.
- Facilitates the use of clear and logical program design.
Modular Programming

1. Definition: Modular programming is a design technique that separates a program


into distinct modules or components, each encapsulating a specific functionality or
set of related functions.
2. Key Features:
- Encapsulation: Each module operates independently and can be developed,
tested, and debugged separately.
- Reusability: Modules can be reused across different programs.
- Interfacing: Modules communicate through well-defined interfaces, which helps
in maintaining separation of concerns.
3. Advantages:
- Enhances code organization and clarity.
- Facilitates collaboration, as multiple programmers can work on different modules
simultaneously.
- Makes it easier to update and maintain code since changes in one module
typically do not affect others.
What is Programming Logic?

Programming logic, at its core, involves the development of systematic procedures that solve
specific problems. Like a skilled chef following a tried-and-true recipe, a programmer applies
logic to their logic code to achieve the desired result. Logical programming isn’t about the
syntax of a particular programming language. Rather, it’s about the approach to solving a
problem and how developers use their chosen logic language programming tool to achieve
this.
Just as an architect relies on their blueprint, so does a software developer rely on
programming logic. Without it, even the most potent and feature-rich programming
languages are just a collection of keywords and symbols devoid of meaningful action.
Programming logic gives purpose and direction to these elements, allowing developers to
create software that is both functional and efficient.
The Essence of Coding Logic

At the heart of programming logic is the idea of coding logic, a principle that transcends the
barrier of programming languages. Whether you’re coding in Java, Python, or C++, the
essence of coding logic remains the same. It encompasses:

 Sequence: The order in which instructions are executed.

 Selection: Decision-making with if-else statements, switch-case statements, etc.

 Loop: Repeating certain actions using for, while, and do-while loops.
 Function: Group of reusable code which can be called anywhere in the program.
These concepts form the cornerstone of any programming logic and act as the building blocks
for creating software applications.

 Recursion:

 Performing the same operations multiple times with different inputs.


 In every step, we try smaller inputs to make the problem smaller.
 Base condition is needed to stop the recursion otherwise infinite loop will occur.
Coupling refers to the interdependencies between modules, while cohesion describes how
related the functions within a single module are. Low cohesion implies that a given module
performs tasks which are not very related to each other and hence can create problems as the
module becomes large.
What is Testing?

Testing is the process of verifying and validating that a software or application is bug-free,
meets the technical requirements as guided by its design and development, and meets the user
requirements effectively and efficiently by handling all the exceptional and boundary cases.
The purpose of software testing is to identify the errors, faults, or missing requirements in
contrast to actual requirements.

Static Testing Tools: Analyze code without execution, requiring no input or output data.

Flow Analyzers: Manage data flow from input to output.

Path Tests: Identify unused or inconsistent code.

Coverage Analyzers: Ensure all logical paths are tested.

Interface Analyzers: Examine the impact of variables and data passing between modules.

What is Debugging?

Debugging is the process of fixing a bug in the software. It can be defined as identifying,
analyzing, and removing errors. This activity begins after the software fails to execute
properly and concludes by solving the problem and successfully testing the software. It is
considered to be an extremely complex and tedious task because errors need to be resolved at
all stages of debugging.

Debuggers are distinct tools that give developers the ability to watch and control how their
program is being run. A debugger lets you set a breakpoint in your code, normally by
highlighting a line of code, then when the application runs in debug mode the debugger can
intercept the program and halt execution.

Some common interactive debuggers include:

GDB (GNU Debugger)

LLDB (Low-Level Debugger)


WinDbg (Windows Debugger)

Visual Studio Debugger

IntelliJ IDEA Debugger

PyCharm Debugger

What is programming?

Programming refers to a technological process for telling a computer which tasks to perform in
order to solve problems. You can think of programming as a collaboration between humans and
computers, in which humans create instructions for a computer to follow (code) in a language
computers can understand.

Programming tools, often referred to as tools in the software industry, are sets of software
applications used to write, test, debug and maintain source code. They provide foundations for
compiling, interpreting and editing code in various programming languages.

Exploring Different Types of Programming Tools

When coding, you wouldn't be limited to only one type of programming tool. Various tools
are available, each designed to assist a different part of your coding journey.

IDE (Integrated Development Environment)

Code Editor

Library

API (Application Programming Interface)

Database Management System

You might also like