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

Data Types, Variables and Expressions

Chapter 3: 11th Computer Science · Computer Science · EN medium

From your actual textbook ✓

What does your textbook say about Data Types, Variables and Expressions?

. Introduction Every programming language has two fundamental elements, viz., data types and variables. They are very essential elements to write even the most elementary programs. C++ provides a predefined set of data types for handling the data items. Such data types are known as fundamental or built-in data types. Apart from the built-in data types, a programmer can also create his own data types called as User-defined data types. In this chapter, we are going to learn about built-in data types. . Concept of Data types Let us look at the following example, Name = Ram Age = = . In the above example, Name, Age, are the fields which hold the values such as Ram, , and . respectively.

📖 Namma Kalvi 11th Computer Science Textbook English Medium · Page 138

Read from the source

Complete lesson

. Introduction Every programming language has two fundamental elements, viz., data types and variables. They are very essential elements to write even the most elementary programs. C++ provides a predefined set of data types for handling the data items.

Such data types are known as fundamental or built-in data types. Apart from the built-in data types, a programmer can also create his own data types called as User-defined data types. In this chapter, we are going to learn about built-in data types. .

Concept of Data types Let us look at the following example, Name = Ram Age = = . In the above example, Name, Age, are the fields which hold the values such as Ram, , and . respectively. In a programming language, fields are referred as variables and the values are referred to as data .

Each data item in the above example looks different. That is, “Ram” is a sequence of alphabets and the other two data items are numbers. The first value is a whole number and the second one is a fractional number. In real-world scenarios, there are lots of different kinds of data we handle in our day-to-day life.

The nature or type of the data item varies, for example distance (from your home to school), ticket fare, cost of a pen, marks, temperature, etc., In C++ programming, before handling any data, it should be clearly specified to the language compiler, regarding what kind of data it is, with some predefined set of data types. . C++ Data types In C++, the data types are classified as three main categories ( ) Fundamental data types ( ) User-defined data types and ( ) Derived data types. Data Types User Defines Data types Derived Data types Floating Point Integral types Structure, Union, Class, Enumeration Void int char float double Array, Function, Pointer, Reference Fundamantal Built - in data types Figure .

Data types in C++ In this chapter, we are going to learn about only the Fundamental data types. In order 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. 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 :- char c='A'; cout<<ch ; In the above code, ch is declared as a char type variable to hold a character.

It displays the character A Example :- char ch='A' cout<<ch+ ; In the above statements, the value of ch is incremented by and the new value is stored back in the same variable ch . (Remember that, arithmetic operations are carried out only on the numbers not with alphabets) so it displays B Another program illustrates how int and char data types are working together. #include <iostream> using namespace std; int main () int n; char ch; cout << "\n Enter an ASCII code ( to ): "; cin >> n; ch = n; cout << "\n Equivalent Character: " << ch; The output Enter an ASCII code ( to ):

Related topics

Want this shaped for your exam marks?

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

Ask AI about this topic →