C structure differs from CPP class in regards by default all members of structure are public in nature

Q.  C structure differs from CPP class in regards that by default all the members of the structure are __________ in nature.
- Published on 17 Jul 15

a. private
b. protected
c. public
d. None of these

ANSWER: public
 

    Discussion

  • Raj Singh   -Posted on 08 Oct 15
    All the members in structure are by default public but in class it is private.
    Example:
    class myClass
    {
    int rollNo // By default rollNo and name are private data member.
    char name[10];
    public:
    void getdata()
    {
    // implementation here.
    }
    }

    Structure example:
    struct person {
    char name[40]; // By default all data member are public.
    int age;
    float salary;
    };

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)