About typedef

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bindiya182003
    New Member
    • Oct 2007
    • 16

    About typedef

    Can anyone tell me the use of typedef in C
    What will this statement do:

    typedef unsigned char byte;

    plz help me......
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by bindiya182003
    Can anyone tell me the use of typedef in C
    What will this statement do:

    typedef unsigned char byte;

    plz help me......
    Think of an ordinary variable definition; e.g.

    [code=c]
    int i;
    char* p;
    [/code]

    This defines two variables 'i' and 'p'. Now prepend them with the 'typedef' keyword:

    [code=c]
    typedef int i;
    typedef char* p;
    [/code]

    Now you have to aliases 'i' and 'p' for the typed 'int' and 'char*' so you may now
    use them as:

    [code=c]
    i ii; // an int
    p pp; // a char*
    [/code]

    kind regards,

    Jos

    Comment

    • bindiya182003
      New Member
      • Oct 2007
      • 16

      #3
      Thanks a lot for your answer...One more doubt How are the datatypes char and unsigned char different

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by bindiya182003
        Thanks a lot for your answer...One more doubt How are the datatypes char and unsigned char different
        I already answered that question in your other thread.

        kind regards,

        Jos

        Comment

        Working...