Thread: Hazzy on Structures

  1. #1
    Registered User
    Join Date
    Mar 2003

    Thumbs up Hazzy on Structures

    First off HI!
    I am learning structures right now in my programming journey, and i find them easy enought to understand but i just can't figure out what advantages it has. i know you can store definitions under one name etc. So what? i can just create those variables seperately. I will probably have alot easier time working with them if i understood their advantages over just created seperate variables.
    So can someone just expand or explain them to me. thanks
    #include <Jesus.h>
    It will save your life

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    c++ is a language that works on types.
    If the language doesnt provide a type that does what you need then you use the tools of the language to create a new type that does. These tools are structs and classes. Dont worry too much about it now but rest assured once you see classes you will understand structs. A struct is the same as a class in c++ but with one small difference, its default access is public instead of private.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    #include <Jesus.h>
    Would that be "Jesus H. Christ"? LMFAO.

    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Feb 2003
    The way my teacher explained it long ago, is that it helps in sorting and searching and what not. Say you have a structure that has 5 fields, name, address, etc. etc. etc., and you want to sort it by name..if you had an array for 5 names, addresses etc., you had to move each field if you had a structure with the 5 fields, all you would do is compare the .name part of the structure, and you can move it around like so, without having to hassle moving around each field.....hope this makes sense

  5. #5
    Registered User
    Join Date
    Feb 2003
    I don't know how much structs would help with sorting. I think it would be the same as with an array. But I agree with Stone_Coder in that you should just wait and live with them for now. Once you get in to classes and inheritance, etc..., then it'll make sense why they exist. But another benefit to having structures is when you're dealing with things like records. Lets say you want to set up a directory. You could have an array of structures, each element containing name, address, phonenumber, etc... and all these elements would be linked to each other through the structure. Also when you get into linked lists, which are also very powerful, you will see why structs exist. Hope this helps a bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  3. Classes and Structures.
    By jrahhali in forum C++ Programming
    Replies: 6
    Last Post: 03-28-2004, 05:03 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM