CrazyEngineers
  • C++ Viva Questions

    Matthew08

    Matthew08

    @matthew08-Mmlanl
    Updated: Oct 22, 2024
    Views: 1.1K
    Well, today I had my C++ viva at my school..and I screwed it up!! The answers to this question which I was asked may be easy but I couldn't get it..Few questions of which I haven't got the answers yet--
    1. <a href="https://www.daniweb.com/forums/misc-explaincode.html?TB_iframe=true&height=400&width=680" target="_blank" rel="nofollow noopener noreferrer">DaniWeb-Flavored Markdown Syntax</a>
    C++ Syntax (toggle plain text)


    1. class A
    2. { public:
    3. int a;
    4. int b;
    5. };

    class A { public: int a; int b; };


    In the class A there are two public members. If a pointer is created for the object of this class, it will point to first public member of this class. How would I be accessing the next member in the following cases--
    1. if the object was static
    2. dynamic object
    3. normal object

    2. How to access any element of two dimensional array using pointers .

    3. I was also asked the output for this--
    ______________________________________________________________________________________________
    #-Link-Snipped-# | #-Link-Snipped-# | #-Link-Snipped-#
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberDec 31, 2009

    2nd question 3rd part
    whenever you create pointer to normal object
    you can access its members by using
    p->f.a;
    p->f.b;
    where p is pointer to object,,f is onject

    For 3rd question
    use this
    *(*(a + i) + j)
    to assign element to an array say 1 to s[1][1]
    then you can use
    *(*(a+1)+1)=1;
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register