Data Types in C++

Image result for c++ logo

Data Types - They are means to identify types of data and the associated operation of handling it .

In simple words, it tells us about the type of data we are dealing with in our program. It can be integer, character or fractional numbers.

C++ offers various types of data types :
  1. Primitive / Fundamental 
  2. Non-primitive / Derived (further divided)
         (i) built in derived data types
         (ii) user defined derived data types

In this part, we will only learn about Fundamental data types ,which is a very important concept and you will see this in every program . And these data types can also be used with derived data types , so you must know them.

remember all the data types in C++ are keywords , so you cannot use them as identifier.

FUNDAMENTAL DATA TYPES

1. int - * used to represent an integer value (a number without any decimal).
            * number can have + or - sign (number can be positive or negative).
            * size of int variable is 2 bytes.
            * to declare an integer variable, use the syntax -> int variable_name (ex - int x).
            * to declare more than one variable, separate them using comma (,) -> int variable1, variable2

2. char - * used to represent any character from the keyboard.
               * a single character must be enclosed in single quotes ( ' ' ) when used with output stream                        (cout), same as words are enclosed in double quotes (" ").
               * size of char variable is 1 byte.
               * for any given character its value is equivalent to the integer code of the character (ASCII                      CODE) (ex - for 'a' and 'A' ASCII code is 97 and 65).
               * syntax -> char variable_name (ex - char ch).
               * to declare more than one variable, separate them using comma -> char variable1,                                  variable2 

3. float - * used to represent a fractional number (ex - 1.5).
               * you can use either float or int data type to declare a number without fractional part, but                        the size of float variable (4 bytes) is greater than size of int variable (2 bytes). 
               * syntax -> float variable_name (ex - float x).
               * to declare more than one variable,separate them using comma-> float variable1, variable2

4. double - * used to represent a fractional number but with more precision (ex - 1.005).
                   * size of double variable (8 bytes) is twice of float variable.
                   * syntax -> double variable_name (ex - double x).
                   * to declare more than one variable, separate them using comma-> double variable1,                              variable2

5. void - * used to represent a valueless entity.
               * this data type is used for those functions which does not return any value.
               * syntax for functions -> void function_name ( )
                                                             { function body  }                                                                                                                                                                    

The first three data types are often used in programming and void data type is used when we are dealing with functions. So we will learn more about void data type latter while dealing with functions.

In next part we will discuss about input stream and new line character in C++ and in next to next part we will combine all our previous knowledge to make a complete working user friendly program.

  
               





Comments

Popular Posts