Vous êtes sur la page 1sur 12

DCS – 101

Q.5 What are operators? Describe various types of operators available in C language.

Ans. C language supports a rich set of built-in operators. An operator is a symbol that tells the compiler to
perform a certain mathematical or logical manipulation. Operators are used in programs to manipulate data
and variables.

C language supports a rich set of built-in operators. An operator is a symbol that tells the compiler to
perform a certain mathematical or logical manipulation. Operators are used in programs to
manipulate data and variables.
C operators can be classified into following types:

 Arithmetic operators
 Relational operators
 Logical operators
 Bitwise operators
 Assignment operators
 Conditional operators
 Special operators

 Arithmetic operators
 C supports all the basic arithmetic operators. The following table shows all the basic arithmetic
operators.

Operator Description

+ adds two operands

- subtract second operands from first

* multiply two operand

/ divide numerator by denominator

% remainder of division

++ Increment operator - increases integer value by one

-- Decrement operator - decreases integer value by one


Relational operators
The following table shows all relation operators supported by C.

Operator Description

== Check if two operand are equal

!= Check if two operand are not equal.

> Check if operand on the left is greater than operand on the right

< Check operand on the left is smaller than right operand

>= check left operand is greater than or equal to right operand

<= Check if operand on left is smaller than or equal to right operand

Logical operators
C language supports following 3 logical operators. Suppose a = 1 and b = 0,

Operator Description Example

&& Logical AND (a && b) is false

|| Logical OR (a || b) is true

! Logical NOT (!a) is false

Bitwise operators
Bitwise operators perform manipulations of data at bit level. These operators also perform shifting
of bits from right to left. Bitwise operators are not applied to float or double(These are datatypes,
we will learn about them in the next tutorial).

Operator Description
& Bitwise AND

| Bitwise OR

^ Bitwise exclusive OR

<< left shift

>> right shift

Now lets see truth table for bitwise &, | and ^

a b a&b a|b a^b

0 0 0 0 0

0 1 0 1 1

1 0 0 1 1

1 1 1 1 0

The bitwise shift operator, shifts the bit value. The left operand specifies the value to be shifted and
the right operand specifies the number of positions that the bits in the value have to be shifted. Both
operands have the same precedence.

Assignment Operators
Assignment operators supported by C language are as follows.

Operator Description Example

= assigns values from right side operands to left side a=b


operand

+= adds right operand to the left operand and assign the a+=b is same as
result to left a=a+b

-= subtracts right operand from the left operand and a-=b is same as
assign the result to left operand a=a-b
*= mutiply left operand with the right operand and assign a*=b is same as
the result to left operand a=a*b

/= divides left operand with the right operand and assign a/=b is same as
the result to left operand a=a/b

%= calculate modulus using two operands and assign the a%=b is same as
result to left operand a=a%b

Conditional operator
The conditional operators in C language are known by two more names

1. Ternary Operator
2. ? : Operator

It is actually the if condition that we use in C language decision making, but using conditional
operator, we turn the if condition statement into a short and simple operator.

Special operator
Operator Description Example

sizeof Returns the size of an variable sizeof(x) return size of the variable x

& Returns the address of an variable &x ; return address of the variable x

* Pointer to a variable *x ; will be pointer to a variable x

Q.8 Describe the process of the execution of a C program in detail.

Ans. Pre-processing, Compiling, Linking, Loading


Execution of a C/C++ program involves four stages using different compiling/execution tool,
these tools are set of programs which help to complete the C/C++ program's execution
process.

1. Preprocessor
2. Compiler
3. Linker
4. Loader

These tools make the program running.

1) Preprocessor
This is the first stage of any C/C++ program execution process; in this stage Preprocessor
processes the program before compilation. Preprocessor include header files, expand the
Macros.

2) Complier
This is the second stage of any C/C++ program execution process, in this stage generated
output file after preprocessing ( with source code) will be passed to the compiler for
compilation. Complier will compile the program, checks the errors and generates the object
file (this object file contains assembly code).

3) Linker
This is the third stage of any C/C++ program execution process, in this stage Linker links the
more than one object files or libraries and generates the executable file.

4) Loader
This is the fourth or final stage of any C/C++ program execution process, in this stage Loader
loads the executable file into the main/primary memory. And program run.

Different files during the process of execution


Suppose, you save a C program with prg1.c – here .c is the extension of C code, prg1.c file
contains the program (source code of a C program). Preprocessor reads the file and generates
the prg1.i(prg1.ii – for c++ source code) file, this file contains the preprocessed code.
Compiler reads the prg1.i file and further converts into assembly code and
generates prg1.s and then finally generates object code in prg1.o file.
Linker reads prg1.o file and links the other assembly/object code or library files and
generates executable file named prg1.exe.
Loader loads the prg1.exe file into the main/primary memory and finally program run.
One more file is created that contains the source code named prg1.bak; it’s a backup file of
the program files.
Q.3 What is software? Diffentiate between system software and application software in
detail with suitable examples.

Ans. Computer software, or simply software, is a collection of data or computer instructions that
tell the computer how to work. This is in contrast to physical hardware, from which the system is built
and actually performs the work. In computer science and software engineering, computer software is
all information processed by computer systems, programs and data. Computer software
includes computer programs, libraries and related non-executable data, such as online
documentation or digital media. Computer hardware and software require each other and neither can
be realistically used on its own.

Software is basically classified into two categories, System Software and Application
Software. Where System Software acts as an interface between Application Software
and hardware of the computer. The Application Software acts an interface between user
and System Software. We can distinguish System Software and Application Software on
account of the purpose of their design. The System Software is designed to manage
the system resources and it also provides a platform for Application Software to run. On
the other hand Application Software are designed for the users to perform their
specific tasks.

Difference between System Software and Application Software

S.No. System Software Application Software

System software is used for Application software is used by user


1. operating computer hardware. to perform specific task.

System softwares are installed on


the computer when operating Application softwares are installed
2. system is installed. according to user’s requirements.
In general, the user does not
interact with system software
because it works in the In general, the user interacts with
3. background. application sofwares.

System software can run Application software can’t run


independently. It provides independently. They can’t run
platform for running application without the presence of system
4. softwares. software.

Some examples of system Some examples of application


softwares are compiler, softwares are word processor, web
5. assembler, debugger, driver, etc. browser, media player, etc.

Q.2 What is a computer? What are the main characterstics of a computer? Draw a neat
block diagram of a computer.

Ans. computer is an electronic device . which is used to comput organise store information and
used to process data . It is also for to arithmetic calculation

Basic characteristics about computer are:


1. Speed: - As you know computer can work very fast. It takes only few seconds for calculations that
we take hours to complete. You will be surprised to know that computer can perform millions
(1,000,000) of instructions and even more per second.
2. Accuracy: - The degree of accuracy of computer is very high and every calculation is performed
with the same accuracy. The accuracy level is 7.
determined on the basis of design of computer. The errors in computer are due to human and
inaccurate data.
3. Diligence: - A computer is free from tiredness, lack of concentration, fatigue, etc. It can work for
hours without creating any error. If millions of calculations are to be performed, a computer will
perform every calculation with the same accuracy. Due to this capability it overpowers human being
in routine type of work.
4. Versatility: - It means the capacity to perform completely different type of work. You may use your
computer to prepare payroll slips. Next moment you may use it for inventory management or to
prepare electric bills.
5. Power of Remembering: - Computer has the power of storing any amount of informationor data.
Any information can be stored and recalled as long as you require it, for any numbers of years. It
depends entirely upon you how much data you want to store in a computer and when to lose or
retrieve these data.
6. No IQ: - Computer is a dumb machine and it cannot do any work without instruction from the user.
It performs the instructions at tremendous speed and with accuracy. It is you to decide what you want
to do and in what sequence. So a computer cannot take its own decision as you can.
7. No Feeling: - It does not have feelings or emotion, taste, knowledge and experience. Thus it does
not get tired even after long hours of work. It does not distinguish between users.
8. Storage: - The Computer has an in-built memory where it can store a large amount of data. You
can also store data in secondary storage devices such as floppies, which can be kept outside your
computer and can be carried to other computers.

Block Diagram of Computer

Computer – The word “computer “comes from the word “compute “which means to calculate. So a computer
is normally considered to be a calculating device that performs arithmetic operations at enormous speed. A
computer is an electronic device which is used to perform operation on raw data as per instruction given by
user. They are
1) It accepts data or instructions through input,
2) It stores data,
3) It can process required data by the user,
4) It gives results as production, and
5) It controls all functions inside the computer

Various Components of Computer


Computer is an electronic device which performs tasks given by user with extremely fast speed and accuracy.
Like any other device or machine, a computer system has also a number of parts. A computer system can be
blocked into mainly three parts:

1. Input Unit
2. Central Processing Unit
3. Output Unit

1. Input unit – Input unit is a unit that accepts any input device. The input device is used to input data into the
computer system.
Function of input unit:

1. It converts inputted data into binary codes.


2. It sends data to main memory of computer .

2. Central Processing Unit (CUP) – CPU is called the brain of a computer. An electronic circuitry that carries
out the instruction given by a computer program.
CPU can be sub classified into three parts.
i .Control unit (CU)

ii. Arithmetic & Logic unit (ALU)

ii.Memory Unit (MU)

i. Control unit (CU)- the control unit manages the various components of the computer. It reads instructions
from memory and interpretation and changes in a series of signals to activate other parts of the computer. It
controls and co-ordinate is input output memory and all other units.
ii. Arithmetic & Logic unit (ALU) – The arithmetic logic unit (ALU), which performs simple arithmetic
operation such as +,-, *, / and logical operation such as >, <, =<, <= etc.
iii. Memory Unit (MU)- Memory is used to store data and instructions before and after processing. Memory is
also called Primary memory or internal memory. It is used to store data temporary or permanently.
Function of CPU-

1. It controls all the parts and software and data flow of computer.
2. It performs all operations.
3. It accepts data from input device.
4. It sends information to output device.
5. Executing programs stored in memory
6. It stores data either temporarily or permanent basis.
7. It performs arithmetical and logical operations.

3. Output Unit –Output unit is a unit that constituents a number of output device. An output device is used to
show the result of processing.
Function of Output unit:

1. it accepts data or information sends from main memory of computer


2. It converts binary coded information into HLL or inputted languages.

Q.6 What are looping statements? Discuss all types of looping statements supported by C
language with suitable example.

Ans. Loop control statements in C are used to perform looping operations until the given condition is true. Control comes out of
the loop statements once condition becomes false.

TYPES OF LOOP CONTROL STATEMENTS IN C:


There are 3 types of loop control statements in C language. They are,

1. for
2. while
3. do-while
Syntax for each C loop control statements are given in below table with description.

Loop Name Syntax

for (exp1; exp2; expr3)


{ statements; }Where,
exp1 – variable initialization
( Example: i=0, j=2, k=3 )
for exp2 – condition checking
( Example: i>5, j<3, k=3 )
exp3 – increment/decrement
( Example: ++i, j–, ++k )

while (condition)
{ statements; }where,
while condition might be a>5, i<10

do { statements; }
while (condition);where,
do while condition might be a>5, i<10

1. MALLOC()

EXAMPLE PROGRAM (FOR LOOP) IN C:

In for loop control statement, loop is executed until condition becomes false .

1 #include <stdio.h>

3 int main()

4 {

5 int i;

7 for(i=0;i<10;i++)

8 {

9 printf("%d ",i);

10 }

11

12 }

OUTPUT:

0123456789

EXAMPLE PROGRAM (WHILE LOOP) IN C:

In while loop control statement, loop is executed until condition becomes false .
C
1 #include <stdio.h>

3 int main()

4 {

5 int i=3;

7 while(i<10)

8 {

9 printf("%d\n",i);

10 i++;

11 }

12

13 }

OUTPUT:

3456789

EXAMPLE PROGRAM (DO WHILE LOOP) IN C:


In do..while loop control statement, while loop is executed irrespective of the condition for first time. Then 2nd time onwards, loop is
executed until condition becomes false.
C

1 #include <stdio.h>

3 int main()

4 {

5 int i=1;

7 do

8 {

9 printf("Value of i is %d\n",i);
10 i++;

11 }while(i<=4 && i>=2);

12

13 }

OUTPUT:

Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4

DIFFERENCE BETWEEN WHILE & DO WHILE LOOPS IN C LANGUAGE:

while do while

Loop is executed Loop is executed for first time irrespective of the


only when condition condition. After executing while loop for first
is true. time, then condition is checked.

Vous aimerez peut-être aussi