0% found this document useful (0 votes)
9 views47 pages

Chapter 1

The document provides an overview of programming languages, defining them as vocabularies and grammatical rules for instructing computers. It categorizes programming languages into low-level and high-level languages, explaining their characteristics, uses, and evolution over time. Additionally, it discusses data structures and operators, highlighting their importance in programming.

Uploaded by

mumubrown706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views47 pages

Chapter 1

The document provides an overview of programming languages, defining them as vocabularies and grammatical rules for instructing computers. It categorizes programming languages into low-level and high-level languages, explaining their characteristics, uses, and evolution over time. Additionally, it discusses data structures and operators, highlighting their importance in programming.

Uploaded by

mumubrown706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Chapter 1

Introduction to programming
languages

1
Definitions of programming languages
• A programming language is a vocabulary and set of grammatical rules for instructing a computer or
computing device to perform specific tasks. It is a set of instructions that are compiled together to
perform a specific task.

• A programming language is a computer language that programmers use to develop software

programs, scripts, or other sets of instructions for computers to execute.

• Although many languages share similarities, each has its own syntax. Once a programmer learns the

languages rules, syntax, and structure, they write the source code in a text editor or IDE. Then, the

programmer often compiles the code into machine language that can be understood by the computer.

• Scripting languages, which do not require a compiler, use an interpreter to execute the script.

2
Cont.
• The term programming language usually refers to high-level languages, such
as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal.

• A program written in a particular programming language has two parts: instructions written in that
language and statements written in another language called machine code.

• Machine code is a binary format that consists of ones and zeros (1 and 0); each digit represents
either an instruction or data within the program.

3
Cont.
• Each programming language contains a unique set of keywords and syntax, which are used to
create a set of instructions. Thousands of programming languages have been developed till now,
but each language has its specific purpose. These languages vary in the level of abstraction they
provide from the hardware.

• Some programming languages provide less or no abstraction while some provide higher
abstraction.

• Based on the levels of abstraction, they can be classified into two categories:
Low-level language
High-level language

4
Cont.

• The image which is given below describes the abstraction level from hardware.

• As we can observe from the below image that the machine language provides no abstraction,
assembly language provides less abstraction whereas high-level language provides a higher level of
abstraction.

5
Cont.

• Today, there are thousands of programming languages. They can be classified in a variety of ways.

• One classification is by generation.

 First-generation languages are the machine languages.

 Second-generation are the assembly languages.

 Third-generation are the higher-level languages like Fortran, Cobol, Lisp, C,


C + + , C # , and Java.

 Fourth-generation languages are languages designed for specific applications like NOMAD
for report generation, SQL for database queries, and Postscript for text formatting.

 Fifth-generation language has been applied to logic- and constraint-based languages like
Prolog and OPS5.
6
Low-level language
• The low-level language is a programming language that provides no abstraction from the hardware,
and it is represented in 0 or 1 forms, which are the machine instructions. The languages that come
under this category are the Machine level language and Assembly language.

 Machine-level language: It is a language that consists of a set of instructions that are in the binary
form 0 or 1. As we know that computers can understand only machine instructions, which are in
binary digits, i.e., 0 and 1, so the instructions given to the computer can be only in binary codes.

• Creating a program in a machine-level language is a very difficult task as it is not easy for the
programmers to write the program in machine instructions.

• It is error-prone as it is not easy to understand, and its maintenance is also very high. A machine-
level language is not portable as each computer has its machine instructions, so if we write a
program in one computer will no longer be valid in another computer.
7
Cont.
• The different processor architectures use different machine codes, for example, a PowerPC
processor contains RISC architecture, which requires different code than intel x86 processor, which
has a CISC architecture.

 Assembly Language: It contains some human-readable commands such as mov, add, sub, etc.

• The problems which we were facing in machine-level language are reduced to some extent by
using an extended form of machine-level language known as assembly language.

• Since assembly language instructions are written in English words like mov, add, sub, so it is easier
to write and understand.

8
Cont.
• As we know that computers can only understand the machine-level instructions, so we require a
translator that converts the assembly code into machine code. The translator used for translating the
code is known as an assembler.

• The assembly language code is not portable because the data is stored in computer registers, and
the computer has to know the different sets of registers.

• The assembly code is not faster than machine code because the assembly language comes above
the machine language in the hierarchy, so it means that assembly language has some abstraction
from the hardware while machine language has zero abstraction.

9
Cont.
Machine-level language Assembly language

It comes at the lowest level in the hierarchy, so it It comes above the machine language means that
has zero abstraction level from the hardware. it has less abstraction level from the hardware.

It cannot be easily understood by humans. It is easy to read, write, and maintain.

It is written in binary digits, i.e., 0 and 1. It is written in simple English language, so it is


easily understandable by the users.

It does not require any translator as the machine In assembly language, the assembler is used to
code is directly executed by the computer. convert the assembly code into machine code.

It is a first-generation programming language. It is a second-generation programming language.

10
High-Level Language
• The high-level language is a programming language that allows a programmer to write the
programs which are independent of a particular type of computer.

• The high-level languages are considered as high-level because they are closer to human languages
than machine-level languages.

• When writing a program in a high-level language, then the whole attention needs to be paid to the
logic of the problem.

• A compiler is required to translate a high-level language into a low-level language.

• Examples of high level languages are C, C++, C#, Java, Python, JavaScript, PHP, Visual Basic,
FORTRAN, LISP, Pascal, Prolog, Ruby, Perl, GO, Rust, etc.

11
Cont.
Low-level language High-level language

It is a machine-friendly language It is a programmer-friendly language

It takes more time to execute. It executes at a faster pace.

It requires the assembler to convert the assembly It requires the compiler/interpreter to convert the
code into machine code. high-level language instructions into machine
code.

The machine code cannot run on all machines, so The high-level code can run on all the platforms,
it is not a portable language (machine-dependent). so it is a portable language.

It is high memory efficient. It is less memory efficient.

Debugging and maintenance are not easier in a Debugging and maintenance are easier in a high-
low-level language. level language.
12
Evolution of Programming Languages

• Programming languages continue to evolve in both industry and research, as systems and
applications change.

• Today there is a wide variety of programming languages with different languages, syntax, and
features.

• Developers can now use a language based on either the client's preference or their own.

• Language technology developed between 1967 and 1997, giving birth to some of the most
popularly used programming languages even now.

• The swift growth of the internet in the mid-1990s was a major boost to the programming language
world.

13
Cont.
• In the computer world, we have about 500+ programming languages with having their own syntax
and features.

• And if you type who’s the father of the computer, then the search engine will show you the result
as to Charles Babbage but the father of the computer didn’t write the first code.

• It was Ada Lovelace who has written the first-ever computer programming language and the year
was 1883.

14
Cont.
 1883: The Journey starts from here…!!

• In the early days, Charles Babbage had made the device, but he was confused about how to give
instructions to the machine, and then Ada Lovelace wrote the instructions for the analytical engine.

• The device was made by Charles Babbage and the code was written by Ada Lovelace for
computing Bernoulli’s number. First time in history that the capability of computer devices was
judged.

 1949: Assembly Language

• It is a type of low-level language. It mainly consists of instructions (kind of symbols) that only
machines could understand. In today’s time also assembly language is used in real-time programs
such as simulation flight navigation systems and medical equipment eg – Fly-by-wire (FBW)
systems. It is also used to create computer viruses.
15
Cont.
 1952: Autocode

• Developed by Alick Glennie.

• The first compiled computer programming language.

• COBOL and FORTRAN are the languages referred to as Autocode.

 1957: FORTRAN

• Developers are John Backus and IBM.

• It was designed for numeric computation and scientific computing.

