📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 138question

Data Types, Variables and Expressions · Part 2

Chapter 3: 4 · Computer Science

to understand the working of data types, we need to know about variables. T he variables are the named memory locations to hold values of specific data types. In C++, the variables should be declared explicitly with their data types before they are actually used. Syntax for declaring a variable: <data type> <variable name>; Example: int num1; To declare more than one variable which are of the same data type using a single statement, it can be declared by separating the variables using a comma.

Example: int num1, num2, sum; For example, to store your computer science marks first you should declare a variable to hold your marks with a suitable data type. Choosing an appropriate data type needs more knowledge and experience. Usually, marks are represented as whole numbers. Thus, the variable for storing the computer science marks should be of integer data type.

Example: int ; Now, one variable named is ready to store your marks. We will learn more about variables later in this chapter. . .

Introduction to fundamental Data types: Fundamental (atomic) data types are predefined data types available with C++. There are five fundamental data types in C++: char, int, float, double and void . Actually, these are the keywords for defining the data types. ( ) int data type: Integer data type accepts and returns only integer numbers.

If a variable is declared as an int , C++ compiler allows storing only integer values into it. If you try to store a fractional value in an int type variable it will accept only the integer portion and the fractional part will be ignored. Chapter Page - - For Example int num= ; num1 variable is declared as integer types. So, it can store integer value ( ) char data type: Character data type accepts and returns all valid ASCII characters.

Character data type is often said to be an integer type, since all the characters are represented in memory by their associated ASCII Codes. If a variable is declared as char, C++ allows storing either a character or an integer value. Example

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →