# S.O.S. Mathematics CyberBoard

Your Resource for mathematics help on the web!
 It is currently Fri, 24 May 2013 11:48:23 UTC

 All times are UTC [ DST ]

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Help with C pleasePosted: Fri, 13 May 2005 15:28:53 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sun, 6 Jul 2003 07:53:15 UTC
Posts: 409
Location: Melbourne, Australia
I just have a quick question about C. I don't understand the primary purpose of 'typedef'. I have read my textbook but I still don't have a clear idea as to what typedef does. From what I gather(in my book typedef is introduced in the context of arrays), typedef defines a type and acts as a kind of definition shortcut in programs. That's all I (think)understand about it. Can someone please give me an explanation. I'm finding it to be quite difficult to understand and make use of - even after having read my textbook a few times.

Top

 Post subject: Posted: Fri, 13 May 2005 17:58:09 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Thu, 9 Oct 2003 08:09:39 UTC
Posts: 1631
If I recall correctly, typedef is basically a way for you to define something that is very long to type. That way once you defined it by typedefing it, you won't have to type that same long thing over and over again. It's used in creating structs, say if your struct is very huge (30+ members). Do you really want to type that all over your code?

Top

 Post subject: Posted: Fri, 13 May 2005 18:48:56 UTC
Put simply, typedef is just a way to create a new data type name. As Corneo said, this is useful with structs:

Code:
typedef struct { int age; char* name } person;

Remember by default structs have public access so:

Code:
person a;
a.age = 19;

would create me... and so on, you get it.

Top

 Post subject: Posted: Fri, 13 May 2005 18:52:14 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Wed, 1 Oct 2003 04:45:43 UTC
Posts: 9633
Corneo wrote:
If I recall correctly, typedef is basically a way for you to define something that is very long to type.

Another use for typedef is to define mnemonics for the standard data types. For example, you might do:

Code:
typedef unsigned int natural;

or

Code:
typedef double real;

Then in your code, you could write things like:

Code:
real x, y;
natural m, n;

which is easier to read, I suppose.

Top

 Post subject: Posted: Sat, 14 May 2005 06:39:37 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sun, 6 Jul 2003 07:53:15 UTC
Posts: 409
Location: Melbourne, Australia
Thanks for the help. So for your example if say I wrote 'real g' then the compiler would take that 'g' as a variable of type double?

Top

 Post subject: Posted: Sat, 14 May 2005 07:45:23 UTC
yes.

Top

 Post subject: Posted: Sat, 14 May 2005 09:40:25 UTC
 Member of the 'S.O.S. Math' Hall of Fame

Joined: Sun, 6 Jul 2003 07:53:15 UTC
Posts: 409
Location: Melbourne, Australia
Thanks GOD.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 7 posts ]

 All times are UTC [ DST ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ High School and College Mathematics    Algebra    Geometry and Trigonometry    Calculus    Matrix Algebra    Differential Equations    Probability and Statistics    Proposed Problems Applications    Physics, Chemistry, Engineering, etc.    Computer Science    Math for Business and Economics Advanced Mathematics    Foundations    Algebra and Number Theory    Analysis and Topology    Applied Mathematics    Other Topics in Advanced Mathematics Other Topics    Administrator Announcements    Comments and Suggestions for S.O.S. Math    Posting Math Formulas with LaTeX    Miscellaneous