Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ call by reference

#include <iostream>

using namespace std;

void increment(int &n){
    n++;
   cout<<"In function: "<<n<<endl; 
}

int main()
{
   int x=5;
   increment(x);
   cout<<"In main: "<<x<<endl;
   
}
Comment

calling by reference c++

void fun2(int& a) 
{
    a = 5;
}

int main()
{
    int b = 10;
    fun2(b); 

    // now b = 5;
    return 0;
}
Comment

calling by reference c++

int main() {
    int b = 1;
    fun(&b);
    // now b = 10;
    return 0;
}
Comment

calling by reference c++

void fun(int *a)
{
   *a = 10;
}
Comment

calling by reference c++

void fun3(int a)
{
    a = 10;
}

int main()
{
    int b = 1;
    fun3(b);
    // b  is still 1 now!
    return 0;   
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ vector declaration 
Cpp :: lutris 
Cpp :: length of array in cpp 
Cpp :: run cmd command c++ 
Cpp :: indexing strings in c++ 
Cpp :: C++ Structures (struct) 
Cpp :: create copy constructor c++ 
Cpp :: for c++ 
Cpp :: how to reverse a vector 
Cpp :: c++ string size 
Cpp :: what is thread in c++ 
Cpp :: 58. Length of Last Word leetcode solution in c++ 
Cpp :: push local branch to another remote branch 
Cpp :: inline function in c++ 
Cpp :: print duplicate characters from string in c++ 
Cpp :: hexadecimal or binary to int c++ 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: float to int c++ 
Cpp :: c include 
Cpp :: how many months have 31 days 
Cpp :: c++ replace 
Cpp :: cpp lambda function 
Cpp :: print stack without pop c++ 
Cpp :: how to remove maximum number of characters in c++ cin,ignore 
Cpp :: difference between --a and a-- c++ 
Cpp :: initialize a vector to 0 
Cpp :: constructor syntax in c++ 
Cpp :: how to input in cpp 
Cpp :: convert ascii char value to hexadecimal c++ 
Cpp :: c++ class 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =