Use of typedef

typedef is a user-defined synonym for an existing type. To create a synonym for a type, you use the keyword typedef followed by the name of the type and the new name you are defining.


E.g. typedef unsigned int uInt; 


Here uInt will be synonym for type unsigned int. 


The following line of code actually produces an int* which is and an int (not an int*) which is y. That is, the ‘*’ binds to the right, not the left.


int * x, y; 


However, if you use a typedef:



typedef int* intPtr;
intPtr x, y;
                  
Then both x and y are of type int*.

No comments:

Post a Comment

Golang: Http POST Request with JSON Body example

Go standard library comes with "net/http" package which has excellent support for HTTP Client and Server.   In order to post JSON ...