Predefined Data Types
Predefined data types
Data can be of many types (e.g. Character, integer, real, string, etc). Data types define the types of variables. There are following predefined data types:-
- Int data type (for integer):-
Integers are whole numbers such as 642, -19 etc. they have no fractional parts.
Short int————occupies 2 bytes
Int———–occupies 2 bytes
Long int———— occupies 4 bytes
- Float data type(for floating point number):-
A number having fractional part is a fractional point number. E.g. 3.145. float occupies 4 bytes.
- Char data type(for character):-
It is used for representing characters and strings. Char occupies 1 byte
- Double data types(for double precision floating point number):-
It is also used for handling floating point number. But, it occupies twice as much memory as type float and stores floating point numbers with much larger range and precision. Double occupies 8 byte and long double occupies 10 bytes.
Keywords refer to a character or group of characters whose definition is already defined in the compiler. It is also called as reserve word. C++ includes 48 keywords. Some of them are listed below:-
Class, private, public, protected, friend, new, delete, do, while, for, int, float, double, return, void, size of, long.
[Note: - keyword cannot be used as identifiers (variables name).]
Declaring variables and constants
A variable is a named location in memory that is used to hold a value that may be modified by the program. All variables must be declared before they are used.
Declaration form of variables
Where Data_type is any c++ data type and variable name is the name of the variable.
Character variables:- Are used to store characters ‘a’, ‘c’, ‘b’ & so on
Integer variables: – are used to store whole number.
Float variables: – are used to store floating point number.
A variable can also be declared constant using keyword const so that its value can never be changed during program execution.
E.g. Const int a=500;
It is a unary operator that returns the size or length of the variables or data type in bytes. It can be used in two forms:-
- Size of(var);
Where, var is a variable
E.g. Size of (a);
- Size of(Data_type);
E.g. Size of (int);
Comma operator is used to string together several expressions. Expression is the combination of operator and variable.
E.g. B= (a=3, a+1);
This first assigns ‘a’ the value 3 and then assigns ‘B’ the value a+1 i.e. 3+1=4.
- Procedural oriented programming Procedural oriented programming (pop):- A program in a procedural language...
- Implicit and explicit functions What is Implicit and Explicit function? Continue reading to find...
- Types of operating systems An operating system can also be divided into many types...
- Types of matrices Matrix theory is one of most important topic in mathematics...
- Object oriented programming Object oriented programming : The main idea behind object oriented...