🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #80

Pass Structures


Pass Structure to a Function

You can also pass a structure to a function.

This is useful when you want to work with grouped data inside a function:

Example

struct Car {
  string brand;
  int year;
};

void myFunction(Car
c) {
  cout << "Brand: " << c.brand << ", Year: " << c.year << "\n";
}

int main() {
  Car myCar = {"Toyota", 2020};

myFunction(myCar);
  return 0;
}

Note: Since the structure is passed by value, the function gets a copy of the structure.

This means that the original data is not changed.


Pass by Reference

You can also pass a structure by reference, using &.

This allows the function to modify the original data:

Example

struct Car {
  string brand;
  int year;
};

void updateYear(Car &c) {

c.year++;
}

int main() {
  Car myCar = {"Toyota", 2020};

updateYear(myCar);
  cout << "The " << myCar.brand << " is now from
year " << myCar.year << ".\n";
  return 0;
}

Tip: Use reference if you want the function to change the structure's data, or to avoid copying large structures.

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Pass Structures – FAQs

Quick answers about learning Pass Structures in C++.

This free note from CodingNow 2.0 explains Pass Structures in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including Pass Structures, is 100% free with no signup required.
With focused practice, most students grasp Pass Structures in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now