calling by reference and pointers c++
C++
#include <iostream>
using namespace std;
// Function prototype
void swap(int&, int&);
int main()
{
int a = 1, b = 2;
cout << "Before swapping" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
swap(a, b);
cout << "\nAfter swapping" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
return 0;
}
void swap(int& n1, int& n2) {
int temp;
temp = n1;
n1 = n2;
n2 = temp;
}#include <iostream>
using namespace std;
// Function prototype
void swap(int*, int*);
int main()
{
int a = 1, b = 2;
cout << "Before swapping" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
swap(&a, &b);
cout << "\nAfter swapping" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
return 0;
}
void swap(int* n1, int* n2) {
int temp;
temp = *n1;
*n1 = *n2;
*n2 = temp;
}
Also in C++:
- Title
- disjoint set code in c++
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- inconsequential meaning
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- select elements from array C++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- apple and orange hackerrank solution in c++
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- c++ vector lower_bound index
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- sqrt in c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- c++ initialize array
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- c++ for loops
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- how to output to console c++
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- Create a program that finds the minimum value in these numbers
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- initialising 2d vector
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- c++ get type name of object
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- how to write an or in c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- how to grab all of user input c++
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- how to initialize an struct object in c++
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- c++ delet from memory
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- cout value c++
- Category
- C++