How to use pointer to struct in C++

1 Answer

0 votes
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

struct user {
	string name;
	int age;
};

int main()
{
	user u;
	user *pu;
	pu = &u;

	pu->name = "Blaire";
	pu->age = 47;

	cout << pu->name << " " << pu->age << endl;

	return 0;
}

/*
run:

Blaire 47

*/

 



answered May 24, 2018 by avibootz

Related questions

2 answers 152 views
1 answer 160 views
160 views asked May 16, 2022 by avibootz
2 answers 175 views
175 views asked Aug 13, 2017 by avibootz
1 answer 209 views
1 answer 183 views
183 views asked Mar 7, 2020 by avibootz
3 answers 281 views
...