Different types of Character Set, Constant & Datatypes in C++

different types of character set, constant & data types in C++ programming


Introduction of Character Set in C++ Programming:

A character set is a combination of English language (Alphabets and White spaces) and math's symbols (Digits and Special symbols). Character Set means that the characters and symbols that a C++ Program can understand and accept.  These are grouped to form the commands, expressions, words, c-statements and other tokens for C++ Language.

The character set of C++: 

Letters: a-z, A-Z.
Digits: 0-9.
Special Symbols: Space, +, -, *, (, ),@,<,>,#.

White Spaces: Blank Space, horizontal tab, carriage return, New Line, Form Feed and C++ can process any of the 256 ASCII characters as data or literals.

What are Constants in C++ Programming?

Constant is a quantity that can’t be changed during program execution. Simply we can say that the value assigned to a variable is called constant. 
Example: a=5; 
“a” is a variable. “5” is a constant. 

There are different Types of constants used in C++ like Numeric Constant and Non-Numeric Constant.

1. Numeric constant:      

 The type of constants that consists of positive or negative signed numbers are called numeric constants. Numeric constants have different types like Integer, Floating, Octal, hexadecimal.

i. Integer constant: 

That positive or negative numbers that do not contain a decimal point.  Example: 27, 45, 1000, -78, -98.

ii. Floating point constant: 

That positive or negative numbers that contain a decimal point.  Example: 2.7, 4.5, -7.8, -9.8 

iii. Octal constants: 

A number system that uses only 8 digits (0-7) is called the octal number system. To represent a number as octal we must start that number with 0.  Example: 0347, 0342, 056

iv. Hexa-decimal constant: 

A number system that uses 10 digits (0-9) and alphabets (A-F, A=10, B=11, . . . , F=16) is called hexa-decimal number system. To represent a number as hexadecimal we must start that number with 0X.  v. Example: 0X347, 0X342, 0XAB12.

2. Non-numeric constant: 

 Non-numeric constants are the type of constants that does not consists of numbers, instead they use alphabet/symbols or sequence of alphabets/ symbols as constant. Non-numeric constants have Character, String constants.

i. Character constants: A character enclosed within single quotes is called character constant. A character constant can be a single alphabet, symbol or number enclosed in single quotes.  Examples: ‘a’, ‘$’, '1'. 

ii. String constant: A string constant is a single or sequence of character enclosed in double quotes.  Example: “Ali”, “123”, “#@&”.

Different Data Types used in C++ Programming Language:

While programming we store variables in a computer’s memory but the computer has to know what kind of data we want the store in them. Data types tell the compiler that what types of data (means integer, float, character or string) the variable will store. The most commonly used data types used in C++ programming are listed and well-explained below:

1) Integer data type: 

The data type which represents integer numbers is called integer data type. These are used to declare integer variables. The reserved word “int” is used to represent Integer data type which has a size of 2 bytes. The reserved word “short int” is used to represent Short Integer data type which has a size of 2 bytes. The reserved word “long int” is used to represent Long Integer data type which has a size of 2 bytes.

2) Floating point data type:

Floating point data types are used to represents numbers with a decimal point. Floating point data types are used to declare floating point variable. The reserved word “float” is used to represent Float data type which has a size of 4 bytes. The reserved word “double” is used to represent Double data type which has a size of 8 bytes. The reserved word “long double” is used to represent Long Double data type which has a size of 10 bytes. 

3) Character data type: 

The data type which represents a character is called a character data type. It is used to declare a character variable. The reserved word “char” is used to represent Character data type which has a size of 1 bytes. 

4) String data type: 

The data type which represents string is called a String data type. It is used to declare a string variable. The reserved word “char” with size enclosed in [ ] is used to represent String data type

5) Boolean data type:  

A data type that represents binary values (1/0) is called Boolean data type. The reserved word “bool” is used to represent Boolean data type.  








  


Post a Comment

0 Comments