C++ data types

C++ Data types

basic data types in c++

1. Enumerated Data type( click here to Learn)

2. Structure and classes( click here to Learn)

3. Array( click here to Learn)

4. Function( click here to Learn)

5. Pointers( click here to Learn)

6. References( click here to Learn)

C language and c++ languages both support all the build-in data types. with the exception of void , and the basic data type may have several modifiers preceding them to serve the needs of various situation. The unsigned signed, short ,long and may be applied to character and integer(or use with character or integer) basic data types. However, the modifier long may also be applied to double. and Data type represent is machine specific in c++ programming.

In the below table show list all combinations of the basic data data types and modifiers along with their size and range for a 16 bit machine.

char 1 -128 to 127
unsigned char 1 0 to 255
signed char 1 -128 to 127
int 2 -32768 to 32767
unsigned int 2 0 to 65535
signed int 2 -31768 to 32767
short int 2 -31768 to 32767
unsigned short int 2 0 to 65535
signed short int 2 -31768 to 32767
long int 4 -2147483648 to 2147483647
signed long int 4 -2147483648 to 2147483647
unsigned long int 4 0 to 4294967295
float 4 3.4E-38 to 3.4E+38
double 8 1.7E-308 to 1.7E+308
long double 10 3.4E-4932 to 1.1E+4932

talk about void some the type void was introduced in ANSI C Language. two normal uses of void are

1. To specify the Return type of a function or from a function when it is not returning any value 2. To indicate an empty argument list or parameters to a function

example void function(void);

Another important use of void is in when the declaration of generic pointers, Example void *gp; //gp becomes generic pointer

so A generic pointer can be assigned a pointer value of any basic data type, but also it may not be dereferenced , lets see in example

int *iptr; // int pointer
gp=iptr; // assign int pointer to void pointer

are valid statements ,but the invalid statements are

iptr=*gp;

it is illegal, it would not make sense to dereference a pointer to a void value

Assigning any pointer type to a void pointer without using a cast is allowed in both c++ and C programming, we can also assign a void pointer to a non void pointer without using a cast to a non void pointer type. but This is not allowed in c++ programming, for example

void *ptr1;
char *ptr2;
ptr2=ptr1;

These statements are valid in ANSCII C but not in C++, so A void pointer cannot be directly assign to other type pointer in c++, then in this condition

we need to use a cast operator as shown below

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise