5.
DATA TYPES AND OPERATORS
1. What are data types?
Data types are the means to identify the nature of the data and the set of operations
that can be performed on the data.
2. What are different data types in C++?
There are three types of data types C++,
a). Fundamental data type (built in Data types): They are defined in the C++
compiler. They can not be further broken down. There are 5 types of Fundamental
data types,
1). Char: They are symbols covered by the character set of C++ language. It
uses only one byte
of memory (storing in memory with its ASCII value).
2). Int : Whole numbers without fractional part. It can be positive or negative,
or zero. It uses
Four bytes of memory based on GCC compiler.
3). Float : They are numbers with fractional part. It uses four bytes of
memory. It can be
represented either by scientific notation or mantissa exponential
method.
4). Double: It is used for handling large floating point numbers. It uses 8
bytes of memory.
5). Void : uses zero bytes of memory.
b). Derived data types: They are derived from fundamental data types by some
grouping or alteration in size.
Eg. Array, pointer etc…
c). User defined data types: The programmer can define there own data types.
Eg. Struct, enum, union, class etc..
3. What are variables?
Name given to a memory location is known as variable. It is use to store and retrieve
data. It have three part: a) variable name b). Memory address(starting address of the
allocated memory)
c). Content
4. What are operators?
Tokens constituted by predefined symbols that can trigger to carry out operation.
The participants of the operation are called operands. The operators either be
constant or literal.
5. What are different types of operators used in C++?
According to the number of operand used in an operation, three types operators
a). unary: only one operand( eg +(positive),-(negative)
b). Binary operator: Two operator(eg. Arithmatic, relational etc..)
c). Ternary operator: Three operators( conditional ? :)
According to types of operation
a). Arithmetic operators ( +, - * /, %)
b). Relational operators( <,>, <=,>=, ==, !=)
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
c). Logical operator:
and (&&):( Result will be true only if both the combined expressions have true
value)
or(||):Result will be true only if any of the combined expressions have true value
)
not(!): To get the negation of the give expression
d). input/out put operators: input(get from or extract operator), output (put to or
insertion operator)
e). Assignment operator: = (to assign a value to a variable).
6. What are expressions? What are different types of expressions in C++?
expressions are composed of operators and operands. It is evaluated to get a
value(returning of value)
On the basis of operators expressions can be divided into,
a). Arithmetic expression: Expression in which arithmetic operators are used ( may
be integer or floating point expression)
b). Relational expression : Expression in which relational operators are used
c). Logical Expression : ): Expression in which logical operators are used
In an expression , the values of the variable have constant values, the expression is
known as constant expression.
7. What is a statement?
Statement is the smallest executable unit of programming language. It uses (;) as
delimiter. All the statements except declaration statement are executable.
8. What are different types of statements?
There are mainly four types of statements,
a). Declaration statements: It is used to declare the type of the variable or constant
used in the program.
Eg. int x, y ; int a=10;
b).Assignment statement: It is used to assign a value to a variable
eg. a=10; b=c+d;
c). Input statement: It allows the user to store data in the memory (RAM) during the
program execution. In C++ get from or extract operator(>>) is used for it.
Eg. cin >> a;
d). Output statement: It allows the user to make available the results through any
output device. In C++ put to or insertion operator(<<)is used for it.
Eg. cout >> a;
9. What is mean by cascading of I/O Operator?
Multiple use of Input / Output operators in a single statement is called cascading of
I/O Operator. Here the values are assigned to the variables from left to right.
Eg. cout << x <<y <<z; cin >> x >> y;
Assignment
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
10. Fill the tables
x y X && X || !x !y
y y
0 0
0 1
1 0
1 1
a b a<b a>b A<=b a>=b a!b a==b
5 3
-8 -2
7 10
Previous Questions
1. Given that x= 5 y=5. What will be the value of the expression x > y|| y > x? (1)
2. While writing a C++ program, a student forget to put semicolon at the end of a
3. declaration statement.What type of error can he expect during compilation ? (1)
4. The memory size of float data type in C++ is ............... bytes.
a)2 b)4 c)8 d)10 (1)
5. Explain different types of logical operators on C++. (3)
6. What is the difference between “=” and “= =” operators? (2)
7. What is the difference between x= 5 and x ==5 in C++ (2)
8. The memory size of float data type in C++ is .......... bytes.
a) 2 b) 4 c) 8 d) 10 (1)
9. Identify the name of following operators in C++.
&& , || , ! (1)
10.Write the declaration in C++ for a variable that can be used to store height of a
student. Justify, why you have selected this data type in the declaration. (1)
11. Which of the following is not a character constant in C++?
a) ‘a’ b) a c) ‘8’ d)’\a’ (1)
12. Memory requirement of void data type in C++ is .......... byte(s). (1)
13.Let X and Y are two variables of int data type, then correct the following input
statement.
cin<< X >> Y; (1)
14. Write the output of the following C++ expressions.
Let a=7,b=2.
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
a) a+b *3/ ++b;
b) a<=7&&b>1; (1)
15. Write value returned by the C++ expressions
a). 60 % 25;
b). 22 / 7; (2)
16. How do the type modifiers affect the size and range of int and char data types. (2)
17. Explain the difference between float g=9.8 ; and const float g=9.8 ; (2)
18. What is implicit type conversion?Why it is called type promotion ? (2)
19. Explain the different types of logical operators in C++ (2)
20. Distinguish between float and double data types in C++. (2)
21. What is a variable ?Differentiate between memory address and content of the
variable. (2)
22. Briefly explain any two expressions in C++. (2)
23. Predict the output of the following operations. x = -5and y = 3 initially.
a). –x b). x/y c). x % y d). –x + -y (2)
24. Consider the following statement.
int length;
Then what is the difference between (a) and (b)?
a). length = 50; b). length = = 50; (2)
25. Write sample statements in C++ for the cascading of input and output operators (2)
26. Explain the operations involved in the following C++ expressions and write the output.
a) 5/2+3
b) (10%3)/2.0 (2)
27.Write four different C++ statements to add 1 to the value stored in the variable
Num. (2)
28. Write a C++ program to print the following message.
( Hint : use only one cout statement).
“ SMOKING IS INJURIOUS TO HEALTH”
“ SAY GOODBYE TO DRUGS” (2)
29. What is the output of the following C++ statements.
X= -7 Y=3
a) add –x with –y
b) x modulus y (2)
30. What are data types ?Explain the fundamental data types in C++. (3)
31. Classify the identifiers given below as valid and invalid .Give reason for invalidity.
sum,if,_Num 1,Switch,stud Age (3)
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
32. .If a=5, b=7 and c=3. Predict the output of the following expresssions.
a) a<c b) b%a c) (a<c) && (a<b) d) a/c (2)
b)Write the declaration in C++ for a variable that can be used to store height of a
student.Justify,why you have selected this data type in the declaration. (1)
33. Predict the value of 'b' in the following C++ code after execution of each code snippet
a) and b) Justify your answer.
a) a = 5; b = a++; b) a = 5; b = ++a; (3)
34. Write a C++ program to check whether a given year is a leap year or not. (3)
35. Explain any three types of statements in C++. (3)
36. Consider X = 5 and Y = 2 and write the output of the following expressions. (3)
a). X = = Y && Y > X
b). X >= || Y = =2
c). ( X * X) – Y
37. What do you mean by a data type? Compare the fundamental data types char
and int available in C++. (3)
38. Find the best match from columns B and C for each item in column A. (3)
A B C
Assignment operator Modifier
“9” int Same as 9
== Relational operator Constant
short String Two operand are
needed
39. Identify six errors in the following C++ program and give a reason for each.
#include<iostream>
using namespace std;
int main()
{
int a; b;
cin<<a<<b;
a+b=s;
cout>>s;
} (3)
40. List the three numeric data types in C++ with an example for each. (3)
41. A part of bio data of a student is given. Identify the data types which we can use
to store and process these data.
Roll_Number : 34
Age : 17
Sex :M
Mob_Number : 8181818181
Height_In_Cm : 152.8
Pincode : 690601 (3)
42. If a = 5, b = 4, c = 3, d = 4 then what is the result in x after following operation?
X=a + b – c * d; (3)
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam
43. Is there any difference between (a) and (b) by considering the following statement?
char Gender;
a). Gender = ‘M’;
b). Gender = “M”; (3)
44. Write a short note on arithmetic And logical operators in C++. (3)
45. Write the equivalent arithmetic operations for the given C++ short hands.
i) x% =20; il) a+=2; Iii)p / = 5;
b) What is the difference between a = 20 and a = = 20? (3)
46. Classify the following identifiers valid or invalid. If invalid give reason.
a). Length_1 b). _Length1 c). Length 1 d). 1Length (4)
47. Write a C++ program to find the sum of first 10 odd numbers. (5)
© www.hsslive.in Prepared by Anil Kumar C , Govt HSS, Kuzhumathikkad, Kollam