0% found this document useful (0 votes)
47 views9 pages

CPC Imp Questions

The compilation process converts source code into executable machine code in multiple steps. It involves preprocessing, compiling, assembling, and linking. Preprocessing expands source code. Compiling converts it to assembly code. Assembling converts assembly code to object code. Linking combines object code with library code to create the executable file.

Uploaded by

sayyedzuber5anas
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)
47 views9 pages

CPC Imp Questions

The compilation process converts source code into executable machine code in multiple steps. It involves preprocessing, compiling, assembling, and linking. Preprocessing expands source code. Compiling converts it to assembly code. Assembling converts assembly code to object code. Linking combines object code with library code to create the executable file.

Uploaded by

sayyedzuber5anas
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/ 9

Q1.What is an algorithm.

Describe the characteristics of an algorithm

Algorithm

An algorithm is a properly defined sequence of steps or commands designed to


clear up a selected problem or perform a selected task. It is a scientific method
to problem-fixing that outlines the important movements or operations to be
accomplished in a clean and unambiguous manner. Algorithms can be
expressed in various bureaucracy, along with natural language, pseudocode,
flowcharts, or programming languages.

.Characteristics of algorithms:

1. Well-described steps: Algorithms are composed of a specific and


unambiguous set of instructions or steps that can be observed to perform
a selected task or solve a problem. Each step ought to be well-defined,
leaving no room for ambiguity or confusion.
2. Input and output: Algorithms take inputs, which might be the
preliminary records or facts furnished to the algorithm, and produce
outputs, which are the results or solutions generated by using the set of
rules after processing the inputs. The relation among the inputs and
outputs is decided by means of the algorithm's good judgment.
3. Finiteness: Algorithms must have a well-defined termination condition.
This method means that they finally attain an endpoint or change after a
finite quantity of steps. If a set of rules runs indefinitely without
termination, it's far taken into consideration wrong or incomplete.
4. Determinism: Algorithms are deterministic, that means that given the
same inputs and achieved below the same conditions, they may
continually produce the identical outputs. The conduct of a set of rules
ought to be predictable and regular.
5. Efficiency: Algorithms attempt to be efficient in phrases of time and
sources. They goal to clear up issues or perform obligations in an
inexpensive quantity of time and with ultimate use of computational
sources like memory, processing power, or garage.
6. Generality: A set of rules must be designed to resolve a particular
problem or carry out a selected assignment, but it must also be relevant to
a broader elegance of times or scenarios. It ought to have a certain level
of flexibleness and flexibility.
7. Correctness: Algorithms must be designed to produce correct results for
all legitimate inputs inside their domain. They must accurately solve the
problem they may be designed for, and their outputs must match the
anticipated consequences.
8. Modularity and reusability: Algorithms may be modular, meaning they
may be divided into smaller subproblems or features that may be reused
in unique parts of the algorithm or in other algorithms. This promotes
code agency, maintainability, and code reuse.
9. Understandability: Algorithms need to be designed with clarity and ease
in mind, making them easy to apprehend and implement. Well-
documented and readable code can enhance the understandability of an
algorithm.

Q.2. What is Compiler and interpreter. Differenciate between


these two.
Interpreter Compiler

Scans the entire program and translates it as a whole


Translates program one statement at a time.
into machine code.

Interpreters usually take less amount of time to analyze Compilers usually take a large amount of time to
the source code. However, the overall execution time is analyze the source code. However, the overall execution
comparatively slower than compilers. time is comparatively faster than interpreters.

No Object Code is generated, hence are memory Generates Object Code which further requires linking,
efficient. hence requires more memory.

Programming languages like JavaScript, Python, Ruby


Programming languages like C, C++, Java use compilers.
use interpreters.

Q.3.What is a Flowchart .Describe different symbols of Flowchart.

Flowchart is a diagrammatic representation of sequence of logical steps of a program.


Flowcharts use simple geometric shapes to depict processes and arrows to show relationships
and process/data flow.

Flowchart Symbols

Here is a chart for some of the common symbols used in drawing flowcharts.

Symbol Symbol Name Purpose

Used at the beginning and end of the algorithm to


Start/Stop
show start and end of the program.

Process Indicates processes like mathematical operations.


Input/ Output Used for denoting program inputs and outputs.

Stands for decision statements in a program,


Decision
where answer is usually Yes or No.

Arrow Shows relationships between different shapes.

Connects two or more parts of a flowchart, which


On-page Connector
are on the same page.

Connects two parts of a flowchart which are


Off-page Connector
spread over different pages.

Guidelines for Developing Flowcharts

These are some points to keep in mind while developing a flowchart −

 Flowchart can have only one start and one stop symbol
 On-page connectors are referenced using numbers
 Off-page connectors are referenced using alphabets
 General flow of processes is top to bottom or left to right
 Arrows should not cross each other

Here is a flowchart to calculate the average of two numbers.


Q.4. What is the compilation process.Explain with neat diagram.
he compilation is a process of converting the source code into object code. It is done with the
help of the compiler. The compiler checks the source code for the syntactical or structural
errors, and if the source code is error-free, then it generates the object code.

The c compilation process converts the source code taken as input into the object code or
machine code. The compilation process can be divided into four steps, i.e., Pre-processing,
Compiling, Assembling, and Linking.
The preprocessor takes the source code as an input, and it removes all the comments from the
source code. The preprocessor takes the preprocessor directive and interprets it. For example,
if <stdio.h>, the directive is available in the program, then the preprocessor interprets the
directive and replace this directive with the content of the 'stdio.h' file.

The following are the phases through which our program passes before being transformed
into an executable form:

ADVERTISEMENT

o Preprocessor
o Compiler
o Assembler
o Linker

Preprocessor

The source code is the code which is written in a text editor and the source code file is given
an extension ".c". This source code is first passed to the preprocessor, and then the
preprocessor expands this code. After expanding the code, the expanded code is passed to the
compiler.

Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler
converts this code into assembly code. Or we can say that the C compiler converts the pre-
processed code into assembly code.

Assembler

The assembly code is converted into object code by using an assembler. The name of the
object file generated by the assembler is the same as the source file. The extension of the
object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file
is 'hello.c', then the name of the object file would be 'hello.obj'.

Linker

Mainly, all the programs written in C use library functions. These library functions are pre-
compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The
main working of the linker is to combine the object code of library files with the object code
of our program.
In the above flow diagram, the following steps are taken to execute a program:

o Firstly, the input file, i.e., hello.c, is passed to the preprocessor, and the preprocessor
converts the source code into expanded source code. The extension of the expanded
source code would be hello.i.
o The expanded source code is passed to the compiler, and the compiler converts this
expanded source code into assembly code. The extension of the assembly code would
be hello.s.
o This assembly code is then sent to the assembler, which converts the assembly code
into object code.
o After the creation of an object code, the linker creates the executable file. The loader
will then load the executable file for the execution

You might also like