Wednesday, September 12, 2012

Program to illustrate 'typedef' keyword

#include <iostream>
using std::cout;
using std::endl;

typedef float FLOAT32;
typedef double FLOAT64;     //
By using typedef Keyword we can make alias of datatypes
typedef unsigned int U32;    //it is something like macro

int main()
{
    U32 bigint = 23433;
    FLOAT32 myFloat = 6.6;
    FLOAT64 myDouble = 34343.3;
   
    cout << "  bigint: " << bigint;
    cout << "\n myFloat: " << myFloat;
    cout << "\nmyDouble: " << myDouble;
}


what is typedef:
typedef is a keyword in the C and C++ programming languages. The purpose
of typedef is to assign alternative names to existing types

what is the use of typedef keyword:

1) it provides a means to make a program more portable. Instead of having to
    change a type everywhere it appears throughout the program's source 

    files, only a single typedef statement needs to be changed.
2) A typedef can make a complex declaration easier to understand. 


By using typedef Keyword we can make alias of datatypes

No comments:

Post a Comment