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

C Programming Language (1) (1)

C is a general-purpose programming language developed by Dennis Ritchie in the early 1970s, primarily associated with UNIX. It is known for its efficiency, portability, and structured programming capabilities, making it a foundational language in computer science. The document also outlines the history, features, and benefits of learning C, along with a basic structure of a C program.

Uploaded by

catindigalyn21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C Programming Language (1) (1)

C is a general-purpose programming language developed by Dennis Ritchie in the early 1970s, primarily associated with UNIX. It is known for its efficiency, portability, and structured programming capabilities, making it a foundational language in computer science. The document also outlines the history, features, and benefits of learning C, along with a basic structure of a C program.

Uploaded by

catindigalyn21
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

C

Programming
Language
What is C Programming Language?

✓ C is a general-purpose programming language created by Dennis


Ritchie at the Bell Laboratories in 1972.
✓ It is a very popular language, despite being old. The main reason for
its popularity is because it is a fundamental language in the field of
computer science.
✓ C is strongly associated with UNIX, as it was developed to write the
UNIX operating system.
Brief History of C

Brief History of C The C programming language was developed in


the Bell Labs of AT&T by an employee called Dennis Ritchie between
1969 and 1973 while working on Unix operating system. He created this
language using ALGOL, BCPL, and B the languages that were used
before C was created. He added many powerful features to C and used it
to further develop the UNIX operating system. American National
Standards Institute (ANSI) in 1983, formed a committee to provide a
comprehensive definition to the C language and thus came into
existence the new ANSI C language with better features.
The root of all modern
languages is ALGOL (Algorithmic
Language). ALGOL was the first
computer programming language
to use a block structure, and it was
introduced in 1960. In 1967,
Martin Richards developed a
language called BCPL (Basic
Combined Programming
Language). BCPL was derived from
ALGOL.
In 1970, Ken Thompson
created a language using BCPL
called B. Both BCPL and B
programming languages were type
less. After that, C was developed
using BCPL and B by Dennis Ritchie
at the Bell lab in 1972. So, in terms
of history of C language, it was used
in mainly academic environments,
but at long last with the release of
many C compilers for commercial
use and the increasing popularity of
UNIX, it began to gain extensive
support among professionals.
Popular Compilers of C

➢Turbo C
➢Tiny C Compiler
➢GCC
➢Clang
➢Portable C Compiler
Structure of a Basic C Program

Link
❖ This section includes all header files. A header file is a file that
contains C declarations that can be shared among many files. We
can use other people’s codes in our files due to it. Before
compilation, a copy of these header files is inserted into your code.
#include
Documentation
❖ In a C program, single-line comments can be written using two
forward slashes i.e., //, and we can create multi-line
comments using / /. Here, we’ve used multi-line comments.
Definition
❖Any statement in C that starts with the symbol "#" is referred to
be a preprocessor directive. Constants are made using the
#define preprocessor compiler command. The usage of
constants in our code is fundamentally made possible by
#define, which enables the macro declaration. #define BORN
2000
Global Declaration
❖ All global variables, function declarations, and static variables
are contained in this section. Anywhere in the program can
utilize the variables specified in this section. They get access to
all of the program’s features. Consequently, they are known as
global variables
Main() Function
❖ This section of a C program’s structure comprises the code’s
primary purpose. The main() function is when the compiler
begins running code. It may make use of user-defined
functions as well as built-in and global variables. The main()
function’s return type is not required to be an int and can
alternatively be void.
Subprograms
❖ This also applies to the user-defined programs that the main()
function calls. Regardless of their sequence, user-defined functions
are typically written after the main() function. The program’s control
switches to the user-defined function when it is called from the
main() function, and it returns to the main() function when it meets a
return statement. In this instance, we’ve developed the age()
function, which only accepts the current year as an input.
Formation of C
#include This is the main header file preprocessor function, which
preprocesses standard input and output header files from the C library
repository, such as <stdio.h>,before compiling the program.
int main() This C statement, like most programming languages, is
the main function, which is the point where the program execution
begins. Once the primary main () has been executed, all other methods
and functions are performed.
{ Curly braces are a type of bracket that can be seen in any
computer language, not just C. This represents the start of a method or
function definition.
✓ /* explanation of C code */ The text inside the /* and */ tags will be
considered as comments and will not be executed or compile.
✓ Printf The output is printed to the console screen using this C
command.
✓ Scanf The user data is taken from the usual console terminal window
using this C function.
✓ Getch() This function is being used to wait for the user's input.
✓ return 0 This C function returns 0 after terminating the C program or
main function.
✓ } The function or method block is closed with these curly braces.
✓ // These are called single line comments, and they are utilized not only
in the C programming language but in others as well.
Data Types in C

Each variable in C has an associated data type. It specifies the


type of data that the variable can store like integer, character,
floating, double, etc. Each data type requires different amounts of
memory and has some specific operations which can be performed
over it. The data type is a collection of data with values having fixed
values, meaning as well as its characteristics.
Arithmetic
Operators
Arithmetic operators are used to perform
common mathematical operations.
Why learn C?
✓ It is one of the most popular programming languages in the world
✓ If you know C, you will have no problem learning other popular
programming languages such as Java, Python, C++, C#, etc, as the
syntax is similar
✓ C is very fast, compared to other programming languages,
like Java and Python
✓ C is very versatile; it can be used in both applications and
technologies
Benefits of Learning C
✓ C is a powerful programming language that offers several benefits over other
languages.
✓ C is a universal language that can be used for various applications.
✓ C is a very efficient language that can write code that is both fast and reliable.
✓ C is a portable language, meaning that code written in C can be easily compiled
and run on various platforms.
✓ C is a well-established language with a large and active community of
developers constantly working on improving and creating new tools and
libraries.
Features of C Language
➢Simple
C is a simple language in the sense that it provides a structured
approach (to break the problem into parts), the rich set of library
functions, data

➢Machine Independent or Portable


Unlike assembly language, c programs can be executed on different
machines with some machine specific changes. Therefore, C is a machine
independent language.
Features of C Language

➢Mid-level programming language


Although, C is intended to do low-level programming. It is used to
develop system applications such as kernel, driver, etc. It also supports the
features of a high-level language. That is why it is known as mid-level
language.
➢ 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.
Features of C Language

➢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 C language,
we can free the allocated memory at any time by calling the free() function.
Features of C Language

➢Speed
The compilation and execution time of C language is fast since there
are lesser inbuilt functions and hence the lesser overhead.

➢Pointer
provides the feature of pointers. We can directly interact with the
memory by using the pointers. We can use pointers for memory, structures,
functions, array, etc..
Features of C Language

➢Recursion
In C, we can call the function within the function. It provides code
reusability for every function. Recursion enables us to use the approach of
backtracking.

➢Extensible
C language is extensible because it can easily adopt new features.
#include <stdio.h>

int main() {

int num1, num2, sum;

// Prompt the user to enter the first number

TRY TO RUN THIS printf("Enter the first number: ");


scanf("%d", &num1);
SAMPLE PROGRAM
// Prompt the user to enter the second number

printf("Enter the second number: ");


scanf("%d", &num2);

// Calculate the sum


sum = num1 + num2;

// Print the result


printf("The sum of %d and %d is %d\n", num1, num2, sum);

return 0; }
Thank you

You might also like