#include<iostream>
usingnamespace std;
struct date
{
int d=12;
int m=13;
int y=14;
};
date s;
date *dob;
int main()
{
cout<<"Output using structure variable"<<endl;
cout<<s.d<<s.m<<s.y<<endl;
cout<<"Output using structure pointer"<<endl;
cout<<dob->d<<dob->m<<dob->y<<endl;
return 0;
}
#include<iostream>
usingnamespace std;
struct date
{
int d=12;
int m=13;
int y=14;
};
date s;
date *dob;
dob=&date;
int main()
{
cout<<"Output using structure variable"<<endl;
cout<<s.d<<s.m<<s.y<<endl;
cout<<"Output using structure pointer"<<endl;
cout<<dob->d<<dob->m<<dob->y<<endl;
return 0;
}
I'll ask the same question as I asked in your other thread - do you actually understand what a pointer is?
If not, your time would be better spent reading your textbook to get an understanding of them, rather than randomly writing code you don't understand, to see if it works.
dob=&date;
makes no sense. date is a type, not an object.
#include<iostream>
usingnamespace std;
struct date
{
int d=12;
int m=13;
int y=14;
};
date s;
date *dob=&s;
int main()
{
cout<<"Output using structure variable"<<endl;
cout<<s.d<<s.m<<s.y<<endl;
cout<<"Output using structure pointer"<<endl;
cout<<dob->d<<dob->m<<dob->y<<endl;
return 0;
}
#include<iostream>
usingnamespace std;
struct date
{
int d=12;
int m=13;
int y=14;
};
date s;
date *dob=new date;
int main()
{
cout<<"Output using structure variable"<<endl;
cout<<s.d<<s.m<<s.y<<endl;
cout<<"Output using structure pointer"<<endl;
cout<<dob->d<<dob->m<<dob->y<<endl;
return 0;
}
Yes, but a very important difference is that in the first version, s and *dob are the same object, whereas in the second version, they are different objects.