• Software for NASA probes voyager-1 (space probe) and voyager-2 (space probe) was originally
written in FORTRAN 5.
16
Cont.
 1958: ALGOL

• ALGOL stands for ALGOrithmic Language.

• The initial phase of the most popular programming languages of C, C++, and JAVA.

• It was also the first language implementing the nested function and has a simple syntax than
FORTRAN.

• The first programming language to have a code block like “begin” that indicates that your program
has started and “end” means you have ended your code.

17
Cont.
 1959: COBOL

• It stands for COmmon Business-Oriented Language.

• In 1997, 80% of the world’s business ran on Cobol.

• The US internal revenue service scrambled its path to COBOL-based IMF (individual master file)
in order to pay the tens of millions of payments mandated by the coronavirus aid, relief, and
economic security.

 1964: BASIC

• It stands for beginners All-purpose symbolic instruction code.

• In 1991 Microsoft released Visual Basic, an updated version of Basic

• The first microcomputer version of Basic was co-written by Bill Gates, Paul Allen, and Monte
Davidoff for their newly-formed company, Microsoft. 18
Cont.
 1972: C

• It is a general-purpose, procedural programming language and the most popular programming


language till now.

• All the code that was previously written in assembly language gets replaced by the C language like
operating system, kernel, and many other applications.

• It can be used in implementing an operating system, embedded system, and also on the website
using the Common Gateway Interface (CGI).

• C is the mother of almost all higher-level programming languages like C#, D, Go, Java, JavaScript,
Limbo, LPC, Perl, PHP, Python, and Unix’s C shell.

19
Cont.
 Some other programming languages that are popular among programmers are listed below.

YEAR OF PROGRAMMING
FACTS
RELEASE LANGUAGES
SQL was developed at IBM by Donald D. Chamberlin and Raymond F.
1972 SQL Boyce. The earlier name was SEQUEL (Structured English Query
Language).
It stands for MATrix LABoratory. It is used for matrix manipulation,
1978 MATLAB
implementation of an algorithm, and creation of a user interface.
C++ is the fastest high-level programming language.
1983 Objective-C, C++
Earlier, Apple Inc uses Objective-C to make applications.
1990 Haskell It is a purely functional programming language.
The language is very easy to understand. Famous language among data
1991 Python
scientists and analysts. 20
Cont.
JAVA is everywhere. JAVA is a platform-independent language. PHP is a
scripting language mainly used in web programming for connecting databases.
JAVA, PHP,
1995 JavaScript enables interactive web pages. JS is the most popular programming
JavaScript
language. JS is famous for building web applications. It makes our page
interactive.
C#(C-sharp) is mainly used for making games. Unity engine uses C# for
2000 C#
making amazing games for all platforms
GO language is developed in Google by Robert Griesemer, Rob Pike, and Ken
2009 GO
Thompson.
2011 Kotlin Kotlin is developed by JetBrains. It is used for making an android application.
Swift language is developed by Apple Inc. It is a general-purpose programming
2014 Swift
language.
21
Elements of Programming languages
Data element: is an atomic unit of data that has precise meaning or precise semantics.

• A data element has:

 An identification such as a data element name

 A clear data element definition

 One or more representation terms

 Optional enumerated values Code (metadata)

 A list of synonyms to data elements in other metadata registries Synonym ring

• It is a basic unit of information that has a unique meaning and subcategories (data items) of distinct
value.

• Examples of data elements include gender, race, and geographic location.


22
Cont.
Data structure: is a storage that is used to store and organize data.

• It is a way of arranging data on a computer so that it can be accessed and updated efficiently.

• A data structure is not only used for organizing the data.

• It is also used for processing, retrieving, and storing data.

• There are different basic and advanced types of data structures that are used in almost every

program or software system that has been developed.

• Types of Data Structures: There are two types of data structures:

1) Primitive data structure

2) Non-primitive data structure

23
Cont.
1) Primitive Data structure

• The primitive data structures are primitive data types. The int, char, float, double, and pointer are
the primitive data structures that can hold a single value.
o Example-1: int x = 10;
o Example-2: char sex=‘M’;
o Example-3: int fv;
int * pt;
2) Non-Primitive Data structure pt = &fv;
*pt = 10;
• The non-primitive data structure is divided into two types:

o Linear data structure

o Non-linear data structure

24
Cont.
o Linear data structure: Data structure in which data elements are arranged sequentially or linearly,
where each element is attached to its previous and next adjacent elements, is called a linear data
structure. Examples of linear data structures are array, stack, queue, linked list, etc.

• Static data structure: Static data structure has a fixed memory size. It is easier to access the
elements in a static data structure. It size is allocated at the compile time.
An example of this data structure is an array.  Example: int num[5];

• Dynamic data structure: In dynamic data structure, the size is not fixed (flexible). It can be
randomly updated during the runtime which may be considered efficient concerning the
memory (space) complexity of the code. Therefore it size is allocated at the run time.
Examples of this data structure are linked list, queue, stack, etc.
Example: struct node {
char name[20]; int age;
float height;
node *nxt; };
node *start_ptr = NULL;
25
Cont.
o Non-linear data structure: Data structures where data elements are not placed sequentially or
linearly are called non-linear data structures. In a non-linear data structure, we can’t traverse all the
elements in a single run only.
Examples of non-linear data structures are trees and graphs.
 Tree  Graph
Example: struct node { Example: struct Vertex {
int data; char label;
struct node *leftChild; bool visited;
struct node *rightChild; };
};
struct node *root = NULL;

26
Cont.
Operator: is a symbol that tells the compiler to perform specific mathematical or logical functions.

• C, C++ or other programming language is rich in built-in operators and provides the following types
of operators:

 Arithmetic Operators

 Relational Operators

 Logical Operators

 Bitwise Operators

 Assignment Operators

 Other Operators

 Operator precedence
27
Cont.
 Arithmetic Operators
• The following table shows all the arithmetic operators supported by the C/C++ language.
• Assume variable A holds 10 and variable B holds 20 then −

Operator Description Example

+ Adds two operands. A + B = 30

− Subtracts second operand from the first. A − B = -10

* Multiplies both operands. A * B = 200

/ Divides numerator by de-numerator. B/A=2

% Modulus Operator and remainder of after an integer division. B%A=0

++ Increment operator increases the integer value by one. A++ = 11


-- Decrement operator decreases the integer value by one. A-- = 9

28
Cont.
 Relational Operators
• The following table shows all the relational operators supported by C/C++ language.
• Assume variable A holds 10 and variable B holds 20 then −

Operator Description Example

== Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true.

Checks if the values of two operands are equal or not. If the values are not equal, then the condition
!= (A != B) is true.
becomes true.
Checks if the value of left operand is greater than the value of right operand. If yes, then the
> (A > B) is not true.
condition becomes true.
Checks if the value of left operand is less than the value of right operand. If yes, then the condition
< (A < B) is true.
becomes true.
Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then
>= (A >= B) is not true.
the condition becomes true.
Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the
<= (A <= B) is true.
condition becomes true.

29
Cont.
 Logical Operators
• Following table shows all the logical operators supported by C/C++ language.
• Assume variable A holds 1 and variable B holds 0, then −

Operator Description Example

&& Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false.

Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes
|| (A || B) is true.
true.
Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is
! !(A && B) is true.
true, then Logical NOT operator will make it false.

30
Cont.
 Bitwise Operators
• Bitwise operator works on bits and perform bit-by-bit operation.
• The truth tables for &, |, and ^ is as follows −

p q p&q p|q p^q  Assume A = 60 and B = 13 in binary format, they will


0 0 0 0 0 be as follows − A = 0011 1100
B = 0000 1101
0 1 0 1 1 -----------------------------
1 0 0 1 1 A&B = 0000 1100
1 1 1 1 0 A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011

31
Cont.
• The following table lists the bitwise operators supported by C/C++ language.
• Assume variable 'A' holds 60 and variable 'B' holds 13, then −

Operator Description Example


(A & B) = 12, i.e.,
& Binary AND Operator copies a bit to the result if it exists in both operands.
0000 1100
(A | B) = 61, i.e.,
| Binary OR Operator copies a bit if it exists in either operand.
0011 1101
(A ^ B) = 49, i.e.,
^ Binary XOR Operator copies the bit if it is set in one operand but not both.
0011 0001
(~A ) = ~(60), i.e,. -
~ Binary One's Complement Operator is unary and has the effect of 'flipping' bits.
1100 0011
Binary Left Shift Operator. The left operands value is moved left by the number of bits specified A << 2 = 240 i.e.,
<<
by the right operand. 1111 0000
Binary Right Shift Operator. The left operands value is moved right by the number of bits specified A >> 2 = 15 i.e.,
>>
by the right operand. 0000 1111

32
Cont.
 Assignment Operators
• The following table lists the assignment operators supported by the C/C++ language −
Operator Description Example
C = A + B will assign
= Simple assignment operator. Assigns values from right side operands to left side operand the value of A + B to
C
Add AND assignment operator. It adds the right operand to the left operand and assign the result to C += A is equivalent
+=
the left operand. to C = C + A
Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns C -= A is equivalent
-=
the result to the left operand. to C = C - A
Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns C *= A is equivalent
*=
the result to the left operand. to C = C * A
Divide AND assignment operator. It divides the left operand with the right operand and assigns the C /= A is equivalent
/=
result to the left operand. to C = C / A
Modulus AND assignment operator. It takes modulus using two operands and assigns the result to C %= A is equivalent
%=
the left operand. to C = C % A

33
Cont.
Operator Description Example

<<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2

>>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2

&= Bitwise AND assignment operator. C &= 2 is same as C = C & 2

^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2

|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2

34
Cont.
 Other Operators

• Besides the operators discussed above, there are a few other important operators such as ternary
operator ?:, reference operator &, dereference operator * and member selection operator ->
supported by the C/C++ Language.
Operator Description Example
sizeof() Returns the size of a variable. sizeof(a), where a is integer, will return 4.

& Returns the address of a variable. &a; returns the actual address of the variable.

* Pointer to a variable. *a;

?: Conditional Expression. If Condition is true ? then value X : otherwise value Y


a->b is the same as (*a).b , where a is variable definition of structure
-> Arrow operator
with pointer and b is element member of structure defined.
a.b is considered like (a).b , where a is variable definition of structure
. Dot operator without pointer and b is element member of structure defined.

35
Cont.
 Operators Precedence in C/C++
• Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated.
• Certain operators have higher precedence than others; for example, the multiplication operator has
a higher precedence than the addition operator.
• For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
• Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
Category Operator Associativity

Postfix () [] -> . ++ - - Left to right

Unary + - ! ~ ++ - - (type)* & sizeof Right to left

Multiplicative */% Left to right

36
Cont.
Category Operator Associativity

Additive +- Left to right

Shift << >> Left to right

Relational < <= > >= Left to right

Equality == != Left to right

Bitwise AND & Left to right

Bitwise XOR ^ Left to right

Bitwise OR | Left to right

Logical AND && Left to right

Logical OR || Left to right

Conditional ?: Right to left

Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left


37
Cont.
 Program unit: is a sequence of one or more lines, organized as statements, comments,
and INCLUDE directives.

• Specifically, a program unit can be:

 The main program

 A module

 A block data program unit

 An external function subprogram

 An external subroutine subprogram

• An executable program is a collection of program units consisting of one main program and any
number of external subprograms, modules, and block data program units.

38
Cont.
• A subprogram can be invoked by a main program or by another subprogram to perform a particular
activity.

