0% found this document useful (0 votes)
3 views

Computer Programming Chapter wise question

The document provides an overview of computer software, categorizing it into system software and application software, detailing their functions and differences. It also discusses essential software features, types of programming languages, and the characteristics of low-level and high-level languages. Key aspects include the importance of usability, efficiency, flexibility, and maintainability in software development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Programming Chapter wise question

The document provides an overview of computer software, categorizing it into system software and application software, detailing their functions and differences. It also discusses essential software features, types of programming languages, and the characteristics of low-level and high-level languages. Key aspects include the importance of usability, efficiency, flexibility, and maintainability in software development.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Table of Contents

Computer Software: ................................................................................................................................ 2


1. System Software:......................................................................................................................... 2
2. Application Software: .................................................................................................................. 2
Features a Software must have: .............................................................................................................. 3
Types or Levels of Programming Languages: .......................................................................................... 5
1. Low-level Language: .................................................................................................................... 5
2. High-level Language: ................................................................................................................... 6
Language Processor: ............................................................................................................................... 6
Difference between Compiler and Interpreter: ...................................................................................... 7
Problem Solving Using Computer: .......................................................................................................... 8
Difference between Source Code and Object Code:............................................................................. 11
Importance/ Advantages of C: .............................................................................................................. 11
Executing a C Program/Compilation Phases: ........................................................................................ 12
Basic Structure of C Program: ............................................................................................................... 13
Function of semicolon in C programming ............................................................................................. 14
Keywords: .............................................................................................................................................. 14
Identifiers: ............................................................................................................................................. 15
Data Types: ............................................................................................................................................ 15
Constants .............................................................................................................................................. 17
Variables ................................................................................................................................................ 17
Preprocessor Directives ........................................................................................................................ 18
Tokens In C ............................................................................................................................................ 18
Operators .............................................................................................................................................. 18
Operator Precedence and Associativity ................................................................................................ 20
Expression: ............................................................................................................................................ 21
Type Conversions in Expressions........................................................................................................... 21
Formatted Functions ................................................................................ Error! Bookmark not defined.
Unformatted Functions ............................................................................ Error! Bookmark not defined.
Formatted I/O vs Unformatted I/O .......................................................... Error! Bookmark not defined.

1|Page
Computer Software:
Software is a computer program which is a sequence of instructions designed to direct a computer to
perform certain functions. The software enables a computer to receive input, store information,
make decisions, manipulate, and output data in the correct order and format. Most of the software
on a computer comes in the form of programs. A program consists of “instructions” that tell the
computer what to do, how to behave. Software is generally categorized as: System Software and
Application Software.

1. System Software:
The type of software which is most essential for computer operation and directs the inter-operations
of computer are called system software. System software refers to the files and programs that make
up computer’s operating system. System files include libraries of functions, system services, utility
programs, drivers for printers and other hardware, system preferences, and other configuration files.
The system software is installed on a computer when we install our operating system. Since system
software runs at the most basic level of computer, it is called “low-level” software. Example: OS,
System support software, etc.

2. Application Software:
The types of software which is used for user’s specific application are called application software. It
consists of a number of programs designed to perform specific user application. The types of
application software are listed below:

a. Tailored Software: Tailored software is designed specifically for a specific company or individual.
It is created by experts in the field and is quite expensive because the entire budget is set up by
the individual or company. Software is tested, but it may include bugs, and no documentation is
provided.
b. Package Software: Packaged software is software that is designed primarily for common users. It
is created by computer specialists and is inexpensive, sometimes even free. Software is
thoroughly tested, has fewer errors, and includes documentation. For example: Microsoft office
package.
c. Utility Software: Utility software includes all systems and programs on a computer system that
maintain its functionality. A computer’s utility software includes components that assist the
operating system to optimize, maintain, organize and manage how it functions in all situations.

Differences between System Software and Application Software are:

System Software Application Software


System software are the type of software Application software are the type of software
designed to manage system resources, such as designed to meet the requirements of users to
memory management, thread management, perform specific tasks.
system security, and more.
System software acts as an interface between Application software acts as an interface
the application software and the system. It between users and system software.
basically provides a platform to install and run
application software.
System software are usually written in a low- Application software are written in a high-level
level language (e.g., machine language or language. For example: Java, C++, etc.
assembly language), which gives the system
maximum compatibility for interacting with
computer hardware.

2|Page
System software are installed along with the Application software are third-party software
operating system. that can be downloaded and installed on the
computer according to the user’s requirement.
System software are general-purpose software Application software are specific-purpose
primarily used to operate a system with software primarily used to perform certain
computer hardware. tasks.
System software start running when we power Application software generally start when we
on a computer system and stop when the launch them to work, and stop when we
computer is powered off. They typically run in particularly close them. There is no need to
the background. turn off the computer system to end the
application software.
Programming of system software is Programming of application software is simple
comparatively complex and more importantly as compared to system software, because they
written for hardware compatibility, therefore, are designed for user-specific tasks, a user-
less or no user interaction is provided. interface is provided so that users can interact
and perform according to their work.
System software can run independently, Application software cannot run independently
meaning that they can also operate without and system software is required to run them.
application software. However, the system
cannot run without system software
The working of the system software is mostly User-action is required to operate the
automated. They start working on their own application software. They usually work
when the system is turned on. according to the commands given by the user.
System software are usually classified as a Application software are usually classified as
package program/software or customized client-server, time-sharing and resource
program. sharing.
System software are essential for the Application software are not so important for
functioning of the system. the effective function of the system.
Some common examples of the system Some common examples of the application
software include Windows Operating system, software include Photoshop software. MS
Android, complier, debugger, etc., Office, File downloader, media player, etc.

Features a Software must have:


The quality of a software product is determined by what it offers and how easily it can be used.
Software is judged by different people on different grounds. Customers, for instance, want software
that meets their specific needs. Similarly, developers engaged in designing, coding, and maintaining
the software determine the quality of the software by assessing its internal characteristics. Some of
the features are:

i. Functionality: The functionality of software refers to its ability to perform and function according
to design specifications. In simple terms, software systems should function correctly, i.e.,
perform all the functions for which they are designed. The functions refer to the features that
the end user, as well as the business, expect as basic facilities from the system. All these
functions must be integrated into the system. Many software applications out there are designed
for simplicity, but ultimately, the purpose of the software is to provide its users with the desired
functionality. In order to look like the best software product, it must have a clear appearance,
components, and functions. However, there are also those products out there that can provide a
great deal of value for your money.

3|Page
ii. Usability (User-friendly): The user-friendliness of the software is characterized by its ease of use.
In other words, learning how to use the software should require less effort or time. Navigating
the software is extremely important since it helps determine the journey the user takes within
the software. This is imperative to ensure visitors remain on your website and have a positive
experience, which leads to an increase in sales and brand loyalty. An important indicator of a
good piece of software is its user interface, i.e., the smooth flow of its design. A product with a
great UI (User Interface) design is more likely to get noticed than one without. If a software
program isn’t user-friendly, users may have trouble navigating the software and using some of its
features. Software should require less time or effort to learn. Ideally, software should be easy to
use even by people with no IT experience.
iii. Efficiency: Essentially, it refers to the software’s ability to utilize human and system resources
such as time, effort, CPU, memory, computation power, network bandwidth, files, databases,
etc., as effectively and efficiently as possible. For a software project to succeed, efficiency is
crucial. In addition to meeting the needs for which the software was made, it must also provide
excellent features designed to assist users in completing their tasks faster. Software should make
efficient use of storage space and execute commands according to timing requirements. In order
to be efficient, software must offer users proper value in terms of their time and cash. The
market is filled with products that cater to various industries, but only a handful of products are
efficient enough to benefit individuals and businesses. The medical billing software that Opens
Practice Solutions provides, for instance, makes billing processes much more efficient for clients
than those offered by other companies.
iv. Flexibility: Software Flexibility refers to the ability of the software solution to adapt to potential
or future changes in its requirements. When evaluating the flexibility of software, look at how
simple it is to add, modify, or remove features without interfering with the current operation. It
is essential to keep up with rapidly changing markets, technologies, and customer needs. In
software development, change is inevitable; it can arise during the development process itself or
as the result of future requirements. Flexibility is therefore highly valued. Consequently, any
software product must be scalable, flexible, and easily adaptable to future technology. When
designing or building a software product, be sure to plan for these changes that are inevitably
going to occur. Loose coupling of components is the key to creating highly flexible systems.
v. Reliability: The reliability of a software product describes the likelihood it will operate without
failure over a specified period of time under certain conditions. It determines the ability of
software to maintain its level of performance (provide desired functionality) under specified
conditions for a specified period of time. Generally speaking, software reliability is measured as
the availability of the software. The value should not be less than 99%. In reliability testing, the
goal is not perfection, but achieving a level of reliability that is acceptable before a software
product is released to customers. MTTF, MTTR, MTBR, etc., are some reliability metrics that can
be used to quantify the reliability of a software product. It is regarded as one of the most
important quality aspects of software quality, along with functionality, efficiency, maintainability,
etc. Since software tends to be complex, it is hard to achieve software reliability.
vi. Maintainability: Maintainability refers to how easily you can repair, improve and comprehend
software code. In some ways, maintaining is similar to being flexible. Maintainability deals with
the modification of errors and minor alterations to software code, while flexibility focuses on
major functional extensions. It also involves maintaining the services and functionality of the
software. Most of the time, developers are not the ones who maintain the software. Therefore,
good documentation is crucial, which includes code documentation, interface definitions, etc.
The maintainability of software products is affected by the quality of the documentation.
Typically, more than half of development budgets are spent on software maintenance.

4|Page
Maintenance should therefore be integrated into the development lifecycle for effective software
maintenance.
vii. Portability: Software portability is a critical factor that cannot be ignored. Portability refers to the
ability to use software in different environments. This is the ease with which software can be
ported from one platform to another without (or with minimal) changes, while obtaining similar
results. As simple as it may sound, it refers to the ability of software to work on different
hardware platforms without any (or little) modifications needed. Furthermore, you should be
aware that porting software to a new environment is comparatively cheaper than developing an
equivalent application from scratch. There can be no doubt that portability is a crucial aspect of
reducing development costs.
viii. Integrity: There are multiple interpretations of software integrity. Some people tend to associate
integrity with security, believing it is resistant to hacks and privacy violations. To others, high
integrity means that the software cannot be modified without authorization. Integrity is key for
demonstrating the safety, security, and maintainability of your software. In addition, software
that needs to be compliant with industry regulations and coding standards requires high code
integrity. Achieving software integrity can be difficult. Yet, with the right practices to improve
safety, security, and maintainability, the challenge can be easily overcome. In these days of
increased security threats, all software must include this factor.

Types or Levels of Programming Languages:


There are mainly two types of programming languages: High-level programing language and Low-
level programming languages.

1. Low-level Language:
Low-level language is a programming language in which each statement or instruction is directly
translated into a single machine code. It is machine dependent, i.e., a particular low-level language
works only for a certain machine. They are further divided into two types: Machine-level language
and Assembly language.

a. Machine Language: Machine language is a language that a computer actually understands. The
least possible level at which we can program a computer is in its own native machine code,
consisting of strings of 1’s and 0’s, and are stored as binary numbers. Thus, machine language is a
sequence of instructions written in the form of binary numbers consisting of 1’s and 0’s to which
the computer responds directly.
Advantage:
The CPU directly understands machine instructions, and hence no translation is required.
Therefore, the computer directly starts executing the machine language instructions, and it takes
less execution time.
Disadvantages:
➢ Difficult to use: As computer instructions are written in binary forms, it is hard to write,
understand and debug.
➢ Machine dependent: The code written for one processor may be incompatible for other. The
programmer has to remember machine characteristics while developing a program. As the
internal design of the computer is different across types, which in turn is determined by the
actual design or construction of the ALU, control unit and size of the word length of the memory
unit, the machine language also varies from one type of computer to another.
➢ Difficult to debug and modify: Checking machine instructions to determine errors are about
as tedious as writing the instructions. It is difficult to modify the program.

5|Page
b. Assembly Language: Assembly language is a symbolic representation (called mnemonics) of
machine code. They are close to machine code but the computer cannot understand them. The
assembly-language program must be translated into machine code by a separate program called
an assembler.
Advantages:
Writing a program in assembly language is more convenient than writing one in machine
language. Instead of binary sequence, as in machine language, a program in assembly language is
written in the form of symbolic instructions. This gives the assembly language program improved
readability.
Disadvantages:
➢ Hard to remember mnemonics: There are large numbers of mnemonics for a machine. It is
difficult to remember all the mnemonics for writing assembly program.
➢ Machine dependent: Assembly language is specific to particular machine architecture. Thus,
assembly language programs written for one processor will not work on a different processor
if it is architecturally different.
➢ Less efficient than machine language: The assembly language is to be translated into
machine language before execution. Thus, a program written in assembly language is less
efficient compared to an equivalent machine language program but more efficient than
equivalent high level language program.

2. High-level Language:
A high-level programming language is a programming language that is more user-friendly, to some
extent platform-independent and abstracts from low-level computer processor operations such as
memory access. They are similar to natural language (like English) and so are easy to write and
remember. They are easy to learn and work but while executing, they have to be translated into
assembly language and then to machine language so, it is slow in execution but is efficient for
developing programs.

Advantages:

➢ Easy to use: The statements in high level language are much more like English language. Thus,
they are easier to understand than those written in assembly and machine language.
➢ Portability: High level programming languages can be run on different machines with little or no
change. It is, therefore, possible to exchange software, leading to creation of program libraries.
➢ Easy debugging: Errors can be easily detected and removed.
➢ Easy and Fast development of software: Since the commands of these languages are close to the
English language, software can be developed with ease and fast.

Disadvantages:

➢ More execution time: As the program written in high level language cannot directly generate
executable code, it has to be translated into assembly language and then to machine language.
Thus, it takes more time for execution.
➢ Need own translator: To change high level language program into machine language, each
language has its own translator.

Language Processor:
Mostly, high-level languages like Java, C++, Python, and more are used to write the programs, called
source code, as it is very uninteresting work to write a computer program directly in machine code.
These source codes need to translate into machine language to be executed because they cannot be

6|Page
executed directly by the computer. Hence, a special translator system, a language processor, is used
to convert source code into machine language. A language processor is a special type of software
program that has the potential to translate the program codes into machine codes. Languages such
as COBOL and Fortran have language processors, which are generally used to perform tasks like
processing source code to object code. A specific description of syntax, lexicon, and semantics of a
high-level language is required to design a language processor. There are mainly three kinds of
language processors, which are discussed below:

1. Compiler: The language processor allows the computer to run and understand the program by
reading the complete source program in one time, which is written in a high-level language. The
computer can then interpret this code because it is translated into machine language. While
working on the Harvard Mark I computer, Grace Hopper created the first compiler. In modern
times, to compile the program, most of the high-level languages have toolkits or a compiler. GCC
command for C and C++ and Eclipse for Java are two popular compilers. It takes a few seconds or
minutes while compiling the program based on how big the program is.
2. Assembler: An assembler converts programs written in assembly language into machine code. It
is also referred to assembler as assembler language by some users. The source program has
assembly language instructions, which is an input of the assembler. The assemble translates this
source code into a code that is understandable by the computer, called object code or machine
code.
3. Interpreter: An interpreter is a computer program that allows a computer to interpret or
understand what tasks to perform. The programs written with the help of using one of the many
high-level programming languages are directly executed by an interpreter without previously
converting them to an object code or machine code, which is done line by line or statement by
statement. When the interpreter is translating the source code, it displays an error message if
there is an error in the statement and terminates this statement from translating process. When
the interpreter removed errors on the first line, then it moves on to the next line.

Difference between Compiler and Interpreter:


Compiler Interpreter
A compiler is a program that takes the complete The interpreter is different from the Compiler; it
program as a single unit and converts the entire takes a source program and translates it one by
source code into executable machine code for a one, and executes.
CPU.
The compiler is comparatively faster in order to As compare to the compiler, an interpreter is
the overall execution of the source code; slower in order to the overall execution of the
however, it takes a large amount of time to programming code, but it takes less time to
analyze to compile the complete programming evaluate the source code.
code.
When the compiler completes scanning the With an interpreter, until the error is met, it
whole program, then it generates the error continues converting the program; therefore, its
message. As the error can be found in any debugging is easier.
statement in the program; therefore, debugging
is comparatively hard with a compiler.
When you want to run the program, a When you want to run the program, a
translator program is needed each time to translator program is not needed each time to
convert the source code convert the source code.
It stores object code and is more beneficial for It does not hold object code, and it is more
commercial purposes. beneficial for learning purposes.

7|Page
Examples: C, C++, Java, FORTRAN compiler, Examples: Python, Perl, APL, Prolog interpreter,
PASCAL compiler. etc.

Problem Solving Using Computer:


There are a number of steps/stages while solving a problem using computer. They are explained
below:

1. Problem Analysis: This step is the processing of becoming familiar with the problems that will be
solved with a computer program. Before solving a problem, it should be analyzed and
understood well. The program’s inputs, outputs, different ways of solving problems, its
constraints, software & hardware requirements, available time period, required accuracy of the
program should be known in advance well.
2. Algorithm Development: An algorithm is step by step description of the method to solve a
program. It is effective procedure for solving a problem in a finite number of steps. Algorithm
maintains sequences of computer instructions requited to solve a problem in such a way that if
the instructions are executed in the specified sequence, the desired result is obtained.

Advantages of Algorithms:
➢ It is a step-wise representation of a solution to a given problem, which makes it easy to
understand
➢ An algorithm uses a definite procedure.
➢ It is not dependent on any programming language, so it is easy to understand for anyone
even without programming knowledge.
➢ Every step in an algorithm has its own logical sequence so it is easy to debug.
➢ By using algorithm, the problem is broken down into smaller pieces or steps hence, it is
easier for programmer to convert it into an actual program.
Some conventions used in developing algorithms:
➢ Each algorithm will be enclosed by two statements START and STOP.
➢ To accept data from user, the INPUT or READ statement is used.
➢ To display any user message, the PRINT or DISPLAY statement is used.
➢ The arithmetic operators (+, -, * and /) are used in the expressions.
➢ The relational operators (>, >=, <, <=, ==, !=) are used in conditions.
➢ The logical operators (AND, OR, NOT) are used for logical expression.
3. Flowcharting: Flowchart is the graphical representation of an algorithm using standard symbols.
In other words, flowchart is a pictorial representation of an algorithm that uses boxes of different
shapes to denote different type of instruction.
Advantages of Flowchart:
➢ Communication: Flowcharts are a better way of communications. They quickly and clearly
provide logic, ideas and description of algorithms to other programmers, students, teachers,
computer operator and users.
➢ Effective Analysis: Flowcharts provide a clear overview of the entire problem and its
algorithm for solution. They show all major elements and their relationships. Thus, with the
help of flowcharts, problems can be analyzed more effectively.
➢ Proper Documentation: The flowchart provides a permanent recording of program logic. It
documents the steps followed in an algorithm. A comprehensive, carefully drawn flowchart is
an indispensable part of documentation for each program and it helps to understand the
program and its logic in future when required.

8|Page
➢ Efficient Coding: Flowcharts show all major parts of a program. A programmer can code the
programming instructions in a computer language with more ease with a comprehensive
flowchart as a guide. The flowchart specifies all the steps to be coded and helps to prevent
omissions or errors. Thus, a flowchart acts as a guide or blueprint during the system analysis
and program development phase.
➢ Easy is debugging and program maintenance: Flowcharts help in the debugging process and
maintenance of operating program.

Limitations of Using Flowchart:

➢ Complex Logic: A flowchart becomes complex and clumsy when the program logic is quite
complicated.
➢ Difficult in alteration and modifications: If alterations are required; the flowchart may need
to be redrawn completely.

Flowchart Symbols:

Flowchart Symbol Name Meaning


Flow line Used to connect flow chart
symbols and the direction
indicates the flow of logic.
Terminal (Start or End) Used to represent the
beginning (Start) or the end
of a task.
Processing Used for arithmetic and data-
manipulations operations.
The instructions are written
inside the symbol.
Input/ Output Used for input (reading data)
and output (displaying data)
operations. The data to be
read or displayed are written
inside the symbol.
Decision Used for a decision making
and branching operation that
has two alternatives (true and
false or yes and no).
Connector Used to join different
flowlines and to connect
remote parts of the flowchart
on the same page.
Some Guidelines in flowcharting:

➢ Flowcharts should be started on the top of the page and flow down and to the right.
➢ Only standard flowcharting symbols should be used.
➢ There should be start and stop to the flowchart.
➢ The flowchart should be clear, neat, and easy to follow. There should be no ambiguity in
understanding the flowchart.
➢ The direction of flow line of a procedure or system should be from left to right or top to
bottom.
➢ Only one flow line should emerge from a process symbol.

9|Page
➢ Only one flow line should enter a decision symbol, but tow or three flow lines, one for each
possible answer can leave the decision symbol.
➢ Only one flow line is used in conjunction with a terminal (Start and Stop) symbol.
➢ The contents of each symbol should be written legibly. English should be used in flow charts,
not specific programming language.
➢ If the flowchart becomes complex, connector symbols should be used to reduce the number
of flow lines. The intersection of flow lines should be avoided to make the flow chart a more
effective and better way of communication.
4. Coding: The coding is the process of transforming the program logic design into a computer
language format. This stage translates the program design into computer instructions using some
programming languages like c, c++, java, etc. The code written using programming language is
also known as source code.
5. Compilation and Execution: The process of changing high level language into machine level
language is known as compilation. It is done by special software, known as compiler. The
compilation process tests the program whether it contains syntax errors or not. If syntax errors
are present, compiler cannot compile the code. Once the compilation is completed then the
program is linked with object programs needed for execution, thereby resulting in a binary
program and then the program is loaded in the memory for the purpose of execution and finally
it is executed.
6. Debugging & Testing: Debugging is the discovery and correction of programming errors. The
errors may appear during compilation or linking or execution of the program. When the error is
appeared, the debugging is necessary. Testing ensures that program performs correctly the
required task. It is the verification and validation of the program, where verification ensures that
the program does what the program intends to do and validation ensures that the program
produces the correct results for a set of test data.
Errors that may occur during debugging: There are five different types of errors in C. They are
listed below:
➢ Syntax Error: Syntax errors occur when a programmer makes mistakes in typing the code’s
syntax correctly or makes typos. In other words, syntax errors occur when a programmer
does not follow the set of rules defined for the syntax of C language. Syntax errors are
sometimes also called compilation errors because they are always detected by the compiler.
Generally, these errors can be easily identified and rectified by programmers. The most
commonly occurring syntax errors in C language are: missing semi-colon, missing
parenthesis, assigning value to a variable without declaring it, etc.
➢ Runtime Error: Errors that occur during the execution (or running) of a program are called
Run Time errors. These errors occur after the program has been compiled successfully. When
a program is running, and it is not able to perform any particular operation, it means that we
have encountered a run time error. For example, while a certain program is running, if it
encounters the square root of -1 in the code, the program will not be able to generate an
output because calculating the square root of -1 is not possible. Hence, the program will
produce an error. Runtime errors can be a little tricky to identify because the compiler
cannot detect these errors. They can only be identified once the program is running. Some of
the most common run time errors are: number not divisible by zero, array index out of
bounds, etc.
➢ Logical Error: Sometimes, we don’t get the output we expected after the compilation and
execution of a program. Even though the code seems error free, the output generated is
different from the expected one. These types of errors are called Logical Errors. Logical errors
are those errors in which we think that our code is correct, the code compiles without any

10 | P a g e
error and gives no error while it is running, but the output we get is different from the
output we expected.
➢ Semantic Error: Errors that occurs because the compiler is unable to understand the written
code are called Semantic Errors. A semantic error will be generated if the code makes no
sense to the compiler, even though it is syntactically correct. It is like using the wrong word in
the wrong place in the English language. Semantic errors are different from syntax errors, as
syntax errors signify that the structure of a program is incorrect without considering its
meaning. On the other hand, semantic errors signify the incorrect implementation of a
program by considering the meaning of the program. The most commonly occurring
semantic errors are: use of un-initialized variables, type compatibility, and array index out of
bounds.
➢ Linker Error: Linker is a program that takes the object files generated by the compiler and
combines then into a single executable file. Linker errors are the errors encountered when
the executable file of the code cannot be generated even though the code gets compiled
successfully. This error is generated when a different object file is unable to link with the
main object file. We can run into a linked error if we have imported an incorrect header file
in the code, we have a wrong function declaration, etc.

7. Program Documentation: Program documentation is description of the program and its logic
written to support understanding the program. Documentation of program helps to those who
use, maintain and extend the program in future. A program may be difficult to understand even
to the programmer who wrote the code after some days. If a program coded by one person is to
be maintained and extended by other person, there will be more difficulty to understand.
Properly documented program is necessary which will be useful and efficient in debugging,
testing, maintenance and redesign process.

Difference between Source Code and Object Code:


Source Code Object Code
Source code is generated by human or Object code is generated by compiler or other
programmer. translator.
Source code is written in plain text by using Object code is translated code of source code.
some high-level programming language. It is in binary format.
Source code is not directly understandable by Object code is machine understandable and
machine. executable.
It can be changed over time. Source code needs to be compiled or
translated by any other translator to get
modified object code.
Performance of source code is less than object Performance of object code is more than
code as it is less close towards machine. source code as it is closer towards machine

Importance/ Advantages of C:
➢ Robust Language: C is a robust language whose rich set of built-in functions and operators can be
used to write any complex program. The C compiler combines the capabilities of an assembly
language with the features of a high-level language. Therefore, it is well suited for writing both
system and application packages.
➢ Efficient and fast: Programs written in C are efficient and fast due to its variety of data types and
powerful operators.

11 | P a g e
➢ Highly portable: C is a structured language as it has a fixed structure. A C program can be divided
into a number of modules or blocks. A proper collection of these modules would make a
complete program. Due to the structured program, debugging, testing and maintenance is easier
and fast.
➢ Extendibility: A C program may contain a number of user defined functions. We can add our own
user defined functions to the C Library if required.
➢ Middle Level Language: C is a middle level language because it combines the best part of high-
level language with low-level language. It is well suited for writing both user and machine-
oriented programs and provides infinite possibilities.
➢ Rich System Library: There are large numbers of built in functions, keywords and operators in C’s
System library organized in different header files. Using built-in functions, we can save our effort
and reduce the size of the program.

Executing a C Program/Compilation Phases:


1. Writing the source code: Computer instructions are written in a text editor to perform certain
jobs. The instructions are written using correct syntax of the language we are using. The
computer instructions written using the syntax of C is known as the source code of C program.
This source code can be written using any text editor such as Notepad or Turbo C. However, it
should be saved with .c extension.
2. Compilation and Linking the program: The computer instructions written in the form of source
code are translated into a form that is suitable for execution by the computer. The translation is
done by a special program called compiler that processes statements written in programming
language and converts them into a machine language or code that a computer’s processor uses.
So, compiling generally means creating an executable file for a particular platform. During
compilation linking process also takes place. Linking is the process of putting translated program
and other object programs needed by the program together. The program is using C’s system
library for common tasks such as reading input, producing output and computing mathematical
functions. In some cases, the program may be using a separately compiled subprograms or
functions for some user defined functions. To create an executable program, the object program
must be linked to the library subprogram or separately compiled user defined subprogram. For
example, if program is using printf () function to output data on the screen, then the object code
of this function should be brought from the stdio system library and linked to the main program.
3. Executing the program: Executing the program loads the created executable object code into the
computer memory and executes the instruction. During execution, the program may require
some data to be entered through the keyboard.

12 | P a g e
Figure: Process of compiling and running a C program.

Basic Structure of C Program:


Documentation Section
Link Section
Definition Section
Global Declaration Section
main ( ) Function Section
{


}
Subprogram Section
{


}
1. Documentation Section: This section contains a set of comment lines giving the name of
program, the author, algorithms, methods used and other details. This will be useful in future for
users and developing teams. The documentation acts as a communication medium between

13 | P a g e
members of the development team when a number of developers are working in the same
project. It is used by maintenance engineers to update and upgrade the system in future. It helps
while debugging and testing the program. It tells users “How to use and administer the system”.
It acts as user manual.
For example, the title of a program can be written in this section as,
/* This program displays natural numbers from 1 to 10*/

2. Link Section: This section provides instruction to the compiler to link functions with program
from the system library. For example, the statement #include <stdio.h> links input/output
functions like printf ( ) and scanf ( ) with the program.
3. Definition Section: In this section, all symbolic constants are defined.
#define PI 3.14
4. Global Declaration Section: The variables which are used in more than one functions or blocks
are called global variables. These variables are defined or declared in this section. This section
also declares all the user-defined functions.
5. main ( ) Function Section: Every C program starts with a main ( ) function. Within main ( )
function, there are declaration and executable parts. The declaration part declares all the
variables used in the execution part.
6. Subprogram Section: This section contains all the user-defined functions that are called in the
main function. All the sections except the main ( ) function section may be absent when they are
not required.

Function of semicolon in C programming


➢ Semicolons are end statements in C.
➢ The Semicolon tells that the current statement has been terminated and other statements
following are new statements.
➢ Usage of Semicolon in C will remove ambiguity and confusion while looking at the code.
➢ They are not used in between the control flow statements but are used in separating the
conditions in looping.

