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 156 views
1 answer 165 views
165 views asked May 16, 2022 by avibootz
2 answers 181 views
181 views asked Aug 13, 2017 by avibootz
1 answer 212 views
1 answer 186 views
186 views asked Mar 7, 2020 by avibootz
3 answers 294 views
...