Help with Structures!

This is a discussion on Help with Structures! within the C++ Programming forums, part of the General Programming Boards category; I am new to the world of structures and pointers, and was trying to use a modified version of the ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Question Help with Structures!

    I am new to the world of structures and pointers, and was trying to use a modified version of the program example given in the structures tutorial. Every time I try to run it, it crashes. Any advice?

    Code:
    #include <iostream>
    
    using namespace std;
    
    struct database
    {
        int id_number;
        int age;
        float salary;
    };
    
    int main()
    {
        database employee;
        database *ptr,*ptr1,*ptr2;
    
        employee.age=28;
        employee.id_number=1;
        employee.salary=12000.21;
    
        cout<<ptr->age;
        cout<<ptr1->id_number;
        cout<<ptr2->salary;
    
        cin.get();
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    You appear to have forgotten to initialise ptr, ptr1 and ptr2. You presumably want then to point to employee.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Talking oh!

    Oh! I see...stupid mistake on my part. Thank you very much for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Nested Structures and Arrays of Structures
    By Ignoramus in forum C Programming
    Replies: 4
    Last Post: 03-02-2010, 12:24 AM
  2. Structures and dynamically allocated arrays
    By Bandizzle in forum C Programming
    Replies: 7
    Last Post: 10-04-2009, 02:05 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Structures, and pointers to structures
    By iloveitaly in forum C Programming
    Replies: 4
    Last Post: 03-30-2005, 05:31 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

Tags for this Thread


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