Типови податоци во C++

 Статички и динамички типови 






  1. Линеарно подредени

- целобројни  ( integer – int              )

- знаковни      (character – char         )

- логички         (boolean – bool           )

- наброиви      (enumerated – enum )



  1.  Линеарно неподредени

Реални 





// Demonstrates typedef keyword
#include <iostream>
using namespace std;

typedef unsigned short int USHORT; //typedef defined

int main()
{
USHORT Width = 5;
USHORT Length;
Length = 10;
USHORT Area = Width * Length;
cout << "Width:" << Width << "\n";
cout << "Length: " << Length << endl;
cout << "Area: " << Area <<endl;
}


Output: 
Width:5
Length: 10
Area: 50



Data Types in C++ are Mainly Divided into 3 Types: 

1. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char, float, bool, etc. Primitive data types available in C++ are: 

  • Integer
  • Character
  • Boolean
  • Floating Point
  • Double Floating Point
  • Valueless or Void
  • Wide Character

2. Derived Data Types: Derived data types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types. These can be of four types namely: 

  • Function
  • Array
  • Pointer
  • Reference

3. Abstract or User-Defined Data TypesAbstract or User-Defined data types are defined by the user itself. Like, defining a class in C++ or a structure. C++ provides the following user-defined datatypes:  

  • Class
  • Structure
  • Union
  • Enumeration
  • Typedef defined Datatype

Primitive Data Types

  • Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory space and range from -2147483648 to 2147483647.  
  • Character: Character data type is used for storing characters. The keyword used for the character data type is char. Characters typically require 1 byte of memory space and range from -128 to 127 or 0 to 255.  
  • Boolean: Boolean data type is used for storing Boolean or logical values. A Boolean variable can store either true or false. The keyword used for the Boolean data type is bool
  • Floating Point: Floating Point data type is used for storing single-precision floating-point values or decimal values. The keyword used for the floating-point data type is float. Float variables typically require 4 bytes of memory space. 
  • Double Floating Point: Double Floating Point data type is used for storing double-precision floating-point values or decimal values. The keyword used for the double floating-point data type is double. Double variables typically require 8 bytes of memory space. 
  • void: Void means without any value. void data type represents a valueless entity. A void data type is used for those function which does not return a value. 
  • Wide CharacterWide character data type is also a character data type but this data type has a size greater than the normal 8-bit data type. Represented by wchar_t. It is generally 2 or 4 bytes long.
  • sizeof() operator: sizeof() operator is used to find the number of bytes occupied by a variable/data type in computer memory.

No comments: