Computing.Net > Forums > Programming > C Language: typedef

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C Language: typedef

Reply to Message Icon

Name: Ken
Date: May 16, 2002 at 13:28:19 Pacific
Comment:

Hi,

Can anyone please describe what does typedef represent in C?

thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: May 16, 2002 at 16:24:34 Pacific
Reply:

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;


0

Response Number 2
Name: Ken
Date: May 17, 2002 at 06:41:06 Pacific
Reply:

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!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C Language: typedef

Classes : Basic - C Language www.computing.net/answers/programming/classes-basic-c-language/11058.html

Printer programming using C language www.computing.net/answers/programming/printer-programming-using-c-language/2003.html

make folder with C language www.computing.net/answers/programming/make-folder-with-c-language/488.html