0% found this document useful (0 votes)
26 views4 pages

Hsslive XI CS Chap6 Data Types and Operators

The document discusses various topics related to data types and operators in C++ including fundamental data types, data type modifiers, variables, operators, arithmetic expressions, relational expressions, logical expressions, type conversion, and more. It also provides examples of C++ statements and questions from previous years' question papers related to these concepts.

Uploaded by

dxkmyffqv7
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)
26 views4 pages

Hsslive XI CS Chap6 Data Types and Operators

The document discusses various topics related to data types and operators in C++ including fundamental data types, data type modifiers, variables, operators, arithmetic expressions, relational expressions, logical expressions, type conversion, and more. It also provides examples of C++ statements and questions from previous years' question papers related to these concepts.

Uploaded by

dxkmyffqv7
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/ 4

Computer Science - XI

Chapter 6: Data Types and Operators

Data types: These are the means to identify the nature of the data and the set of operations
that can be performed on the data.

Fundamental data types: These are the built-in data types of C++. Also known as basic data
types or atomic data types. The five fundamental data types in C++ are char, int, float,
double and void.

Data type modifiers: The keywords used to alter the size, range or precision of data
supported by the basic data types. Important modifiers are signed, unsigned, long and short.

Variables: The names given to memory locations, by which data in these


locations are referenced. In the figure, the variable name is Num and it
consumes two bytes of memory at memory addresses 1001 and 1002. The
content of this variable is 18. That is the L-value of Num is 1001 and the R-value is 18.

Operators: The tokens or symbols that trigger computer to carry out operations. The data
on which an operation are called operands. An operand may be either a constant or a
variable. Classified into three –unary, binary and ternary.

Arithmetic operators: Used to perform basic arithmetic operations such as addition,


subtraction, multiplication and division.

Modulus operator (%): Also called as mod operator. It gives the remainder value during
arithmetic division.

Relational operators: Used for comparing numeric data. These are binary operators. The
result of any relational operation will be either True or False.

Expression: Composed of operators and operands. Classified into arithmetic expressions,


relational expressions and logical expressions.

Arithmetic expression: An expression in which only arithmetic operators are used. Further
classified into integer expressions and floating point (real) expressions.

Integer expression: An arithmetic expression that contains only integer operands and
produces an integer result after performing all the operations given in the expression.

Floating point or real expression: An arithmetic expression that contains only floating point
data and returns a floating point result after performing all the operations given in the
expression.

Relational expression: An expression that contains relational operators. It produces Boolean


type results like True (1) or False (0).

Logical expressions: An expression that uses logical operators to combine two or more
relational expressions. It produces either True or False as the result.
1 Joy John’s CS Capsule
Computer Science - XI
Type conversion: Conversion of the data type of an operand into another type. Done in two
ways: implicitly and explicitly.

Type promotion: It is the implicit type conversion is performed by C++ compiler internally.
C++ converts the lower sized operands to the data type of highest sized operand. The
conversion is always from lower type to higher and hence the name type promotion.

Type casting: It is the explicit type conversion and is done by the programmer by specifying
the data type within parentheses to the left of the operand.

Variable declaration: data_type <variable1>,<variable2>, <variable3>,...;

Variable initialisation: Supplying value to a variable at the time of its declaration. Syntax:
data_type variable = value;

const access modifier: The keyword const is used to create symbolic constants whose value
can never be changed during execution. Eg: const float pi=3.14; the value of pi remains
constant (unaltered) throughout the execution of the program.

C++ Statements Operator Requirements Example


Input Statement >> cin and a variable cin>> a;
cout << a;
cout and variable or cout << “hello”;
Output Statement <<
constant or expression cout << 25;
cout << a + 2;
A variable and data N = 5;
Assignment
= (constant / variable / N = a;
Statement
expression) Num = a + 5;

Pre-processors: These are the compiler directive statements which give instruction to the
compiler to process the information provided before actual compilation starts. These lines
always start with a # (hash) symbol.

Header files: Files available along with compiler and they are kept in the standard library.
The header files contain the information about functions, objects and predefined derived
data types.

using namespace statement: It tells the compiler about a namespace where it should
search for the elements used in the program. In C++, std is an abbreviation of 'standard' and
it is the standard namespace in which cout, cin and a lot of other things are defined. So,
when we want to use them in a program, we need to follow the format std::cout and
std::cin. This kind of explicit referencing can be avoided with the statement using
namespace std; in the program.

main() function: An essential function in every C++ program. The execution starts at main()
and ends within main().

2 Joy John’s CS Capsule


Computer Science - XI
Questions from Previous Years’ Question Papers

1. Write output of the following C++ program.


#include<iostream>
using namespace std;
int main()
{
int a=1, b=2, c=3;
cout << a+b+c/3;
cout << “\n”;
cout << (a+b)%c;
} (2) (July 2017)
2. Write value returned by the following C++ expressions if x=10 and y=20.
a) x>15 ||y>15 b) x>15 && y>15 c) !(x>y) (3) (July 2017)
3. The following C++ code segment is a part of a program written by Smitha to find the
average of 3 numbers.
int a,b,c;
float avg;
cin >>a>>b>>c;
avg=(a+b+c)/3;
cout<<avg;
What will be the output if she inputs 1, 4 and 5? How can you correct it?
(2) (March 2017)
4. Briefly explain the three components in the structure of a C++ program.
(3) (March 2017)
5. Write C++ example for the following:
a) Declaration statement
b) Assignment statement
c) Type casting (3) (Sept. 2016)
6. Write a C++ expression to calculate the value of the following equation:

(2) (Sept. 2015)


7. Explain the data types in C++. (3) (Sept. 2015)
8. Predict the output of the following C++ statements:
int a=-5, b=3, c=4;
c+= a++ + --b;
cout<<a<<b<<c; (3) (March 2015)

9. Raju wants to add value 1 to the variable ‘p’ and store the new value in ‘p’ itself. Write
four different statements in C++ to do the task. (2) (March 2015)

3 Joy John’s CS Capsule


Computer Science - XI
10. Match the following: (3) (March 2015)
Name Symbol
(a) Modulus operator (i) ++
(b) Logical operator (ii) ==
(c) Relational operator (iii) =
(d) Assignment operator (iv) ?:
(e) Increment operator (v) &&
(f) Conditional operator (vi) %

4 Joy John’s CS Capsule

You might also like