Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What does this typedef line

  1. Oct 24, 2008 #1
    first i create this structure :

    Code (Text):

    struct album {
      char *name;
      char *artist;
      int numTracks;
    if i want my variables not to be global
    i can write this inside main:

    struct album CD1, CD2, CD3;

    typedef struct album Album;

    ... then inside main:

    Album CD1, CD2, CD3;

    i cant understand this last part regarding where to write the typedef line

    and what is the role of type of typedef?
  2. jcsd
  3. Oct 24, 2008 #2
    typedef allows you to use different identifiers to reference data types.

    Code (Text):

    typedef unsigned short USHORT
    typedef unsigned long  ULONG
    typedef unsigned int    UINT

    int main()
        USHORT myShort = 5;
        ULONG   myLong = 10;
        UINT     sum = myShort+myLong;
        return 0;
    typedefs should be used before the procedure definitions.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook