C++20 sections · 1024 units
Open in Course

Modifying Members

Updating struct values

Modify struct members the same way you modify regular variables. Access with the dot operator, then assign new values. The syntax is exactly what you expect. Example: Point p; p.x = 5; p.y = 10; creates a Point and sets coordinates.

Later change them: p.x = 100;. The member x updates, y stays the same. You can read, modify, pass to functions, anything you do with normal variables. p.x++ increments x. p.y *= 2 doubles y.

Members behave like they always did.