Académique Documents
Professionnel Documents
Culture Documents
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
% remainder of division
Operator Description
> Check if operand on the left is greater than operand on the right
Logical operators
C language supports following 3 logical operators. Suppose a = 1 and b = 0,
|| Logical OR (a || b) is true
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
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.
+= 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
1. Preprocessor
2. Compiler
3. Linker
4. Loader
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.
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.
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
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
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:
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)
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:
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.
1. for
2. while
3. do-while
Syntax for each C loop control statements are given in below table with description.
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()
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
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
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++;
12
13 }
OUTPUT:
Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4
while do while