Keywords:
Keywords are predefined words for a C programming language. All keywords have fixed meaning and
these meanings cannot be changed. They serve as basic building blocks for program statements.
ANSI C keywords are listed below:

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue signed void for
default goto sizeof volatile
do if static while
These keywords are used for pre-defined purposes and cannot be used as identifiers. Thus, keywords
are also called reserved words.

14 | P a g e
Identifiers:
Every word used in C program to identify the name of variables, functions, arrays, pointers and
symbolic constants are known as identifiers. They are names given by the user and consist of a
sequence of letters and digits, with a letter as the first character. The underscore character can be
used to link between two words in long identifiers. The rules for naming identifiers are:

➢ It must be a combination of letters and digits and must begin with a letter or an underscore.
➢ White space is not allowed but underscore is permitted between two words.
➢ Only first 31 characters are significant.
➢ Keywords cannot be used.
➢ It is case sensitive, i.e., uppercase and lowercase letters are not interchangeable.

Data Types:
There are three classes of data types:

1. Primary (or fundamental) data types: Primary data types are categorized into five types:
a. Integer Types: Integers are whole numbers, i.e., non-fractional numbers. Generally, integers
require 16 bits of storage. C has further three classes of integer – integer (int), short integer
(short int) and long integer (longs int), in both signed and unsigned forms.
The difference between signed integer and unsigned integer are:
Signed Integer (signed int) Unsigned Integer (unsigned int)
➢ It represents both positive and negative ➢ It represents only positive integers.
integers.
➢ The data type qualifier is signed int or int. ➢ The data type qualifier is unsigned int or
Variables are defined as – unsigned. Variables are defined as –
signed int a; unsigned int a;
int b; unsigned b;
➢ By default, all int are signed. ➢ Unsigned int have to be declared explicitly.
➢ It reserves 16 bits (2 bytes) in memory. ➢ It reserves 16 bits (2 bytes) in memory.
➢ It represents integer values of the range -215 ➢ It represents integer values of the range 0
to +215-1, i.e., -32,768 to +32,767. to +216-1, i.e., 0 to +65,535.
➢ Its conversion character is d. ➢ Its conversion character is u.
The difference between signed and unsigned short integers are:
Signed Short Integer (signed short int) Unsigned Short Integer (unsigned short int)
➢ It represents both positive and negative ➢ It represents only positive integers.
integers.
➢ The data type qualifier is signed short int or ➢ The data type qualifier is unsigned short int
short. Variables are defined as – or unsigned short. Variables are defined as
signed short int a; unsigned short int a;
short int b; unsigned short b;
short c;
➢ By default, all short int are signed. ➢ Unsigned short int have to be declared
explicitly.
➢ It reserves 16 bits (2 bytes) in memory. ➢ It reserves 16 bits (2 bytes) in memory.
➢ It represents integer values of the range -215 ➢ It represents integer values of the range 0
to +215-1, i.e., -32,768 to +32,767. to +216-1, i.e., 0 to +65,535.
➢ Its conversion character is d or i. ➢ Its conversion character is u.
The difference between signed and unsigned long integers are:

15 | P a g e
Signed Long Integer (signed long int) Unsigned Long Integer (unsigned long int)
➢ It represents both positive and negative ➢ It represents only positive integers.
integers.
➢ The data type qualifier is signed long int or ➢ The data type qualifier is unsigned long int
long int or long. Variables are defined as – or unsigned long. Variables are defined as
signed long int a; unsigned long int a;
long int b; unsigned long b;
long c;
➢ By default, all long int are signed. ➢ Unsigned long int have to be declared
explicitly.
➢ It reserves 32 bits (4 bytes) in memory. ➢ It reserves 32 bits (4 bytes) in memory.
➢ It represents integer values of the range -231 ➢ It represents integer values of the range 0
to +231-1, i.e., -2,147,483,648 to to +232-1, i.e., 0 to +4,294,967,295.
+2,147,483,647.
➢ Its conversion character is ld. ➢ Its conversion character is lu.
b. Floating Point Type: Floating point types are fractional numbers (i.e., real numbers). They are
defined in C by the keyword float.
➢ Floating numbers reserve 32 bits (4 bytes) of storage, with 6 digits of precision.
➢ It represents fractional number of the range -3.4×10-38 to +3.4×10-38.
➢ The data type qualifier is float. Variables are defined as - float a;
➢ Its conversion character is f.
c. Double-Precision Floating Point Type: When the accuracy provide by a float number is not
sufficient, the type double can be used to define the number.
The difference between Double Precision and Long Double Precision are:
Double Precision (double) Long Double Precision (long double)
➢ The data type qualifier is double. Variables ➢ The data type qualifier is long double.
are defined as - Variables are defined as -
double a; long double a;
➢ It represents fractional number of the range ➢ It represents fractional number of the range
1.7×10-308 to 1.7×10+308. 1.7×10-4932 to 1.7×10+4932.
➢ It reserves 8 bytes in memory. ➢ It reserves 10 bytes in memory.
➢ Its conversion character is lf. ➢ Its conversion character is Lf.
d. Character Type: A single character can be defined as a character type data. Character is stored in
8 bits (1 byte). The qualifier is char. The qualifier signed or unsigned may be used with char. The
unsigned char has values between 0 and 255. The signed char has values from -128 to 127. The
conversion character for this type is c. In character type each character is represented by an ASCII
(American Standard Code for Information Interchange) number internally. For example, the
character ‘A’ is represented by 65, ‘B’ by 66 and so on for ‘Z’ by 90. Similarly, lowercase letter ‘a’
is represented by 97, ‘b’ by 98 and so on for ‘z’ by 90. Thus, when a character is displayed using
the conversion character d, it will display the ASCII value; and when it is displayed using
conversion character c, it will display the character.
e. Void Type: The void type has no values. This is usually used to specify a type of function when it
does not return any value to the calling function.

2. User-Defined Data Types: C supports a feature called type definition which allows users to define
an identifier that would represent and existing data type. The typedef statement is used to give
new name to an existing data type. It takes the general form –
typedef existing_data_type new_name_for_existing_data_type;

16 | P a g e
Constants
A constant is a quantity that doesn’t change during the execution of a program. C constants can be
divided into different categories:

➢ Numeric Constant.
➢ Character Constant.

Variables
A variable is a symbolic name which is used to store data item, i.e., a numerical quantity or c
character constant. Variables are defined in a computer program to represent an item of data input
by the user, any intermediate calculations or the end results. Unlike a constant, the value of variable
can change during the execution of a program. The same variables can store different value at
different portion of a program. Variables name may consist of letters, digits or underscore characters.
Since a variable is an identifier, the rule for naming variables is similar to those of identifiers.
Variables can be declared as constants by using the “const” keyword before the datatype of the
variable. Example: const int a-10; The constant variables can be initialized once only. The default
value of constant variables is zero.

Variable Declaration:

The declaration of a variable provides information to the compiler about the variable type and the
name. In other words, this information indicates the compiler of the existing variable. Therefore, the
compiler can proceed further compilation without all the details about the variable. Variable
declaration is useful when the programmer uses multiple files and when he defines the variables in
one of the files. They are available when linking the program. We can use the “extern” keyword to
declare a variable in any place. Even though it is possible to declare a variable multiple times in a C
program, it is only possible to define it only once such as in a file or a function.
#include <stdio.h>
extern int num1, num2, result; //Variable declaration
int main ()
{
int num1, num2, result;
num1=5;
num2=7;
result=num1 + num2;
printf (“Result: %d \n”, result);
return 0;
}
Variable Definition:
The definition of a variable indicates the compiler where and how much storage to create for the
variable. A variable definition defines the data type and a set of one or more variables of that type.
Below is an example of a declaration.

17 | P a g e
int a, b;
It declares and defines the variables a and b. It tells the compiler to create two integer variables called
a and b.
Initialization is the process of assigning initial values to the variables. It is also possible to initialize
values to the variables in the declaration. An example is as follows.
int a= 3, b=3;

Preprocessor Directives
Preprocessor directive is a collection of special statements that are executed at the beginning of a
compilation process. They are placed in the source program before the main function. Before a
source code passes through the compiler, it is examined by the preprocessor for any preprocessor
directives. If there are any, appropriate actions are taken and then the source program is handed
over to the compiler. Preprocessor directives follow special syntax rules that are different from
normal C syntax. They all begin with the symbol # (hash) and do not require a semicolon at the end.
The directives are of four types- macro expansion, file inclusion, conditional compilation, and other
miscellaneous directives.

Macro Expansion: The macro in C language is known as the piece of code which can be replace by
the macro value. The macro is defined with the help of #define preprocessor directive and the macro
doesn’t end with a semicolon. Macro is just a name given to certain values or expression it doesn’t
point to any memory location. Whenever the compiler encounters the macro, it replaces the macro
name with the macro value. Two macros cannot have the same name. The syntax of macro is:

#define pi 3.14

Where, #define is preprocessor directive, pi is macro name and 3.14 is macro value.

File Inclusion: #include is a way of including a standard or user-defined file in the program and is
mostly written at the beginning of any C program. This directive is read by the preprocessor and
orders it to insert the content of a user-defined or system header file into the following program.
These files are mainly imported from an outside source into the current program. The process of
importing such files that might be system-defined or user-defined is known as File Inclusion. This
type of preprocessor directive tells the compiler to include a file in the source code program.
Example: #include <stdio.h>

Tokens In C
The basic elements recognized by the C compiler are the tokens. A token is source-program text that
the compiler does not break into component elements. The keywords, identifiers, constants, string
literals, operators and special symbols: brackets [ ], braces { }, parentheses ( ), and commas (,) are
examples of tokens.

Operators
An operator is a symbol that operates on a certain data type or data item. Operators are used in
programs to perform certain mathematical or logical manipulations. For example, in a simple
expression 8+9, the symbol ‘+’ is called an operator which operates on two data items 8 and 9. The
data that operators act upon are called operands. Here, 8 and 9 are operands. An expression is a
combination of variables, constants and operators written according to syntax of the language.

18 | P a g e
According to the number of operands required for an operator, we can classify operators into unary,
binary and ternary operators.

1. Unary operators: The operators which require only one operand are known as unary operators.
For example, ++ (increment operator), --(decrement operator), - (unary minus), and + (unary
plus) are unary operators.
2. Binary Operators: The operators which require two operators are known as binary operators. For
example, + (plus), - (minus), * (multiply), / (division), < (less than), > (greater than), etc.
3. Ternary Operators: The operators that require three operands are known as ternary operators.
For example, the operator pair “?:” (conditional operator) is a ternary operator.

According to the utility and action, operators are classified into various categories-
i. Arithmetic Operators: The operators that performs arithmetic operations are arithmetic
operators. There are five arithmetic operators in C. The +, -, * and / all work in the same way as
in usual mathematics. The modulo operator (%) calculates remainder after division of one integer
operand by another operand.
ii. Relational Operators: Relational operators are used to compare two similar operands, and
depending on their relation, take some actions. Relational operators compare their left-hand side
operand with their right-hand side operand. C supports six relational operators they are: lesser
than (<), greater than (>), lesser than or equal to (<=), greater than or equal to (>=), equal to (==)
and not equal to (!=) relations. The value of a relational expression is either 1 (If condition is true)
or 0 (if condition is false).
iii. Logical Operators: Logical operators are used to compare or evaluate logical and relational
expressions. The operands of these operators must produce either 1 (true) or 0 (false). The
whole result produced by these operators is also either true or false. There are three logical
operators in C- logical AND (&&), logical OR (||) and logical NOT (!).
iv. Assignment Operators: Assignment operators are used to assign the result of an expression to a
variable. The usual assignment operator is ‘=’. There are other various shorthand assignment
operators also. They are +=, -=, *=, /= and %=. The use of shorthand operators makes a
statement more concise and easier to read. The operand or expression on the left-hand side
need not be repeated. The general form of shorthand assignment operators for the operations,
exp1=exp1 opr exp2 is, exp1 opr = exp. Example; a += b is equivalent to a=a+b, which means add
a and b and assign result to a.
v. Increment And Decrement Operators: The increment operator is used to increase the value of
an operand by 1; and the decrement operator is used to decrease the value of an operand by 1.
They take only one operand, so called unary operator. Increment and decrement operators can
be used as postfix or prefix notations. The increment and decrement operators in the form of ++a
and --a is known as prefix notation. In prefix notation, the value of variable is first incremented or
decremented and then the value is used. Similarly, the increment and decrement operators in
the form of a++ and a—are known as postfix notation. In postfix notation, first the previous value
of variable is used and then the value of variable is incremented or decremented.
vi. Conditional Operators: The operator pair “? :” is known as conditional operator. It takes three
operands. So, it is also called ternary operator. The syntax for this operator is-
expression1 ? expression2 : expression3
Here, expression1 is evaluated first. If expression1 is true, the value of expression2 is the value of
conditional expression. If expression1 is false, the value of expression3 is the value of conditional
expression.

