Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Introduction to C Language-1

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

Introduction to C Language-1

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

Introduction to C

Language
History of C
Origin: Developed 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.

Purpose: Originally designed for system programming, specifically for creating the UNIX
operating system.

Evolution: Derived from the B language, which itself was influenced by BCPL. C has
influenced many later languages, such as C++, Java, and C#.

Significance: C is known for its efficiency and control, making it a popular choice for system
programming, embedded systems, and applications requiring high performance.
What is B and BCPL

B and BCPL are both early programming languages that have historical significance in the
development of modern programming languages.

B:

● B is a programming language developed in the late 1960s by Ken Thompson at Bell


Labs.
● It was primarily designed for system and software development. B is considered a
simplified version of the BCPL (Basic Combined Programming Language) language.
● B was mainly used for the development of operating systems and compilers.
● The most notable use of B was in the early development of Unix. However, B had
limitations, especially in terms of data types, which led to the creation of the C
programming language by Dennis Ritchie as an extension of B.
BCPL (Basic Combined Programming Language)

● BCPL is a programming language created by Martin Richards in 1966.


● It was designed as a simplified and more efficient version of the Combined Programming
Language (CPL).
● BCPL was intended for writing system software, such as compilers and operating
systems, and was known for its portability across different computer architectures.
● Although BCPL itself didn't achieve widespread use, it influenced the development of B
and subsequently C, which became one of the most widely used programming
languages.
Features of C Language
C is the widely used language. It provides many features that are given below.
● Simple
○ C is a simple language in the sense that it provides a structured
approach (to break the problem into parts), a rich set of library
functions, data types, etc.
● Machine-independent or portable
○ Unlike assembly language, Cprograms can be executed on different
machines with some machine specific changes. Therefore, C is a
machine independent language.
● Mid-level programming language
○ Although, C is intended to do low-level programming. It is used to
develop system applications such as kernels drivers etc. It also
● 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.
● Rich Library
○ C provides a lot of inbuilt functions that make the development fast.
● Memory Management
○ It supports the feature of dynamic memory allocation. In the C
language, we can free the allocated memory at any time by calling the
free() function.
● Speed
○ The compilation and execution time of the C language is fast since there
are few inbuilt functions and hence the lesser overhead.
● 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, arrays,etc.
● Recursion
○ In C, we can call the function within the function. It provides code
reuse for every function. Recursion enables us to use the approach of
backtracking.
● Extensible
○ The Clanguage is extensible because it can easily adopt new
features.
Character Set

Definition: The character set in C includes all the characters that can be used in a C program.
This includes letters (uppercase and lowercase), digits, special characters, and control
characters.(\n (newline), \t (tab), etc.)

Examples:
Structure of the C program
The return value can indicate whether the
program ended successfully or encountered an
error:

● 0 or EXIT_SUCCESS: The program ended


successfully.
● EXIT_FAILURE (often 1): The program
encountered an error.
Structure of the C program
Documentation section ( used for comments )
Link section ( header files required for input/output functions)
Global declarations ( global variables )
Function prototype ( it tells the compiler what to expect )
int main () {

// Variable Declarations
// Input/Output Operations
// Logic/Function Calls
return 0; // Return statement
}
User-Defined Function Definitions (if any)
Comments
● A comment is an explanation or description of the source code of the
program.
● It helps a programmer to explain the logic of the code and improves program
readability.
● At run-time, a comment is ignored by the compiler.

There are two types of comments in C:


Single line comment
Represented as // double forward slash
It is used to denote a single line comment only.
Example: // Single line comment

Multi-line comment
Represented as /* any_text */ start with forward slash and asterisk (/*) and end with asterisk and forward slash
(*/).
It is used to denote single as well as multi-line comment.
Example: /* multi line comment line -1
Single line comment
Header File

● Begin with #
● Instruct the compilerto perform some transformation to file before compiling
● Example: #include <stdio.h>
○ add the header file stdio.h to this file
○ .h for header file
○ stdio.h defines useful input/output functions
Header files
Main() Method

● The next part of a C program is to declare the main() function.


● It is the entry point of a C program and the execution typically begins with the first line of
the main().
● The empty brackets indicate that the main doesn’t take any parameter
Body of Main Method

● The body of a function in the C program refers to statements that are a part of
that function.
● It can be anything like manipulations, searching, sorting, printing, etc. A pair
of curly brackets define the body of a function.
● All functions must start and end with curly brackets.
Statement

● Statements are the instructions given to the compiler.


● In C, a statement is always terminated by a semicolon (;).
● In this particular case, we use the printf() function to instruct the compiler to
display “Hello World” text on the screen.
Return Statement

● The last part of any C function is the return statement.


● The return statement refers to the return values from a function.
● This return statement and return value depend upon the return type
of the function.
● The return statement in our program returns the value from main().
● The returned value may be used by an operating system to know the
termination status of your program.
● The value 0 typically means successful termination.
Application of C

● Operating systems: C is widely used for developing operating systems


such as Unix, Linux, and Windows.
● Embedded systems: C is a popular language for developing embedded
systems such as microcontrollers, microprocessors, and other electronic
devices.
● System software: C is used for developing system software such as device
drivers, compilers, and assemblers.
● Networking: C is widely used for developing networking applications such
● Database systems: C is used for developing database systems such as
Oracle, MySQL, and PostgreSQL.
● Gaming: C is often used for developing computer games due to its ability
to handle low-level hardware interactions.
● Artificial Intelligence: C is used for developing artificial intelligence and
machine learning applications such as neural networks and deep learning
algorithms.
● Scientific applications: C is used for developing scientific applications
such as simulation software and numerical analysis tools.
Simulation software

You might also like