C++ Viva Questions

Matthew08

Matthew08

@matthew08-Mmlanl Oct 22, 2024
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-#

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Dec 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;