19 | P a g e
vii. Bitwise Operators: Bitwise operators are used for manipulating data at bit level. These operators
are used for testing the bits, or shifting them to the left or to the right. Bitwise operators can be
applied only to integer-type operands and not to float or double. There are three types of bitwise
operators-
➢ Bitwise Logical Operators: Bitwise logical operators perform logical test between two
integer-type operands. These operators work on their operands bit-by-bit starting from the
least significant (i.e., the rightmost) bit. There are three logical bitwise operators-
Bitwise AND (&): The bitwise AND performs logical ANDing between two operands. The
result of ANDing operation is 1 if both the bits have a value of 1; otherwise, it is 0.
Bitwise OR (|): The bitwise OR performs logical ORing between two operands. The result of
ORing operation is 1 if either of the bits have a value of 1; otherwise, it is 0.
Bitwise Exclusive XOR (^): The result of Exclusive ORing operation is 1 only if one of the bits
have a value of 1; otherwise, it is 0.
➢ Bitwise Shift Operators: Bitwise shift operators are used to move bit patterns either to the
left or to the right. There are two bitwise shift operators:
Left Shift (<<): The left-shift operation causes the operand to be shifted to the left by some
bit positions. The general form of left-shift operation is – operand << n
The bits in the operand are shifted to the left by n positions. The leftmost n bits in the
original bit pattern will be lost and the rightmost n bits empty positions will be filled with 0s.
Right Shift (>>): The right-shift operation causes the operand to be shifted to the right by
some bit positions. The general form of right-shift operation is – operand >> n
The bits in the operand are shifted to the right by n positions. The rightmost n bits in the
original bit pattern will be lost. The empty leftmost n bits position will be filled with 0s, if the
operand is an unsigned integer. If the operand is signed, then the operation is machine
dependent.
➢ Bitwise One’s Complement Operator (~): Bitwise one’s complement operator is a unary
operator which inverts all the bits represented by its operand. This means that all 0s become
1s and all 1s become 0s.

viii. Special Operators: C supports some special operators such as comma operator (,), sizeof
operator, pointer operators (& and *) and member selection operators (. and ->).

Operator Precedence and Associativity


Each operator in C has a precedence related with it. This precedence is used to determine how an
expression involving more than one operator is evaluated. There are distinct levels of precedence
and an operator may belong to one of these levels. The operators at the higher level of precedence
are evaluated first. The operators of the same precedence are evaluated either from ‘left to right’ or
from ‘right to left’, depending on the level. This is known as associativity property of an operator. The
table below provides a complete list of operators according to their precedence level, and their rules
of associativity. The groups are listed in the order of decreasing precedence. Precedence level 1
indicates highest precedence level and 15 the lowest.

Precedence Level Operator Description Associativity


1 () Function call Left to right
[] Array element reference
2 + Unary plus Right to left
- Unary minus
++ Increment

20 | P a g e
-- Decrement
! Logical negation
~ Ones complement
* Pointer reference
& Address
Sizeof Size of an object
(type) Type cast
3 * Multiplication Left to right
/ Division
% Modulus
4 + Addition Left to right
- Subtraction
5 << Left shift Left to right
>> Right shift
6 < Less than Left to right
<= Less than or equal to
> Greater than
>= Greater than or equal to
7 == Equal to Left to right
!= Not equal to
8 & Bitwise AND Left to right
9 ^ Bitwise XOR Left to right
10 | Bitwise OR Left to right
11 && Logical AND Left to right
12 || Logical OR Left to right
13 ?: Conditional expression Right to left
14 = Assignment operators Right to left
*= /= %=
+= -= &=
^= |=
<<= >>=
15 , Comma operator Left to right

Expression
Expressions are the combination of variables, operands, and operators. The result would be stored in
the variable once the expressions are processed based on the operator's precedence.

Type Conversions in Expressions


C allows mixing of constants and variables of different types in an expression. In these situations, one
type must be converted to another before evaluation can be done. This kind of conversion is called
type conversion, which may occur implicitly or explicitly.

1. Implicit Type Conversion: When there are constants and variables of different types in an
expression, C automatically converts any intermediate values to the proper type. This conversion
assures that the expression can be evaluated without losing any significance. This automatic
conversion is known as implicit type conversion. During evaluation if operands are of different
types, the ‘lower’ type is automatically converted into the ‘higher’ type before the operation
proceeds. The result is of the higher type. The conversion takes place according to a rule called
the conversion hierarchy.

21 | P a g e
long double
double
float
unsigned long int
long int
unsigned int
int
short char
2. Explicit Type Conversion: Instances where the type can be converted forcibly by the user himself
is called explicit type conversion or casting a value. The general form of a cast is-
(type_name) expression. Here type_name is one of the standard C data types. The expression
may be a constant, variable or an expression.

22 | P a g e

You might also like