C PROGRAMMING 2020 Lesson 1 and 2
C PROGRAMMING 2020 Lesson 1 and 2
1- History of C language
C language has evolved from three different structured language ALGOL, BCPL and B
Language. It uses many concepts from these languages while introduced many new concepts
such as datatypes, struct, pointer etc. In 1988, the language was formalised by American
National Standard Institute (ANSI). Between 1989 and 1990, a version of C language was
approved by the International Standard Organisation (ISO) and that version of C is also
referred to as C89.
Let's see the programming languages that were developed before C language.
The current latest version of C language is C11, which was introduced in 2011. It is supported
by all the standard C language compilers.
Many new features have been introduced in this version and an overall attempt to improve
compatibility of the C language with C++ language has been made.
The idea behind creating C language was to create an easy language which requires a
simple compiler and enables programmers to efficiently interact with the machine/system, just
like machine instructions.
C language compiler converts the readable C language program into machine instruction.
Programs written in C language takes very less time to execute and almost executes at the
speed of assembly language instructions.
Initially C language was mainly used for writing system level programs, like designing
operating systems, but there are other applications as well which can be very well designed
and developed using C language, like Text Editors, Compilers, Network Drivers etc.
The C programming language is used for developing system applications that forms a major
portion of
operating systems such as Windows, UNIX and Linux. Below are some examples of C being
used.
Database systems
Graphics packages
Word processors
Spreadsheets
Operating system development
Compilers and Assemblers
Network drivers
Interpreters
Note: C is called middle-level language because it actually binds the gap between a
machine level language and high-level languages.
Topics as well, which are to be known by any C programmer before writing a C program.
printf(“Hello_World!
printf command prints the output onto the screen.
“);
Below C program is a very simple and basic program in C programming language. This C
program displays
“Hello World!” in the output window. And, all syntax and commands in C programming are
case sensitive.
Also, each statement should be ended with semicolon (;) which is a statement terminator.
#include <stdio.h>
int main(){
/* Our first simple C basic program */
printf("Hello World I doing c programming! ");
getch();
return 0;
}
OUTPUT:
Hello World I doing c programming!
Or you install an IDE(Integrated Development Environment) embedding both text editor and
compiler (codeblock, Turbo C, ….etc.
(a)Text Editor
This will be used to type your program. Examples of a few editors include Windows Notepad,
OS Edit command, Brief, Epsilon, EMACS, and vim or vi …..etc. The name and version of
text editors can vary on different operating systems. For example, Notepad will be used on
Windows, and vim or vi can be used on Windows as well as on Linux or UNIX. The files you
create with your editor are called the source files and they contain the program source codes.
The source files for C programs are typically named with the extension ".c".
Before starting your programming, make sure you have one text editor in place and you have
enough experience to write a computer program, save it in a file, compile it and finally
execute it.
(b)The C Compiler
The source code written in source file is the human readable source for your program. It needs
to be "compiled" into machine language so that your CPU can actually execute the program as
per the instructions given.
The compiler compiles the source codes into final executable programs. The most frequently
used and free available compiler is the GNU C/C++ compiler, otherwise you can have
compilers either from HP or Solaris if you have the respective operating systems.
The following section explains how to install GNU C/C++ compiler on WINDOWS
especially since it is the system that we are using. We keep mentioning C/C++ together
because GNU gcc(GNU Compiler Collection) works for both C and C++ programming
languages
1. Documentation section
2. Link Section
3. Definition Section
4. Global declaration section
5. Function prototype declaration section
6. Main function
7. User defined function definition section
EXAMPLE C PROGRAM TO COMPARE ALL THE SECTIONS:
You can compare all the sections of a C program with the below C program.
DESCRIPTION FOR EACH SECTION OF THE C PROGRAM:
Let us see about each section of a C basic program in detail below.
Please note that a C program mayn’t have all below mentioned sections except main
function and link sections.
Also, a C program structure mayn’t be in below mentioned order.
Sections Description
Function
Function prototype gives many information about a
prototype
function like return type, parameter names used
declaration
inside the function.
section