Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
typedef is a way of making up your own data type names. For example, instead of:
int i;
short s;you could have:
typedef int myInt;
typedef short myShort;myInt i;
myShort s;i and s are exactly the same in both instances. You've just defined a new data type names. A more useful example might be:
typedef unsigned char bit8;
typedef unsigned short bit16;
typedef unsigned long bit32;bit8 smallCount;
bit32 largeCount;
How about a type name for a structure. Instead of:struct person {
char name[50];
short age;
short height;
};struct person me;
struct person you;
struct person *personPointer;You could have:
typedef struct Person {
char name[50];
short age;
short height;
};
Person me;
Person you;
Person *personPointer;

Thanks! It was a great help. I am only used to Java. Just starting to learn C and found these struct and typedef different from Java!
thanks!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |