Data type and keywords in C++

23 Feb 2023
Beginner
788 Views

Introduction

A Data Type is a classification of specific types of data by a certain value or certain types of mathematical or logical operations. Data type depends on the command of the programming language such as letters, lowercase, uppercase, numbers, punctuation, and many more. In programming, keywords are reserved and predefined words which have special meanings. Keywords are mainly needed for the compilation of a program. Keywords are parts of syntax.

What is Data type in C++?

If the question is what data type in C++ is, then it can be answered that all the variables in C++ use various data types to restrict the type of data to be stored during declaration. If a variable is defined in C++ language, then the compiler allocates some specific memory based on that particular data type. There are 3 different Data types in C++, which are:
1. Primitive Data type- primitive data types in C++ are some inbuilt data types that can be used by the user directly for the declaration of the variable. Some primitive data types in C++ are,
  • Integer
  • Character
  • Boolean
  • Floating Point
  • Double Floating Point
  • Valueless or Void
  • Wide Character
2. Derived Data type- derived data type in C++ is derived from the primitive data type. There are some derived data types in C++ language, those are
  • Function
  • Array
  • Pointer
  • Reference
3. User-defined or abstract data type- abstract data type in C++ language is defined by the users themselves. It is like defining a class in structure or C++. This particular data type has some variations, those are
  • Class
  • Structure
  • Union
  • Enumeration
  • Typedef defined Datatype
Some basic data types of C++ programming language
Data Type Size Description
Boolean 1 byte This data type stores true or false values
char 1 byte This “char” data type stores a single character or letter or number or ASCII values
int 2 or 4 bytesThe “int” data type stores the whole numbers without including the decimals
float 4 bytes This data type stores fractional numbers that contain one or more decimals which are sufficient for storing 6-7 decimal digits
double 8 bytes This “double” data type stores fractional numbers that contain one or more decimals which are sufficient for storing 15 decimal digits

What is the keyword in C++?

Keywords or reserved words have some specific meaning to the compiler of C++ programs and it is always written in lower cases. Keywords generally used for serving some special functions such as "void", "int", "public" and many more in languages.

How many keywords are in C++

If the question is how many keywords are in C++ then the answer will be, C++ language has 32 various types of keywords. Those are,

C++ Keyword

asm double new switch
auto else operator template
break enum private this
case extern protected throw
catch float public try
char for register typedef
class friend return union
const goto short unsigned
continueif signed virtual
default inlinesizeofvoid
deleteintstaticvolatile
dolongstructwhile

Define keywords in c++

  • Asm: It is used to declare a block of code that has to be passed to the assembler.
  • auto: this keyword is a storage class specifier that is used for defining objects in a particular block.
  • break: This statement terminates any switch statement or any loop.
  • case: This keyword is used specifically within a switch statement to specify a match for the expression of the statement.
  • catch: it specifies which actions have to be taken when an exception occurs.
  • char: This is one of the fundamental data types in C++ language that defines character objects.
  • class: It is used to declare a user-defined data type that encapsulates any data members and operations or member functions of a particular class.
  • const: this keyword helps to define objects whose value will not alter throughout the lifetime of execution of that particular program.
  • continue:- It transfers control to the starting point of a loop.
  • default:- This keyword handles expression values in a switch statement that could not be handled by case.
  • delete: It is a memory deallocation operator.
  • do: indicate the start of a do-while statement in which the sub-statement is executed repeatedly until the value of the expression is logical-false.
  • double: Fundamental data type used to define a floating-point number.
  • else: Used specifically in an if-else statement.
  • enum: To declare a user-defined enumeration data type.
  • extern: An identifier specified as an extern has an external linkage to the block.
  • float:- Fundamental data type used to define a floating-point number.
  • for: Indicates the start of a statement to achieve repetitive control.
  • friend: A class or operation whose implementation can access the private data members of a class.
  • long: A data type modifier that defines a 32-bit int or an extended double.
  • new: Memory allocation operator.
  • operator: Overloads a c++ operator with a new declaration.
  • private: Declares class members which are not visible outside the class.
  • protected: Declares class members which are private except to derived classes
  • public: Declares class members who are visible outside the class.
  • register: A storage class specifier that is an auto specifier, but which also indicates to the compiler that an object will be frequently used and should therefore be kept in a register.
  • goto: this keyword helps to transfer the power of the control to a specified label.
  • if: it indicates the starting point of an if statement to achieve selective control.
  • inline: A function specifier that indicates to the compiler that inline substitution of the function body is to be preferred to the usual function call implementation.
  • int: Fundamental data type used to define integer objects.
  • return: Returns an object to a function’s caller.
  • short: A data type modifier that defines a 16-bit int number.
  • signed: A data type modifier that indicates an object’s sign is to be stored in the high-order bit.
  • sizeof: Returns the size of an object in bytes.
  • static: The lifetime of an object-defined static exists throughout the lifetime of program execution.
  • struct: To declare new types that encapsulate both data and member functions.
  • switch: This keyword is used in the “Switch statement”.
  • template: parameterized or generic type.
  • this: A class pointer points to an object or instance of the class.
  • throw:throw: Generate an exception.
  • try: Indicates the start of a block of exception handlers.
  • typedef: Synonym for another integral or user-defined type.
  • union: Similar to a structure, struct, in that it can hold different types of data, but a union can hold only one of its members at a given time.
  • unsigned: A data type modifier that indicates the high-order bit is to be used for an object.
  • virtual: A function specifier that declares a member function of a class that will be redefined by a derived class.
  • Void: This keyword identifies the absence of a type or function parameter list.
  • volatile: This particular keyword defines an object which may vary in value in a way that is undetectable to the compiler.
  • while: This keyword helps to start a while statement and end a do-while statement
Summary

This article gives a vast overview of what is data type in C++ language including its various types. This article also covers how many keywords are in the c++ language and the function of every keyword and defines keywords in c++. With this knowledge of data types and keywords under your belt, you're well on your way to becoming a great C++ programmer!

Accept cookies & close this