calling by reference c++
C++
//call by reference example c++
#include <iostream>
using namespace std;
void swap(int& x, int& y) {
cout << x << " " << y << endl;
int temp = x;
x = y;
y = temp;
cout << x << " " << y << endl;
}
int main() {
int a = 7;
int b = 9;
swap(a, b);
}
void fun3(int a)
{
a = 10;
}
int main()
{
int b = 1;
fun3(b);
// b is still 1 now!
return 0;
}int main() {
int b = 1;
fun(&b);
// now b = 10;
return 0;
}void fun2(int& a)
{
a = 5;
}
int main()
{
int b = 10;
fun2(b);
// now b = 5;
return 0;
}void fun(int *a)
{
*a = 10;
}
Also in C++:
- Title
- how to convert string to int c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- mark occurances of elements in array cpp
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- UPARAM(ref)
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- c++ cout int
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- transpose matrix eigen c++
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- add a timer c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- c++ variable arguments
- Category
- C++
- Title
- max element in array c++ stl
- Category
- C++
- Title
- arduino delay millis
- Category
- C++
- Title
- set c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- range of long long in c++
- Category
- C++
- Title
- c++ server service ros
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- c++ how to make a negative float positive
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- binary tree deletion
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- level order traversal
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- c++ get ascii value of char
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- Rectangle area hackerrank solution in c++
- Category
- C++
- Title
- ue4 c++ overlapping functions cpp setup
- Category
- C++
- Title
- c++ reverse vector
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- split 2d array into chunks in c++
- Category
- C++
- Title
- how to get input from the console in c++
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- mkdir boost filesystem
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- intersection between vector c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- matrix multiplication c++ eigen
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- ceil c++;
- Category
- C++
- Title
- runtime array size c++
- Category
- C++