Thread: Structure question

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    15

    Structure question

    Code:
    struct address {
        int street_no;
        char *street_name;
        char *city;
        char *prov;
        char *postal_code;
        };
    Code:
    struct address{
       int street_no;
       char street_name[20];
       char city[20];
       char prov[20];
      char postal_code[20];
    };
    What is the difference between the two declerations??
    Can the pointer variable be something other than char ?? like (int,float,double)??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The difference between them is that in the second case, the storage for the strings is provided in the struct itself; in the first case, all you have is a pointer and for every address you must malloc (or otherwise provide) storage space for the strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  2. Simple C# structure question
    By sketch in forum C# Programming
    Replies: 4
    Last Post: 09-14-2007, 04:29 PM
  3. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2004, 12:56 AM
  4. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM
  5. structure question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 09:04 PM