You are on page 1of 29

What is computer language?

• A language is the main medium of communicating between


the Computer systems and the most common are
the programming languages.
• A Computer only understands binary numbers that is 0 and 1
to perform various operations but the languages are developed
for different types of work on a Computer.
What is a Programming language?
• A programming language is a set of commands, instructions,
and other syntax use to create a software program.

OR
• A programming language is a vocabulary and set of
grammatical rules for instructing a computer or computing
device to perform specific tasks.
Overview of C Language
• C is a structured programming language developed by
Dennis Ritchie in 1973 at Bell Laboratories.
• It is one of the most popular computer languages today
because of its structure, high-level abstraction, machine
independent feature etc. C language was developed to write
the UNIX operating system.
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).
• In 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.
Why C Language is so popular?

• C language is a very good language to introduce yourself to


the programming world,
• it is a simple procedural language which is capable of doing
wonders.
What is procedural language?
• A procedural language is a type of computer programming
language that specifies a series of well-structured steps and
procedures within its programming context to compose a
program. It contains a systematic order of statements,
functions and commands to complete a computational task or
program.
Latest Version of C
• The current latest version of C language is C11, which was
introduced in 2011.
Features of C language
• It is a robust language with rich set of built-in functions and
operators that can be used to write any complex program.
• Programs Written in C are efficient and fast.
• C is highly portable this means that programs once written can
be run on another machines with little or no modification.
• C language is the most widely used language in operating
systems and embedded system development today.
Functions of C language
Low level Programming 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 instructions.
• Low-level languages are designed to operate and handle the
entire hardware and instructions set architecture of a computer
directly
• Programs and applications written in a low-level language are
directly executable on the computing hardware without any
interpretation or translation.
• Two good examples of low-level languages are assembly
and machine code.
High level programming language
• A high-level language is any programming language that
enables development of a program in a much more user-
friendly programming context and is generally independent of
the computer's hardware architecture.
• A high-level language has a higher level of abstraction from the
computer, and focuses more on the programming logic rather
than the underlying hardware components such as memory
addressing and register utilization.
• High-level languages are designed to be used by the human
operator or the programmer.
• Examples : BASIC, FORTRAN, Java, C++ and Pascal.
Assembly language
• An assembly language is a low-level programming
language designed for a specific type of processor.
• It may be produced by compiling source code from a high-
level programming language (such as C/C++). Assembly
code can be converted to machine code using an assembler.
Language processors
• Assembler
• Compiler
• Interpreter
Assembler
• An assembler is a program that converts assembly language into
machine code.
• It takes the basic commands and operations from assembly code
and converts them into binary code that can be recognized by a
specific type of processor.
• The Assembler is used to translate the program written in
Assembly language into machine code. The source program is a
input of assembler that contains assembly language instructions.
The output generated by assembler is the object code or machine
code understandable by the computer.
Compiler
• The language processor that reads the complete source program
written in high level language as a whole in one go and translates
it into an equivalent program in machine language is called as a
Compiler.
• Example: C, C++, C#, Java
• In a compiler, the source code is translated to object code
successfully if it is free of errors. The compiler specifies the
errors at the end of compilation with line numbers when there are
any errors in the source code. The errors must be removed before
the compiler can successfully recompile the source code again.
Interpreter
• The translation of single statement of source program into
machine code is done by language processor and executes it
immediately before moving on to the next line is called an
interpreter.
• If there is an error in the statement, the interpreter terminates its
translating process at that statement and displays an error
message.
• The interpreter moves on to the next line for execution only after
removal of the error.
• An Interpreter directly executes instructions written in a
programming or scripting language without previously
converting them to an object code or machine code.
Example: Perl, Python and Matlab.
Difference between compiler and
interpreter
A compiler is a program which coverts the
interpreter takes a source program and
entire source code of a programming
runs it line by line, translating each line as
language into executable machine code
it comes to it.
for a CPU.

Compiler takes large amount of time to


Interpreter takes less amount of time to
analyze the entire source code but the
analyze the source code but the overall
overall execution time of the program is
execution time of the program is slower.
comparatively faster.

Compiler generates the error message


only after scanning the whole program, so Its Debugging is easier as it continues
debugging is comparatively hard as the translating the program until the error is
error can be present any where in the met
program.

Generates intermediate object code. No intermediate object code is generated.

Examples: C, C++, Java Examples: Python, Perl


Basic structure of a C program
• Documentations (Documentation Section)
• Preprocessor Statements (Link Section)
• Global Declarations (Definition Section)
• The main() function
– Local Declarations
– Program Statements & Expressions
• User Defined Functions
Explanation of each part
• Documentation section is used for giving the comments
regarding the title, author, more detailed information about the
program etc.
• Eg:
Single line comments
//sum of two numbers
• Link section is used to link the compiler to the library function
using header files.
Eg: #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
Conti….
• Definition section consists of symbolic constants.
Eg. #define true 1
• The variables used anywhere in the program are called as
global variables. In this section, global variables are declared
which can be also used in user-defined functions.
Eg. int x=10;
• Main function section is the main part of the program.
It mainly consists of two parts which are written between the
braces {} and every line have to end with a semicolon(;).
• Declaration Section: In declaration section, all the required
variables are declared which can be used in the executable
part.
• Executable Section: In executable
section, statements are given which are
helpful in executing the program and giving
the output.
Conti..
• Main function section is the main part of the program.
It mainly consists of two parts which are written between the
braces {} and every line have to end with a semicolon(;).
• Declaration Section: In declaration section, all the required
variables are declared which can be used in the executable
part.
• Executable Section: In executable section, statements are
given which are helpful in executing the program and giving
the output.
{
Function 1
Function 2
.
.
}
Conti…
• Sub-programming section consists of user-defined
functions.These functions are called by the main function
section.
/*C basic structure example
to find sum of two numbers */ //documentation section

#include<stdio.h> //Link section

int total; //Global declaration section


int sum(int,int); //Function declaration section
void main() //Main section
{
int a,b;
printf("\n Enter the two numbers : ");
scanf("%d %d",&a,&b); /* taking two numbers as input*/
total = sum(a,b); /* calling function. The value returned by the function is stored in total */
printf("\n The sum of two numbers is : %d ",total);
getch();
}

int sum ( int num1,int num2) //User defined section


{
int result; /* defining variable, its scope lies within function */
result = num1 + num2 ; /*adding two numbers*/
return (result) ; //definition section
}
Preprocessor directives
• Preprocessor directives are lines included in a program that
begin with the character #, which make them different from a
typical source code text. They are invoked by the compiler to
process some programs before compilation.
Problem Analysis
If we are to use the computer as a problem-solving tool, then
we must have a good analysis of the problem given. Here are
some suggested steps on how to go about analyzing a certain
problem for computer application:
1. Review the problem carefully and understand what you are
asked to do.
2. Determine what information is given(input) and what result
must be produced(output).
3. Assign names to each input and output items.
4. Determine the manner of processing that must be done on
the input data to come up with the desired output(i.e.,
determine what formulas are needed to manipulate the given
data).

You might also like