Difference between 'data type' and variable?

This is a discussion on Difference between 'data type' and variable? within the C Programming forums, part of the General Programming Boards category; I was told that when I do something like Code: #include <stdio.h> typedef struct{ int fd; char d; }DIR; /*DIR ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195

    Difference between 'data type' and variable?

    I was told that when I do something like

    Code:
    #include <stdio.h>
    
     typedef struct{
       int fd;
       char d;
     }DIR;
    
    
     /*DIR *opendir(char *getname);*/
    
     int main(void) {
       return 0;
     }
    that typedefing the struct declares a new data type. I thought a data type and variable where the same thing. Apparently they aren't. What exactly is the difference between the two then?

    Chad

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    A type (or data type) defines the structure of data that will be stored in an object (variable) of that type.

    A variable is a named instance of that data type.

    In your example, DIR defines how data is stored in a variable of type DIR, but you aren't declaring any variables of that type (though you hae a commented out function prototype that returns a pointer to an object of that type.)
    Insert obnoxious but pithy remark here

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    Okay, thanks. That makes sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21