• When a procedure is invoked, the referenced subprogram is executed.

• An external or module subprogram can contain multiple ENTRY statements.

• The subprogram defines a procedure for the SUBROUTINE or FUNCTION statement, as well as
one procedure for each ENTRY statement.

• An external procedure is defined either by an external subprogram or by a program unit in a


programming language other than Fortran.

• Names of main programs, external procedures, block data program units, and modules are global
entities. Names of internal and module procedures are local entities.
39
Cont.
 Parameter Transmission: mechanism of argument/parameter data can be passed into and out of
methods and functions.

• Assume a function B() is called from another function A(). In this case A is called the “caller
function” and B is called the “called function or callee function”.

• Also, the arguments which A sends to B are called actual arguments and the parameters of B are
called formal arguments.

• Formal Parameter : A variable and its type as they appear in the prototype of the function or
method.

• Actual Parameter : The variable or expression corresponding to a formal parameter that appears
in the function or method call in the calling environment.

40
Cont.
• Modes:

• IN: Passes info from caller to callee.

• OUT: Callee writes values in caller.

• IN/OUT: Caller tells callee value of variable, which may be updated by callee

 Important methods of Parameter Passing

 Pass By Value: This method uses in-mode semantics. Changes made to formal parameter do not
get transmitted back to the caller. Any modifications to the formal parameter variable inside the
called function or method affect only the separate storage location and will not be reflected in the
actual parameter in the calling environment. This method is also called as call by value.
void main()
{ void func(int a, int b) Output:
int x = 5, y = 7; {
a += b;  a = 12 b = 7
// Passing by value
func(x, y); cout << a << b << endl;  x=5y=7
cout <<x<< y<<endl; } } 41
Cont.
 Pass by reference(aliasing): This technique uses in/out-mode semantics. Changes made to formal
parameter do get transmitted back to the caller through parameter passing. Any changes to the
formal parameter are reflected in the actual parameter in the calling environment as formal
parameter receives a reference (or pointer) to the actual data. This method is also called as call by
reference. This method is efficient in both time and space
Output:
 x= 10
void main() void func(int *a)
{ {  *a = 20 and a= address of x (&x)
int x = 10; *a= 20;
// Passing by reference  20
cout <<*a<<“and”<< a << endl;
cout << x << endl; }
func(&x);
cout << x << endl;
}

42
Cont.
 Storage Management: is defined as it refers to the management of the data storage equipment’s
that are used to store the user/computer generated data.

• Hence it is a tool or set of processes used by an administrator to keep your data and storage
equipment’s safe.

• Storage management is a process for users to optimize the use of storage devices and to protect the
integrity of data for any media on which it resides and the category of storage management
generally contain the different type of subcategories covering aspects such as security,
virtualization and more, as well as different types of provisioning or automation, which is generally
made up the entire storage management software market.

43
Cont.
 Storage management key attributes:
Storage management has some key attribute which is generally used to manage the storage
capacity of the system. These are given below:

1. Performance

2. Reliability

3. Recoverability

4. Capacity

44
Cont.
 Feature of Storage management:

• There is some feature of storage management which is provided for storage capacity.

• These are given below:

1) Storage management is a process that is used to optimize the use of storage devices.

2) Storage management must be allocated and managed as a resource in order to truly benefit a
corporation.

3) Storage management is generally a basic system component of information systems.

4) It is used to improve the performance of their data storage resources.

45
Cont.
 Advantage of storage management:

• There are some advantage of storage management which are given below:

o It is very simple to managed a storage capacity.

o It is generally take a less time.

o It is improve the performance of system.

o In virtualization and automation technologies can help an organization improve its agility.

46
Programming Language Basics

• The Static/Dynamic Distinction

• Environments and States

• Static Scope and Block Structure

• Explicit Access Control

• Dynamic Scope

• Parameter Passing Mechanisms

• Aliasing

47

You might also like