146k views
2 votes
Describe the additional data types. Bool, char, string , float

1 Answer

5 votes

Answer:

Basic types of Variables in C++

Here are the basic types of C++ variables:

Int:

An integer is a numeric literal (associated with numbers) without any fractional or exponential part. Example. 120, -90, etc.

Double:

It is a double-precision floating point value. Example: 11.22, 2.345

Char:

A character literal is created by enclosing a single character inside single quotation marks. For example: ‘a’, ‘m’, ‘F’, ‘P’, ‘}’ etc.

Float:

A floating-point literal is a numeric literal that has either a fractional form or an exponent form. For example: 1.3, 2.6

String Literals:

A string literal is a sequence of characters enclosed in double-quote marks. For example: “How are you?”

Bool:

It holds Boolean value true or false.

Rules of Declaring Variables in C++

Here are some common rules for naming a variable:

A C++ variable name can only have alphabets, numbers, and underscore.

A C++ variable name cannot begin with a number.

Variable names should not begin with an uppercase character.

A variable name used in C++ cannot be a keyword. For example, int is a keyword that is used to denote integers.

A C++ variable name can start with an underscore. However, it is not considered a good practice.

C++ Variable Data Types

C++ defines a whole set of primitive types

The void type has no associated values with it and can be used in only a few circumstances. It is most commonly as the return type of functions that do not return a value.

The arithmetic types include characters, integers, Boolean values, and floating-point numbers. Arithmetic type if further divided into 2 categories

Floating-point types. The float (or floating type) represent decimal numbers. The IEEE standard specifies a minimum number of significant digits. Most compilers usually provide more precision than the specified minimum. Typically, floats are represented in by 32bits, doubles in 64 bits, and long doubles in either 96 or 128 bits.

Integral types (which include character, integers, and Boolean types). The Boolean type has only two types of values: True or False. There are several char types, most of which exist to support internationalization. The most basic character type is char. A char is the same size as a single machine byte meaning a single byte.

The Integral types may be signed or unsigned.

Signed Type: They represent negative or positive numbers (including zero). In a signed type, the range must be evenly divided between +ve and -ve values. Thus, an 8-bit signed char will hold values from –127 through 127.

Unsigned Type: In an unsigned type, all values are >= 0. An 8-bit unsigned char can contain 0 through 255 (both inclusive).

Step-by-step explanation:

A C++ variable provides us with a named storage capability. It allows the programmer to manipulate data as per the need. Every variable has a type in C++. The variable type helps to determine the size and layout of the variable’s memory map, the range of values that can be stored within that memory, and the set of operations that can be applied to it.

User Yuichi
by
7.5k points