0% found this document useful (0 votes)
10 views12 pages

Unit 1

The document provides an overview of language and programming languages, defining them and discussing their types, including low-level and high-level languages. It outlines key features of programming languages, structured and modular programming approaches, and stages of program development. Additionally, it covers the C programming language, its history, features, tokens, identifiers, keywords, and variables.

Uploaded by

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

Unit 1

The document provides an overview of language and programming languages, defining them and discussing their types, including low-level and high-level languages. It outlines key features of programming languages, structured and modular programming approaches, and stages of program development. Additionally, it covers the C programming language, its history, features, tokens, identifiers, keywords, and variables.

Uploaded by

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

Unit-1

What is Language?

Language is a mode of communication that is used to share ideas, opinions with each other. For example, if
we want to teach someone, we need a language that is understandable by both communicators.

What is a Programming Language?

A programming language is a computer language that is used by programmers (developers) to communicate


with computers. It is a set of instructions written in any specific language ( C, C++, Java, Python) to perform a
specific task.

A programming language is mainly used to develop desktop applications, websites, and mobile applications.

Types of programming language

1. Low-level programming language

Low-level language is machine-dependent (0s and 1s) programming language. The processor runs low- level
programs directly without the need of a compiler or interpreter, so the programs written in low-level language
can be run very fast.

Low-level language is further divided into two parts -

i. Machine Language

Machine language is a type of low-level programming language. It is also called as machine code or object
code. Machine language is easier to read because it is normally displayed in binary or hexadecimal form (base
16) form. It does not require a translator to convert the programs because computers directly understand the
machine language programs.

The advantage of machine language is that it helps the programmer to execute the programs faster than the high-
level programming language.

ii. Assembly Language

Assembly language (ASM) is also a type of low-level programming language that is designed for specific
processors. It represents the set of instructions in a symbolic and human-understandable form. It uses an
assembler to convert the assembly language to machine language.

The advantage of assembly language is that it requires less memory and less execution time to execute a
program.

2. High-level programming language

High-level programming language (HLL) is designed for developing user-friendly software programs and
websites. This programming language requires a compiler or interpreter to translate the program into machine
language (execute the program).

The main advantage of a high-level language is that it is easy to read, write, and maintain.

High-level programming language includes Python, Java, JavaScript, PHP, C#, C++, Objective C, Cobol,
Perl, Pascal, LISP, FORTRAN, and Swift programming language.
Main features of programming languages

The popularity of a programming language depends on the features and utilities it provides to programmers. The
features that a programming language must have to stand out are the following:

● Simplicity: the language must offer clear and simple concepts that facilitate its learning and
application, in a way that is simple to understand and maintain. Simplicity does not mean that it can be
subtracted from the optimal power of functioning.
● Naturalness: this means that its application in the area for which it was designed must be done
naturally, providing operators, structures and syntax for operators to work efficiently.
● Abstraction: it is the ability to define and use complicated structures or operations while ignoring
some details, which influences writing ability.
● Efficiency: Programming languages must be translated and executed efficiently so as not to take up too
much memory space or require too much time.
● Structuring: the language allows programmers to write their codes according to structured
programming concepts, to avoid creating errors.
● Compactness: with this characteristic, it is possible to express operations concisely, without having to
write too many details.
● Locality: refers to the codes concentrating on the part of the program with which you are working at a
given time.

Structured Programming :-

Structured Programming Approach, as the word suggests, can be defined as a programming approach in
which the program is made as a single structure. It means that the code will execute the instruction by
instruction one after the other. It doesn’t support the possibility of jumping from one instruction to some other
with the help of any statement like GOTO, etc. Therefore, the instructions in this approach will be executed in a
serial and structured manner. The languages that support Structured programming approach are:
● C

● C++

● Java

● C#

The structured program mainly consists of three types of elements:

● Selection Statements

● Sequence Statements

● Iteration Statements

Advantages of Structured Programming Approach:


1. Easier to read and understand
2. User Friendly
3. Easier to Maintain.
4. Development is easier as it requires less effort and time
5. Easier to Debug
6. Machine-Independent, mostly.

Modular programming:-
Modular programming is defined as a software design technique that focuses on separating the program
functionality into independent, interchangeable methods/modules. Each of them contains everything needed
to execute only one aspect of functionality.

Advantages of modular programming:

The following are advantages of modular programming –

⮚ Code is easier to read

⮚ Code is easier to test

⮚ Reusability

⮚ Faster fixes

Disadvantages of modular programming:-

The following are disadvantages of modular programming -

⮚ There is a need for extra time and budget for a product in modular programming.

⮚ It is a challenging task to combine all the modules.

⮚ Careful documentation is required so that other program modules are not affected.

Stages of program development process


The various stages in the development of a computer program are :

1. Problem Definition
2. Program Design
3. Coding
4. Debugging
5. Testing
6. Documentation
7. Maintenance

Problem Definition:

