A computer understands only patterns of bits. People, however, think in words and formulas. Programming languages bridge this gap, and over seventy years they have moved steadily closer to human ways of expressing ideas.
Generations of Programming Languages
Languages are grouped into generations according to their distance from the machine. Table 2.10 summarizes them.
Table 2.10: Generations of programming languages
| Generation | Name | Features | Examples |
|---|---|---|---|
| First | Machine language | Binary codes; runs directly; machine dependent | Binary instructions |
| Second | Assembly language | Short names (mnemonics) for instructions; needs an assembler | ADD, MOV |
| Third | High-level language | English-like statements; portable; needs a compiler or interpreter | C, FORTRAN, COBOL |
| Fourth | Very high-level language | States what is wanted, not how to do it | SQL |
| Fifth | Logic-based language | Works from facts and rules | Prolog |
The first two generations are called low-level languages, because programs are written in terms of the machine's own instructions. From the third generation onwards, languages are high-level: one statement stands for many machine instructions, and the same program can be moved from one kind of computer to another.
Translators
A program written in any language other than machine language must be translated before it can run.
Definition: Compiler. A program that translates an entire source program written in a high-level language into machine code before the program is run.
An assembler translates assembly language. An interpreter translates and carries out a high-level program one statement at a time. C is a compiled language.
Typed and Typeless Languages
Definition: Data type. A classification that determines the kind of value a variable can hold, the memory it occupies and the operations allowed on it.
In a typed language, every variable has a data type. In C the type must be declared before the variable is used, as in int count;. The compiler uses the type to reserve the right amount of memory and to detect mistakes, such as storing text in a numeric variable.
In a typeless language, variables are not declared with types, and any variable can hold any kind of value. BCPL and B, the ancestors of C, were typeless: every value was simply a machine word. Typeless languages are simpler to write but leave more errors to be discovered while the program is running.
History of C
C was developed by Dennis Ritchie at Bell Laboratories in 1972. Its line of descent is as follows.
- BCPL was developed by Martin Richards in 1967.
- B was developed by Ken Thompson in 1970, based on BCPL.
- C was developed by Dennis Ritchie in 1972, adding data types to the ideas of B.
C was created in order to write the UNIX operating system, and most of UNIX was rewritten in C in 1973. In 1978 Brian Kernighan and Dennis Ritchie published the book The C Programming Language. The language was standardized by ANSI in 1989.
Why C Is Still Studied
C is small, fast and close to the machine, yet it is a high-level, structured language. It is widely used for operating systems, compilers and embedded devices, and many later languages, including C++ and Java, borrowed its syntax.
Example 2.10: Declaring typed variables
Problem: Show that C associates a type and a size with every variable.
Solution:
- Declare variables of three common types.
- Use the
sizeofoperator to display the number of bytes each occupies.
#include <stdio.h>
int main(void)
{
char grade = 'A';
int count = 25;
float price = 99.5f;
printf("char : %c uses %d byte\n", grade, (int)sizeof grade);
printf("int : %d uses %d bytes\n", count, (int)sizeof count);
printf("float : %.1f uses %d bytes\n", price, (int)sizeof price);
return 0;
}
Output:
char : A uses 1 byte
int : 25 uses 4 bytes
float : 99.5 uses 4 bytes
Result: Each variable has a declared type that fixes its size and the kind of value it holds. The sizes shown are those of the compiler used here; the size of int can differ between systems.
Common mistakes
- Calling assembly language a high-level language; it is a low-level language.
- Confusing a compiler, which translates the whole program first, with an interpreter, which works statement by statement.
- Stating that C was developed by Ken Thompson; he developed B, and Dennis Ritchie developed C.
Key takeaways
- Languages are grouped into five generations, from machine language to logic-based languages.
- Machine and assembly languages are low-level; C is a high-level, compiled language.
- A typed language gives every variable a data type; a typeless language does not.
- C was developed by Dennis Ritchie at Bell Laboratories in 1972, descending from BCPL and B.
Practice questions
- Which generation of languages does C belong to?
- Who developed the C language, and where?
- What is the job of a compiler?
Answers to the practice questions
- The third generation, the high-level languages.
- Dennis Ritchie, at Bell Laboratories, in 1972.
- To translate an entire high-level source program into machine code before it is run.
Sources
- Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit II
