·  C++ – Syntax – Variables – char

 

- Info:

  - This tutorial shows how to create char and convert it to other Primitive Types.

 

- Procedure:

  - Create C++ Console Application Test.cpp.

 

    Test.cpp

    #include <iostream>

    using namespace std;

   

    int main() {

   

      //CREATE.------------------------------------------------------------------------

      char   value    = 'A';

             value    =  65;    //Decimal     ASCII value.

             value    = 0101;   //Octal       ASCII value.

             value    = 0x41;   //Hexadecimal ASCII value.

   

      //CONVERT.-----------------------------------------------------------------------

      short  toShort  = value;

      int    toInt    = value;

      long   toLong   = value;

      float  toFloat  = value;

      double toDouble = value;

      cout << value << " " << toInt << " " << toFloat << endl;

   

      //DISPLAY.-----------------------------------------------------------------------

      cout << value << " " << (int) value;

   

      return 0;

      

    }