● The first step in the process of program development is the thorough understanding and identification
of the problem for which is the program or software is to be developed.
● In this step the problem has to be defined formally.

● All the factors like Input/output, processing requirement, memory requirements, error handling,
interfacing with other programs have to be taken into consideration in this stage.

Program Design:
● The next stage is the program design. The software developer makes use of tools like algorithms and
flowcharts to develop the design of the program.
o Algorithm
o Flowchart

Coding:

● Once the design process is complete, the actual computer program is written, i.e. the instructions are
written in a computer language.
● Coding is generally a very small part of the entire program development process and also a less time
consuming activity in reality.
● In this process all the syntax errors i.e. errors related to spelling, missing commas, undefined labels etc.
are eliminated.
● For effective coding some of the guide lines which are applied are :
o Use of meaningful names and labels of variables,
o Simple and clear expressions,
o Modularity with emphasis on making modules generalized,
o Making use of comments and indenting the code properly,
o Avoiding jumps in the program to transfer control.

Debugging:

● At this stage the errors in the programs are detected and corrected.

● This stage of program development is an important process. Debugging is also known as program
validation.
● Some common errors which might occur in the programs include:
o Un initialization of variables.
o Reversing of order of operands.
o Confusion of numbers and characters.
o Inverting of conditions eg jumping on zero instead of on not zero.

Testing:

● The program is tested on a number of suitable test cases.

● A test plan of the program has to be done at the stage of the program design itself.

● This ensures a thorough understanding of the specifications.

● The most trivial and the most special cases should be identified and tested.

● It is always useful to include the maximum and minimum values of all variables as test data.

Documentation:

● Documentation is a very essential step in the program development.

● Documentation help the users and the people who maintain the software.

● This ensures that future modification if required can be done easily. Also it is required during
redesigning and maintenance.
Maintenance:

● Updating and correction of the program for changed conditions and field experience is accounted for in
maintenance.
● Maintenance becomes essential in following situations:
o Change in specification,
o Change in equipment,
o Errors which are found during the actual execution of the program.

C Language

The C Language is developed by Dennis Ritchie for creating system applications that directly interact with the
hardware devices such as drivers, kernels, etc.

C programming is considered as the base for other programming languages, that is why it is known as mother
language.

It can be defined by the following ways:

1. Mother language
2. System programming language
3. Procedure-oriented programming language
4. Structured programming language
5. Mid-level programming language

History of C Language
C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American
Telephone & Telegraph), located in the U.S.A.
Dennis Ritchie is known as the founder of the c language.
It was developed to overcome the problems of previous languages such as B etc.
Initially, C language was developed to be used in UNIX operating system. It inherits many features of previous
languages such as B.

Features of C Language
C is the widely used language. It provides many features that are given below.
1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion
10. Extensible

1) Simple

C is a simple language in the sense that it provides a structured approach (to break the problem into parts), the
rich set of library functions, data types, etc.

2) Machine Independent or Portable

Unlike assembly language, c programs can be executed on different machines with some machine specific
changes. Therefore, C is a machine independent language.

3) Mid-level programming language

Although, C is intended to do low-level programming. It is used to develop system applications such as


kernel, driver, etc. It also supports the features of a high-level language. That is why it is known as mid-level
language.
4) Structured programming language

C is a structured programming language in the sense that we can break the program into parts using
functions. So, it is easy to understand and modify. Functions also provide code reusability.

5) Rich Library

C provides a lot of inbuilt functions that make the development fast.

6) Memory Management

It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any
time by calling the free() function.

7) Speed

The compilation and execution time of C language is fast since there are lesser inbuilt functions and hence the
lesser overhead.

8) Pointer

C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use
pointers for memory, structures, functions, array, etc.

9) Recursion

In C, we can call the function within the function. It provides code reusability for every function. Recursion
enables us to use the approach of backtracking.

10) Extensible

C language is extensible because it can easily adopt new features.

First C Program
#include <stdio.h>
int main(){
printf("Hello C Language");
return 0;
}

#include <stdio.h> includes the standard input output library functions. The printf() function is defined in
stdio.h .
int main() The main() function is the entry point of every program in c language.

printf() The printf() function is used to print data on the console.


return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution
and 1 for unsuccessful execution.

Character Set
As every language contains a set of characters used to construct words, statements, etc., C language also has a
set of characters which include alphabets, digits, and special symbols. C language supports a total of 256
characters.

Every C program contains statements. These statements are constructed using words and these words are
constructed using characters from C character set. C language character set contains the following set of
characters...

1. Alphabets
2. Digits
3. Special Symbols

Alphabets
C language supports all the alphabets from the English language. Lower and upper case letters together support
52 alphabets.
lower case letters - a to z
UPPER CASE LETTERS - A to Z

Digits
C language supports 10 digits which are used to construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Special Symbols
C language supports a rich set of special symbols that include symbols to perform mathematical operations, to
check conditions, white spaces, backspaces, and other special symbols.
Special Symbols - ~ @ # $ % ^ & * ( ) _ - + = { } [ ] ; : ' " / ? . > , < \ |

TOKENS:

● C tokens are the basic buildings blocks in C language which are constructed together to write a C program.

● Each and every smallest individual units in a C program are known as C tokens.

C tokens are of six types. They are,


1. Keywords (eg: int, while),
2. Identifiers (eg: main, total),
3. Constants (eg: 10, 20),
4. Strings (eg: “total”, “hello”),
5. Special symbols (eg: (), {}),
6. Operators (eg: +, /,-,*)

C Identifiers
C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions,
labels, etc. An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but
the starting letter should be either an alphabet or an underscore.
We can say that an identifier is a collection of alphanumeric characters that begins either with an alphabetical
character or an underscore, which are used to represent various programming elements such as variables,
functions, arrays, structures, unions, labels, etc. There are 52 alphabetical characters (uppercase and lowercase),
underscore character, and ten numerical digits (0-9) that represent the identifiers. There is a total of 63
alphanumerical characters that represent the identifiers.

Rules for constructing C identifiers

o The first character of an identifier should be either an alphabet or an underscore, and then it can be
followed by any of the character, digit, or underscore.
o It should not begin with any numerical digit.
o In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say that identifiers
are case sensitive.
o Commas or blank spaces cannot be specified within an identifier.
o Keywords cannot be represented as an identifier.
o The length of the identifiers should not be more than 31 characters.
o Identifiers should be written in such a way that it is meaningful, short, and easy to read.

Example of valid identifiers


total, sum, average, _m _, sum_1, etc.

Example of invalid identifiers:-


1. 2sum (starts with a numerical digit)
2. int (reserved word)
3. char (reserved word)
4. m+n (special character, i.e., '+')

Keywords in C
A keyword is a reserved word. You cannot use it as a variable name, constant name, etc. There are only 32
reserved words (keywords) in the C language.
A list of 32 keywin the c language is given below:

auto break case char const continue default do

double else enum extern float for goto if

int long register return short signed sizeof static

struct switch typedef union unsigned void volatile while

ords

Differences between Keyword and Identifier

Keyword Identifier

Keyword is a pre-defined word. The identifier is a user-defined word

It must be written in a lowercase letter. It can be written in both lowercase and uppercase letters.

Its meaning is pre-defined in the c compiler. Its meaning is not defined in the c compiler.
It is a combination of alphabetical characters. It is a combination of alphanumeric characters.

It does not contain the underscore character. It can contain the underscore character.

Variables in C
A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be
reused many times.
It is a way to represent memory location through symbol so that it can be easily identified.
Let's see the syntax to declare a variable:
1. type variable_list;
The example of declaring the variable is given below:
1. int a;
2. float b;
3. char c;
Here, a, b, c are variables. The int, float, char are the data types.
We can also provide values while declaring the variables as given below:
1. int a=10,b=20; //declaring 2 variable of integer type
2. float f=20.8;
3. char c='A';

Rules for defining variables:_

o A variable can have alphabets, digits, and underscore.


o A variable name can start with the alphabet, and underscore only. It can't start with a digit.
o No whitespace is allowed within the variable name.
o A variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:

1. int a;
2. int _ab;
3. int a30;

Invalid variable names:

1. int 2;
2. int a b;
3. int long;

Data Types
A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
There are the following data types in C language.

Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type enum

Void Data Type void

Basic Data Types

The basic data types are integer-based and floating-point based. C language supports both signed and unsigned
literals.

The memory size of the basic data types may change according to 32 or 64-bit operating system.

Data Types Memory Size Range

char 1 byte 128 to 127

signed char 1 byte 128 to 127

unsigned char 1 byte 0 to 255

short 2 byte 32,768 to 32,767

signed short 2 byte 32,768 to 32,767

unsigned short 2 byte 0 to 65,535

int 2 byte 32,768 to 32,767

signed int 2 byte 32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte 32,768 to 32,767

signed short int 2 byte 32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

float 4 byte

double 8 byte

long double 10 byte


Library functions
Library functions are built-in functions that are grouped together and placed in a common location called
library.
Each function here performs a specific operation. We can use this library functions to get the pre-defined output.
All C standard library functions are declared by using many header files. These library functions are created at
the time of designing the compilers.
We include the header files in our C program by using #include<filename.h>. Whenever the program is run
and executed, the related files are included in the C program.
Header File Functions
Some of the header file functions are as follows −

● stdio.h − It is a standard i/o header file in which Input/output functions are


declared

● conio.h − This is a console input/output header file.

● string.h − All string related functions are in this header file.

● stdlib.h − This file contains common functions which are used in the C programs.

● math.h − All functions related to mathematics are in this header file.

● time.h − This file contains time and clock related functions.Built functions in stdio.h

You might also like