Variables and Data Types In C++

Variable

A variable is an identifier that denotes a storage location, which content can be varied during program execution. A variable is a character or group of characters and It is used to store data. Example: Total, Emp_no, avg etc.

Data Types 

Data Type means type of data that variable can store. We use data types during declaration of variable or constant.
In C++ There are three types of data types:
1) Primary or Fundamental or Built-in Data Types
2) Derived Data Types
3) User-Defined Data Types
 

Primary Data Type

These are built in data types and can be used directly by the user.
  • int: It is used to declare integer variables. Ex- int total;
  • char: It is used to declare character variables. Ex- char c;
  • bool: It is used to declare boolean variables. A boolean variable can store either true or false. Ex- bool a;
  • float: It is used to declare floating point variables. Ex- float avg;
  • double: It is used to declare double precision floating point variables. Ex- double avg;
  • void: It means no value. Void data type is used for functions which does not returns any value. Ex- void avg();

Derived Data Type

The data-types that are derived from primary data types are known as Derived Data Types. 
  • Array
  • Function
  • Pointer

User Defined Data Type

These data types defined by user itself.
  • Structure
  • Class

Data Type Modifier

Modifiers are used to modify the size of a data type. 4 modifiers in C++ are Signed, Unsigned, Long and Short.

The modifiers signed, unsigned, long, and short can be applied to integer types. signed and unsigned can be applied to char, and long can be applied to double.

The modifiers signed and unsigned can also be used as prefix to long or short modifiers. For example, unsigned long int.

 


0 Comments:

Post a Comment

If you have any queries or suggestions, please let me know!