Name:
Roll No: BEET,2nd
Lab 1
Introduction Basic C Language and Turbo C Compiler
Objective
In this Lab Student are able to know about basic of c language and Turbo C++ Compiler.
Theory
What is Computer Program
A computer program is a set of instructions for a computer to perform a specific task. Programs generally
fall into these categories applications, utilities or services. Program are written in programming language
then translated into machine code by a compiler and linker so that the computer can execute it directly or
run it line by line (interpreted) by an interpreter program.
What is Programing Language
A programing language is used to write computer programs such as Application, Utilities, Servers and
System programs. A program is written as a series of human understandable computer instruction that
can be read by a compiler and linker, and translated into machine code so that a computer can
understand and run it.
Low Level Language
A low-level language is a programming language that provides little or no abstraction of programming
concepts, and is very close to writing actual machine instruction. Two good example of low-level
language are assembly and machine code.
High Level Language
A HLL is a computer programming language that isn’t limited by computer, designed for a specific job,
and is easier to understand. It is more like human language and less is easier to understand. However,
for a computer to understand and run a program created with high-level language, it must be compiled
into machine language. The first high-level language were introduced in the 1950’s. Today, there are
many high-level language in use, including BASIC, C, C++, Cobol etc..
C Language - Overview
C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop
the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer
in 1972.
In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now
known as the K&R standard.
The UNIX operating system, the C compiler, and essentially all UNIX application programs have been
written in C. C has now become a widely used professional language for various reasons −
Easy to learn
Structured language
Name:
Roll No: BEET,2nd
It produces efficient programs
It can handle low-level activities
It can be compiled on a variety of computer platforms
Facts about C
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around the early 1970s.
The language was formalized in 1988 by the American National Standard Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System Programming Language.
Most of the state-of-the-art software have been implemented using C.
Today's most popular Linux OS and RDBMS MySQL have been written in C.
Why use C?
C was initially used for system development work, particularly the programs that make-up the operating
system. C was adopted as a system development language because it produces code that runs nearly as
fast as the code written in assembly language. Some examples of the use of C might be −
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
C Programs
A C program can vary from 3 lines to millions of lines and it should be written into one or more text files
with extension ".c"; for example, hello.c. You can use text editor to write your C program into a file.
Integrated development environment (IDE)
The IDE is also known as integrated design environment or integrated debugging environment, is a
software application that provides comprehensive facilities to computer programmers for software
development. An IDE normally consists of
GUI builder/ a source code editor
a compiler and/or an interpreter
build automation tools
a debugger
Turboo C++, Dreamweaver are examples of IDEs
Name:
Roll No: BEET,2nd
Steps involved in writing and executing a program
C Compiler
It translates the C source code into object code. It take some time to analyze and process a program, the
resulting executable is some form of machine- specific binary code. The computer hardware interprets
(executes) the resulting code, hence the program execution is fast.
Creating a program
Use a editor to write the source code. This file contains a source code which consists of executable code.
Save the file with .c extension only.
Preprocessing: Using a Preprocessor program to convert C source code in expanded source code.
"#includes" and "#defines" statements will be processed and replaced actually source codes
Compiling the program
The next step is to compile the program. The code is compiled by using compiler. i.e. object code. The
compiler program convert C expanded source to assembly source code.
Assembly
Using a Assembler program to convert assembly source code to object code.
Linking a program to library
The object code of a program is linked with libraries that are needed for execution of a program. The
linker is used to link the program with libraries. It creates a file with .exe extension. Multiple units of
object codes are linked together.
Name:
Roll No: BEET,2nd
Execution of program
The final executable file is then run by the command.
--Loading: Using a Loader program to load the executable code into CPU for execution.
C standard library
A C library is a file containing several object files that can be used as a single entity in a linking phase of a
program. Normally the library is indexed, so it is easy to find symbols (functions, variables and so on) in
them. For this reason, linking a program whose object files are ordered in libraries is faster than linking a
program whose object files are separate on the disk.
The C standard library consists of a set of sections of the ISO C standard which describe a collection of
headers and library routines used to implement common operations, such as input/output and string
handling.
#include <stdio.h>
#include <conio.h>
C - Program Structure
Before we study the basic building blocks of the C programming language, let us look at a bare minimum
C program structure so that we can take it as a reference in the upcoming chapters.
pre-processor directives
global declarations
main()
{
local variable deceleration
statement sequences
function invoking
}
Hello World Example
A C program basically consists of the following parts −
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
Let us look at a simple code that would print the words "Hello World" −
#include<stdio.h>
void main(){
printf("Hello World");
}
Let us take a look at the various parts of the above program −
Name:
Roll No: BEET,2nd
The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to
include stdio.h file before going to actual compilation.
The next line void main() is the main function where the program execution begins.
The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the
program. So such lines are called comments in the program.
The next line printf(...) is another function available in C which causes the message "Hello, World!" to be
displayed on the screen.
Compile and Execute C Program
Let us see how to save the source code in a file, and how to compile and run it. Following are the simple
steps −
Write program in Turboo C++ or Code block
After that in Turboo C++ click on F2 to save
To compile Alt+F9
To run Ctrl+F9 or in code block press F9 only.
C Preprocessor directives
A Preprocessor is a program that processes the code before it passes through the compiler. The preprocessor
directives are placed in the source program before the main line before the source code passes through the compiler
it is examined by the preprocessor for any preprocessor directives. The preprocessor is executed before the actual
compilation of code begins. Preprocessor directives follow the special syntax rules and begin with the symbol # and
do not require any semicolon at the end.
For example:
#include Specifies a file to be included
#define Defines a macro substitution
Name:
Roll No: BEET,2nd
Header Files
Header file contains C function declarations, variable, subroutines and other identifiers. which can be
incorporated into any C program by using the pre-processor #include statement. It have a .h extension.
Header files contain definitions of functions and variables. There are two types of header files: the files that
the programmer writes and the files that come with C compiler. It also contains function prototypes
(declarations) and structure definitions from the standard C stream library.
For example:
#include<stdio.h>
#include<conio.h>
#include<graphic.h>
#include<string.h>
Program example:
#include <stdio.h> #include <stdio.h>
#include <conio.h> #include <conio.h>
main( ) main( )
{ {
printf ("Welcome to NFC IET"); Clrscr( );
getch( ); printf ("Welcome to\n");
} printf ("my class");
getch( );
}
Comments/Conclusion: