difference b/w structures in c and c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sowmyth
    New Member
    • Oct 2006
    • 19

    difference b/w structures in c and c++

    can anybody tell me the difference between structures in c and structures in
    c++?
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by sowmyth
    can anybody tell me the difference between structures in c and structures in
    c++?
    in C and C++ you can create composite data types with struct
    Code:
    struct Student {                       
                    char name[20];            // student name 
                    int age;                   // student age 
                    int course_code;        // institutions course code 
                    int course_year;        // year of course 
                    };
    a struct can only contain data members.
    In C++ the aggregate type class (an extension of the idea of struct) enables users to define their own types each of which is an encapsulation of:
    (a) data members (fundamental types and derived types, e.g. arrays, structures, classes, etc.),
    and (b) function and operator members which operate upon the data.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by sowmyth
      can anybody tell me the difference between structures in c and structures in
      c++?
      You have to use typedef in C or else you define your structures using
      struct MyStructure s; but in C++ you can jusy say MyStructure s;

      Comment

      • LSB
        New Member
        • Jan 2007
        • 8

        #4
        In C: structure is just data container.

        In C++: structure is almost identical to class. There is only one difference between structure and class in C++ : data members in structure are by default public, and in class they are by default private.

        Thanks.

        Comment

        Working...