WEB DEVELOPER SITE
PYTHONPHPJAVA
 

C++ Data Type


The operating system allocates memory and selects what will be stored in the reserved memory based on the variable's data type.


Expression

The examples below show legal and illegal C++ expressions.
34+18 //  legal C++ expression
//Both operands of the + operator are integers

34 + "Morris" // illegal
// The + operator is not defined for integer and string

Numeric

Numeric data types include:
  • Integers -3, 45.
  • Floating point 11.5,12.9

Strings & Characters

A string is composed of numbers, characters, or symbols. String literals are placed in double quotation marks; some examples are "Hello", "My name is Jhon", and similar.


Characters are single letters or symbols, and must be enclosed between single quotes, like 'a', 'b', etc.

Boolean

Conditional statements are data type is Boolean. Two return type 1 true and 0 false

Integers

The integer type holds non-fractional numbers, which can be positive or negative. Examples of integers would include 15, -15, and similar numbers.

Integers Define

Use the int keyword to define the integer data type.
int a = 17;
  • modifiers: basic types, including integers, can be modified using one or more of these type
  • short: Half of the default size.
  • long: Twice the default size.

example:
unsigned long int a;

Floating Point Numbers

A floating point type variable can hold a real number, such as 12, -12.22, or 0.0365.

a float is 4 bytes, a double is 8, and a long double can be equivalent to a double (8 bytes), or 16 bytes.

Floating point data types are always signed, which means that they have the capability to hold both positive and negative values.

String

A string is an ordered sequence of characters, enclosed in double quotation marks.

you can use a library that includes the string library.

#include <string>
using namespace std;

int main() {
  string a = "Programming never forget!";
  return 0;
}
The <string> library is included in the <iostream> library, so you don't need to include <string> separately, if you already use <iostream>.

Characters

A char variable holds a 1-byte integer.

A character is enclosed between single quotes (such as 'a', 'b', etc).


char test = 'A';