Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
C++ provides multiple ways to pass data to functions. Choosing the right method is critical for performance and correctness.
void func(int x)Passes a COPY of the actual value. Changes inside don't affect original.
void func(int &x)Passes an ALIAS to the original variable. Changes DO affect original.
void func(int *x)Passes the ADDRESS of the variable. Changes DO affect original.
Always pass large objects (like std::vector or std::string) by const reference to avoid expensive copies.
void process(const vector<int>& vec);