1) Definition
A programming language is the set of instructions through which humans interact with computers. These languages are used to give instructions and commands to the computer is known as programming language. E.g. C, C++, Java etc.
a)
History/Generation
There are five generations of
Programming Languages. They are:
i)
First Generation Languages (1GL)
1GL uses machine code to write
instruction to interact with computer. Machine code is the binary code (0 and
1) understood by computer. It is also called Machine Level Language.
ii)
Second Generation Languages(2GL)
2GL uses assembly language to
write a program. Assembly language is made up of symbolic instructions and
addresses, for e.g. ADD A. It is also called Assembly Level Language.
iii) Third
Generation Language(3GL)
3GL uses structured programming
language to write a program. Structured programming specifies a logical
structure on the program being written to make it more efficient and easier to
understand and modify. Examples of 3GL are Fortran, Basic, Turbo Pascal, C,
C++.
iv)
Fourth Generation Languages (4GL)
4GL uses Non-Procedural
programming language. Non procedural languages focus on what users want to do
rather than how they will be doing it. It consists of statements that are
similar to statements in the human language. These are used mainly in database
programming and scripting. Example of these languages include, SQL, MATLAB.
v)
Fifth Generation Languages (5GL)
5GL uses Artificial Intelligence.
Artificial Intelligence languages make the computer appear to communicate like
a human being. Examples of fifth generation language include Mercury, OPS5, and
Prolog.
b)
Classification
Programming languages can be
classified as:
·
Machine level language
The first-generation programming languages are known as machine language or
low-level language. The machine level language deals with only two digits 0 and
1which are also known as binary digits. As computer can only understand binary
i.e. 0 and 1 these language deals with the level of abstraction.
The advantages of this languages are as follows:
o
They are translator free and can be directly
executed by computer.
o
The execution speed of these program is very
high.
o
These languages are efficient.
o
Memory utilization is efficient and possible to
keep track of each bit of data.
The
disadvantages of this language are as follows:
o
It is very difficult to develop programs
o
The programmer must have detail knowledge of
hardware configuration
o
The programs are very difficult to understand by
human beings
o
It is difficult to debug the programs.
o
The programs developed in this language are
hardware dependent i.e. the program developed on one machine cannot be executed
in another machine.
·
Assembly level language
Assembly language is one level above than machine language. The second
generation languages is known as assembly language. This language uses the
concept of mnemonics and symbols for writing the program. The program writing
was made easier by the development of assembly language.
The advantages
of assembly language are as follows
o
It is easy to develop, understand and modify the
programs developed in assembly language than machine level language.
o
Less errors are generated in this language.
o
They are more standardized and easier to use
than machine languages.
·
The disadvantages of assembly language are as
follows
o
It is
machine dependent language.
o
The programmer needs to have detail knowledge of
hardware architecture.
o
This language needs additional language
translator to translate the program into machine code
o
Assembly
language program are still complex.
·
High Level Language
High level
language is the modern language that uses formats that are similar to English.
The purpose of developing high level languages was to enable people to write
programs easily in their own native language environment. The generation of languages
that belong to high level language are as follows:
o Third
generation language (structure oriented/ procedure oriented)
These languages belong to the third-generation
language. These programs focus on the logic of the program rather than the
hardware architecture. These languages are machine independent and the program
developed on one computer can be used in another computer. E.g. of these
languages are C, COBOL, ALGOL etc.
The advantages of these languages are as follows.
§
It is easy to learn, develop and understand the
problems.
§
The programs developed on this language can be
executed on other computers.
§
Program are easy to code and debug
§
Program written are less prone to error.
The disadvantages of these language are as follows
§
The program execution is slow
§
The program needs to be converted to machine
code so additional language translator is required
§
Uses computer resources less efficiently
§
The memory requirement of the program written
will be more compared to 1GL and 2GL
o Fourth
generation language (problem oriented/ object oriented)
This language is also termed as fourth generation
language. Most of the languages are general purpose programming languages and
can be used to develop any kinds of software for any platform. These programs
developed in this language are based on real world scenario.
The advantages of these languages are as follows
§
These languages are easy to learn and use
§
The debugging and coding are made easier
§
It is more user friendly.
§
The programs developed in these languages are
machine independent.
The disadvantages of these languages are as follows
§
The execution speed of the program is slower
§
It needs additional software to convert the
program to machine code
§
The memory requirement of the program is high
compared to other
§
programming languages
o Fifth
generation language (Natural Language processing)
Advantage of high-level language
o
Language are user friendly
o
Easier to learn
o
Easier to maintain
o
They are problem oriented rather than machine
based
Disadvantages of
high-level language
o
It takes additional translation time to
translate the source to machine code.
o
High level programs are comparatively slower
than low level programs.
o
Easier to maintain
o
Compared to low level programs, they are
generally less memory efficient.
o
Cannot communicate directly with the hardware.
o
Structure oriented language
Out of these language generation
C belongs to the third generation so it is called middle level language as well
as high level language.
c)
Compiler Interpreter and Assembler
Compiler Interpreter and
Assembler falls under the category of language translator. Language Translators
A program written in high-level language is called as source code. To convert
the source code into machine code, translators are needed. A translator takes a
program written in source language as input and converts it into a program in
target language as output. It also detects and reports the error during
translation.
Roles of translator are
·
Translating the high-level language program
input into an equivalent machine language program.
·
Providing diagnostic or error messages wherever
the programmer violates specification or rules of the high-level language
program.
i)
Different type of translators
The different types of translator
are as follows:
(1)
Compiler
Compiler is a translator which is
used to convert programs in high-level language to low-level language. It
translates the entire program and also reports the errors in source program
encountered during the translation.
(2)
Interpreter
Interpreter is a translator which
is used to convert programs in high-level language to low-level language.
Interpreter translates line by line and reports the error once it encountered
during the translation process. It directly executes the operations specified
in the source program when the input is given by the user. It gives better
error diagnostics than a compiler
(3)
Assembler
Assembler is a translator which
is used to translate the assembly language code into machine language code.
d)
List of high-level programming languages
High level language are the languages which are easy to understand and can be written in English language. The development of program is easy using this language. The example of high-level language are as follows:
- C
- C++
- JAVA
- PHP
- BASIC
- .NET
e)
Syntax and semantics errors
A syntax error is like a
grammatical error or an error in spelling where you made a new, unrecognizable
word. So, basically you made a program the computer can’t read or understand
somewhere. Program doesn’t execute when it has these types of errors. So, these
kinds of errors are easily traceable and can be corrected by beginners of a
program.
For e.g.:
int a = 5 // semicolon is missing
So, compiler cannot process from
here as it requires semicolon so it shows error. A sematic error is the error
in the programming logic which computer can understand but the program gives
wrong output. The computer executes the program but the output is wrong. These
kinds of error are complex in nature and only expert programmers are able to
trace it in a huge program.
For e.g. c = a + b; for this
statement we mistakenly placed c = a-b; here the error is in the logic of the
program so program is right but the output produced by program is wrong.
f)
Program control structures
Program control structures
defines the flow of program. They define the way the program logic to flow in
the program. There are three program control structures they are:
·
Sequence
In this control structure the flow of program flows in sequential manner. The
logic defines the program to flow on the line by line basis. So in these
control structures the length of the program will be high and program becomes
complex due to same repetition of code. This will be addressed in upcoming
chapters
·
Selection
In this control structure the flow of program flows on the basis of
selection. The program has the capability to directly jump to the function
selected by user. The length of the program is reduced by the use of selection
techniques in a program. The most frequently used selection procedures in C
programming are switch, goto, and label.
·
Iteration
In this control structure the flow of a program is designed in such a way
the program continuously operates until the condition given by the user is
satisfied. The program keeps updating its input and output automatically as
defined by the user. These techniques reduce the length of a program and it is
very efficient. The iteration is also termed as looping. The loops available in
C programming are for,while, do…while.
i)
Program Design Tools
The program design tools are the
tools required to develop a program. During designing the program various tools
are required to design the program such as
·
Algorithm
·
Flowchart
·
Pseudocode
(1)
Algorithm
An algorithm is a set of steps of
operations to solve a problem performing calculation, data processing, and
automated reasoning tasks. An algorithm is an efficient method that can be
expressed within finite amount of time and space. An algorithm is the best way
to represent the solution of a particular problem in a very simple and
efficient way. If we have an algorithm for a specific problem, then we can
implement it in any programming language, meaning that the algorithm is independent
from any programming languages.
The main characteristics of
algorithms are as follows
·
Algorithms must have a unique name
·
Algorithms should have explicitly defined set of
inputs and outputs
·
Algorithms are well-ordered with unambiguous
operations
·
Algorithms halt in a finite amount of time.
Algorithms should not run for infinity, i.e., an algorithm must end at some
point
Algorithm for adding two
numbers
Step 1: start
Step2: input two
numbers x and y
Step3: read two
numbers x and y
Step4: z=x+y
Step5: display
result z
Step6: stop
(2)
Flowchart
A flowchart is simply a graphical
representation of steps. It shows steps in a sequential order, and is widely
used in presenting flow of algorithms, workflow or processes. Typically,
flowchart shows the steps as boxes of various kinds, and their order by
connecting them with arrows.
(3)
Pseudocode
Pseudocode gives a high-level
description of an algorithm without the ambiguity associated with plain text
but also without the need to know the syntax of a particular programming
language. The running time can be estimated in a more general manner by
using Pseudocode to represent the algorithm as a set of fundamental operations
which can then be counted.
Pseudocode for finding the area
of rectangle:
Input length breadth
Calculate area= length* breadth
Output: area
C programming, created by Dennis
Ritchie at Bell Labs in the early 1970s, stands as a foundational language in
the world of computing. With its efficiency, portability, and versatility, C
has remained a stalwart tool for programmers across diverse fields.
As a procedural language, C
offers a concise syntax and powerful features suitable for both low-level
memory management and high-level abstraction. Its direct interaction with
hardware makes it invaluable for system programming, embedded systems, and performance-critical
applications like gaming.
Furthermore, C's influence
extends to numerous other languages, including C++, Java, and Python, making it
an essential language to master for any programmer.
In this introduction, we'll
explore the basics of C programming, providing a solid foundation for your
journey into the world of software development.
#include <stdio.h>
int main(){
printf("Namaste!");
return 0;}
This is Basic Syntax for the C
programming. Whenever you start programming then you must include the library
and for the Standard Input and output you have to put stdio.h library. Above
Example shows the following things:
You are including standard input
output library.
You are using Main() function
You are Printing
"Namaste!"
You are informing CPU that after
the execution of program no more resource will be in use.(return 0; indicates
no more resource will be used.)
<stdio.h> is basic library
file that include following functions.
1. printf():
Prints formatted output to the console.
2. scanf():
Reads formatted input from the console.
3. fgets():
Reads a string from a file stream.
4. fputs():
Writes a string to a file stream.
5. fgetc():
Reads a character from a file stream.
6. fputc():
Writes a character to a file stream.
7. fread():
Reads data from a file stream into a buffer.
8. fwrite():
Writes data from a buffer into a file stream.
9. ftell():
Reports the current file position indicator for a file stream.
10. fopen():
Opens a file and returns a pointer to a file stream.
11. fclose():
Closes a file stream.
12. fflush():
Flushes the output buffer of a file stream.
13. setbuf():
Sets the buffer for a file stream.
14. setvbuf():
Sets the buffering mode for a file stream.
15. setlocale()
- sets the locale for formatted input/output functions
16. fprintf():
Prints formatted output to a file stream.
17. fscanf():
Reads formatted input from a file stream.
18. tmpfile():
Creates a temporary file.
19. tmpnam():
Generates a unique temporary file name.
20. remove():
Deletes a file.
21. rename():
Renames a file.
22. freopen():
Reopens a file stream with a specified mode.
23. getchar():
Reads a character from the standard input.
24. putchar():
Writes a character to the standard output.
25. gets():
Reads a string from the standard input.
26. puts():
Writes a string to the standard output.
27. feof():
Checks if the end-of-file indicator is set for a file stream.
28. ferror():
Checks if the error indicator is set for a file stream.
29. clearerr():
Clears the error and end-of-file indicators for a file stream.
30. fseek()
- sets the file position indicator to a location in a file stream.
31. ftell()
- returns the current value of the file position indicator for a stream.
32. fgetc()
- reads the next character from a stream.
33. vprintf()
- prints formatted output with a variable argument list to stdout
34. vfprintf()
- writes formatted output with a variable argument list to a file
35. vsprintf()
- writes formatted output with a variable argument list to a string
36. vscanf()
- reads formatted input with a variable argument list from stdin
37. vfscanf()
- reads formatted input with a variable argument list from a file
38. vsscanf()
- reads formatted input with a variable argument list from a string
0 Comments had been done yet:
Post a Comment