GK SCIENTIST

General Knowledge One Stop Source
Menu
  • Home
  • Social Science
    • History
    • Political Science
    • Geography
  • Science
    • Physics
    • Chemistry
    • Biology
  • Chemistry Notes
  • Mathematics
  • Computer
  • Tutorial MySQL
  • Tutorial Python
  • Java Tutorial
  • English Grammar
  • English Essay
  • Indian Anthropology
  • Philosophy
  • Solved Paper
  • UPSC
  • Current Content
    • Current Affairs
    • RSTV News
    • Yojana and Kurukshetra Gist
  • Donate
  • Contact Us

If you are interested in advertising to our audience, submit the advertising enquiry form.

Advertising Enquiry
Computer

C++ Data Types

Gk Scientist September 18, 2022 No Comments
Tweet WhatsApp Telegram

Table of Contents

  • C++ Data Types:
    • Built-in Data Types:
      • Integral Type:
      • Floating Type:
        • Float Data type:
        • Double data type:
      • Void Data Type:

C++ Data Types:

A data type is a term that is used to show the kind of data values or the type of data that is expected to be handled. A data type is, therefore, a group of data values that are-

  • Governed by the same set of rules.
  • Operated by the same set of operators.
  • Occupy the same number of bytes in the memory.

C++ like any other language provides ways and facilities to handle different types of data by providing data types. C++ language supports three data types-

  • Built-in data types (also known as basic or fundamental types).
  • User-defined data types.
  • Derived data types.
C Data Types and explanation - C++ Data Types

Built-in Data Types:

The built-in data types available in C++ are-

  • Integral Type.
  • Floating Type.
  • Void.

These are also called basic or fundamental data types. The size and range of these data types vary from computer to computer. The fundamental data types are the data types at the lowest level, i.e., those which are used for actual data representation in memory.

Integral Type:

Integral type can be further classified into-

  • int
  • char

int data type- An integer is an integral whole number without a decimal point. These numbers are used for counting. For example 26, 373, –1729 are valid integers. Normally an integer can hold numbers from -32768 to 32767. However, if the need is, a long integer (long int) can also be used to hold integers from -2, 147, 483, 648 to 2, 147, 483, 648.

Program to demonstrate the use of Integer variables:
Program to demonstrate the use of Integer variables - C++ Data Types

char data type- Characters can store any member of the C++ implementation’s basic character set. A character is a non-numeric data type consisting of a single alphanumeric character enclosed between two apostrophes, i.e., single quotation marks. Examples of valid character types are ‘A’, ‘7’, ‘a’, ‘6’, ‘&’.

It may be noted here that 6 and ‘6’ are of different data types. The former is of type int and later of type char.

Char type is often said to be an integer type. It is clear from the above program. It is because the alphabets, symbols, etc. are stored in computer memory by ASCII codes. It must be clear that the ASCII code of ‘A’ is 65, ‘a’ is 97, ‘B’ is 66, ‘b’ is 98, ‘6’ is 54, ‘7’ is 55 and ‘0’ is 48.

Program to display ASCII code of a character and vice versa:
Program to display ASCII code of a character - C++ Data Types

Floating Type:

A floating point number is represented in two ways i.e. decimal form and exponent form. It can be further classified into-

  • float
  • double
Float Data type:

Decimal Form- The floating point number in this form has a decimal point in it. A decimal point must be present even if the number has an integral value. These numbers are used for measurement. Example- height, area, distance, etc.

Examples of valid floating point numbers in decimal form are:

27.4
-927.
40.03
0.006

Examples of invalid floating point numbers in decimal form are:

4,297.98 (comma not allowed)
-39 (No decimal point)
Program to demonstrate the use of Float variables in Decimal Form:
Program to demonstrate the use of Float variables - C++ Data Types

Exponent Form- Another way of representing a floating point number in C++ is exponent form. In this form, the number is broken into two parts: mantissa and exponent. The mantissa is a floating point number in decimal form. The exponent starts with the letter “e” followed by an integer (signed or unsigned). For example- floating point number 7356.8 can be written as 7.3568 x 103. In exponent form, the base 10 of the decimal number system is replaced by the character e or E. So 7.3568 x 103 will be written as 7.3568 e 3.

Examples of valid floating point numbers in exponent form are:

314.27e09
2.967e-98
-87.98e21
84.00765e+8

Examples of invalid floating point numbers in exponent form are:

3.937 e 1.3 (exponent has decimal point)
-26.89 e (exponent has no digit)
Program to demonstrate the use of Float variables in Exponent Form:
Program to demonstrate the use of Float variables in Exponent Form - C++ Data Types

Floating point numbers have two advantages over integers. First, they can represent values between the integers. Second, they can represent a much greater range of values. But floating-point numbers suffer from one disadvantage also. Floating-point operations are usually slower than integer operations.

Double data type:

The word double stands for double precision floating point. The meaning of precision is the number of digits after the decimal point. It is also used for handling floating-point numbers. It is capable of representing floating-point numbers with a much larger range. It occupies twice as much memory as type float. It is used when the type float is too small or insufficiently precise.

The double data type is larger and slower than the float data type. So one must always use the smallest variable type for strong values in a C++ program to make it efficient.

Program to demonstrate the use of Double data type:
Program to demonstrate the use of Double data type - C++ Data Types

Void Data Type:

The void data type specifies an empty set of values. The void data types have two important purposes:

  • Indicates that a function does not return a value.
  • Declares a generic pointer.

No object of type void may be declared.

For example, we may define a function in C++ as:

This indicates that the function main () does not return any useful value.

Data TypesMemory SizeRange
char1 byte-128 to 127
signed char1 byte-128 to 127
unsigned char1 byte0 to 255
short2 byte-32,768 to 32,767
signed short2 byte-32,768 to 32,767
unsigned short2 byte0 to 65,535
int2 byte-32,768 to 32,767
signed int2 byte-32,768 to 32,767
unsigned int2 byte0 to 65,535
float4 byte3.4e-38 to 3.4e38
double8 byte1.7e-308 to 1.7e308
long double10 byte3.4e-4932 to 3.4e4932

FTP (File Transfer Protocol)
Email (Electronic Mail)
World Wide Web (WWW)
Internet and Its Uses
Read About Composite data type– Wikipedia
Prev Article
Next Article

Related Articles

Java FileReader Class
Java FileReader Class: We can use the Eclipse IDE for …
Gk Scientist January 14, 2023 Computer

Java FileReader Class

Encapsulation in Python
Encapsulation in Python: We can use the PyCharm code editor …
Gk Scientist December 5, 2022 Computer

Encapsulation in Python

Python SQLite Search Query
Python SQLite Search Query: We can use the PyCharm code …
Gk Scientist December 9, 2022 Computer

Python SQLite Search Query

Python Arithmetic Operators
Python Arithmetic Operators: We can use the PyCharm code editor …
Gk Scientist November 21, 2022 Computer

Python Arithmetic Operators

Java this Keyword
Java this Keyword: We can use the Eclipse IDE for …
Gk Scientist January 8, 2023 Computer

Java this Keyword

Python Constructors
Python Constructors: We can use the PyCharm code editor for …
Gk Scientist December 5, 2022 Computer

Python Constructors

Python Built-in-Exceptions
Python Built-in-Exceptions: We can use the PyCharm code editor for …
Gk Scientist December 6, 2022 Computer

Python Built-in-Exceptions

Converting JSON to Python Objects
Converting JSON to Python Objects: We can use the PyCharm …
Gk Scientist December 4, 2022 Computer

Converting JSON to Python Objects

Leave a Reply Cancel Reply

Search




  • Popular
  • Recent




GK SCIENTIST

General Knowledge One Stop Source

Information

  • About Us
  • Terms and Condition, Disclaimer
  • Contact Us

Android Apps

  • IAS App For English Medium Students
  • IAS Basics App For English Medium Students
  • IAS Hindi App For Hindi Medium Students
DMCA.com Protection Status

Popular Tags

Biology (33) Biology Questions (88) Chemistry (57) Computer (211) Current Affairs (4) Current Content (0) Economy (6) English Essay (172) English Grammar (75) English Literature (10) Geography (83) History (259) Indian Anthropology (11) Indian Polity (14) JKAS Mains Question Papers (17) Mathematics (68) Moral Science (7) NCERT & Other Boards Books (25) Philosophy (114) Physics (89) Political Science (132) RS TV News (33) Science (553) Social Anthropology (7) Social Science (17) Solved Paper (47) UPSC (7) UPSC Mains Question Papers (26)

Downloads

  • NCERT Books
  • Old NCERT Books
  • NIOS Books For IAS, SSC, and State PSC Exam
  • Tamil Nadu Board Books: Important For UPSC, SSC, and State PSC Exam
  • Modern Indian and World History Notes For IAS Exam
  • UPSC Topper 2013 Gaurav Agrawal Notes For IAS Preparation
  • UPSC IAS Prelims General Studies – Previous Year Papers
  • UPSC Mains Question Papers

Copyright © 2023 GK SCIENTIST
Theme by MyThemeShop.com& Hosted On Cloudways

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh
 

Loading Comments...