C++ Tutorial

Language Elements

Object Oriented Concepts

Data Types

Key Words

Arrays

Pointers

Data Structures

Multithreading

Errors and Exception Handling

Interview Questions



Contact



Data Types in C++


Some of the commonly used primitive data types are integer, boolean, character, float, and double. These values are stored at memory locations, under assigned name, as variables.

Integer

An integer is the data type which can be positive or negative number with no decimal places, e.g. -5, -3, 2, 5 etc.

Float

A floating point number contains decimal places or is written using exponential notations e.g. -3.43, -2.2, .2, 5.9 etc.

Double

Double contain decimal places similar to float, with double precision, and provides 8 - byte storage for numbers (twice to that by float). A double has 15 to 16 decimal digits of precision, while float only has 7.

Character

Character variable can be declaired by using the char key word. It is the data type that holds an integral value of 1 bit i.e. single character (can be blank space).

Boolean

A boolean data type can have two states, true or false. They can expressed by built on constants such as "true" to an ineger 1 or "false" to an integer 0.

Escape Sequence

The combination of a backlash (\) and a special character is called an escape sequence. When placed directly in front of a group of character, it tells the compiler to escape from the usual interpretation of these chracters, e.g. \n (move to the next line), \t (move to the next tab) etc.

Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations, such as addition, subtraction, multiplication, and division. Addition is denoted operator +, subtraction by -, multiplication by *, divided by /. Modulus % operator produces the remainder of an integer division.
9%4 is 1
17%3 is 2
14%2 is 0






Copyright © by Zafar Yasin. All rights reserved.