UNIT I
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
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.
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.
Procedural Programming
Object-Oriented Programming
Adding new data and functions is not easy. Adding new data and function is easy.
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.
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.
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:
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:
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.
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.
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.
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.
Code Editor
Library