0% found this document useful (0 votes)
21 views3 pages

C Set1

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

C Set1

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

SHRI RAMSWAROOP MEMORIAL UNIVERSITY

Solution / Hints
InternalTest – I
Session : 2024-25 (Odd Sem.) Semester : III
Course : Diploma Subject Code : DCS3001
Branch : CSE Subject Name : Computer Programming in C
Group : CS-31,32 Name of Faculty member : Er. Reshav Roushan
Date : 21/08/2024 Duration : 45 Min Max. Marks: 30 SET No. :A

Q1
a) Low-Level Language
A Low-level computer language consists of only 1’s and 0’s.
High-Level Language
High-Level Languages are the advanced development languages in the evolution of computer
languages.

b) The main drawback of machine language is how difficult it is to develop, learn, and execute
codes and algorithms. It is pretty time-consuming to fix flaws and mistakes in codes and
programs. Only some people can memorize or even write the code. It is platform independent
language.

c) An algorithm is a procedure used for solving a problem or performing a computation.


Algorithms act as an exact list of instructions that conduct specified actions step by step in
either hardware- or software-based routines.

d) A function is a group of statements that together perform a task. Every C program has at least
one function, which is main(), and all the most trivial programs can define additional functions.

Q2
a) Algorithm to addition of two numbers in C
 Step 1: Start
 Step 2: Declare three variables: num1, num2, and sum
 Step 3: Read the first number (num1) from the user
 Step 4: Read the second number (num2) from the user
 Step 5: Add num1 and num2 and store the result in the sum variable (sum = num1 +
num2)
 Step 6: Display the value of the sum
 Step 7: End

b) Types of Language Processors


The language processors can be any of the following three types:
1. Compiler
The language processor that reads the complete source program written in high-level language
as a whole in one go and translates it into an equivalent program in machine language is called
a Compiler. Example: C, C++, C#.
In a compiler, the source code is translated to object code successfully if it is free of errors. The
compiler specifies the errors at the end of the compilation with line numbers when there are
any errors in the source code. The errors must be removed before the compiler can successfully
recompile the source code again the object program can be executed number of times without
translating it again.

2. Assembler
The Assembler is used to translate the program written in Assembly language into machine
code. The source program is an input of an assembler that contains assembly language
instructions. The output generated by the assembler is the object code or machine code
understandable by the computer. Assembler is basically the 1st interface that is able to
communicate humans with the machine. We need an assembler to fill the gap between human
and machine so that they can communicate with each other. code written in assembly language
is some sort of mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and so on.
and the assembler is basically able to convert these mnemonics in binary code. Here, these
mnemonics also depend upon the architecture of the machine.

3. Interpreter
The translation of a single statement of the source program into machine code is done by a
language processor and executes immediately before moving on to the next line is called an
interpreter. If there is an error in the statement, the interpreter terminates its translating
process at that statement and displays an error message. The interpreter moves on to the next
line for execution only after the removal of the error. An Interpreter directly executes
instructions written in a programming or scripting language without previously converting
them to an object code or machine code. An interpreter translates one line at a time and then
executes it.

c) // Simple C program to display "Hello World"

// Header file for input output functions


#include <stdio.h>

// Main function: entry point for execution


int main() {

// writing print statement to print hello world


printf("Hello World");

return 0;
}

Q3
a) The 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:
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 isis 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 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 iin n C use library functions. These library functions are pre 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. Sometimes the situation arises when our program refers to the functions defined
in other files; then linker plays a very important role in this. It links the object code of these
files to our program. Therefore, we conclude that the job of the
the linker is to link the object code
of our program with the object code of the library files and other files. The output of the linker
is the executable file. The name of the executable file is the same as the source file but differs
only in their extensions.
ns. In DOS, the extension of the executable file is '.exe', and in UNIX, the
executable file can be named as 'a.out'. For example, if we are using printf() function in a
program, then the linker adds its associated code in an output file.

You might also like