+ 1

which of the following statements are correct for accessing x?and why? #include <iostream> using namespace std; class test{ public: int x=9; }; int main() { test t; test *p=&t; } select all that apply:- a) t.x b) p.x c) t->x d) p->x

24th Aug 2016, 11:09 AM
Lekhraj Singh
Lekhraj Singh - avatar
3 Réponses
+ 2
t.x p->x We use the point (.) to apply on the variable And we use (->) to apply on the address of variable the pointer Here t is the object And p is it pointer So to access it the variable x of the object t Either use pint to access the variable or (->) to access it pointer They are the same thing probably
24th Aug 2016, 11:40 AM
Raizel TheNoblesse
Raizel TheNoblesse - avatar
+ 1
thank Raizel
24th Aug 2016, 12:24 PM
Lekhraj Singh
Lekhraj Singh - avatar
+ 1
Happy to help I just hope it was useful
24th Aug 2016, 12:27 PM
Raizel TheNoblesse
Raizel TheNoblesse - avatar