pass by reference c++
C++
// C++ program to swap two numbers using
// pass by reference.
#include <iostream>
using namespace std;
void swap(int& x, int& y)
{
int z = x;
x = y;
y = z;
}
int main()
{
int a = 45, b = 35;
cout << "Before Swap\n";
cout << "a = " << a << " b = " << b << "\n";
swap(a, b);
cout << "After Swap with pass by reference\n";
cout << "a = " << a << " b = " << b << "\n";
}
// C++ program to demonstrate differences between pointer
// and reference.
#include <iostream>
using namespace std;
struct demo
{
int a;
};
int main()
{
int x = 5;
int y = 6;
demo d;
int *p;
p = &x;
p = &y; // 1. Pointer reintialization allowed
int &r = x;
// &r = y; // 1. Compile Error
r = y; // 1. x value becomes 6
p = NULL;
// &r = NULL; // 2. Compile Error
p++; // 3. Points to next memory location
r++; // 3. x values becomes 7
cout << &p << " " << &x << endl; // 4. Different address
cout << &r << " " << &x << endl; // 4. Same address
demo *q = &d;
demo &qq = d;
q->a = 8;
// q.a = 8; // 5. Compile Error
qq.a = 8;
// qq->a = 8; // 5. Compile Error
cout << p << endl; // 6. Prints the address
cout << r << endl; // 6. Print the value of x
return 0;
}
Also in C++:
- Title
- pbds in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- how print fload wiht 3 decimal in c++
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- c++ vector lower_bound index
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- insertion c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- namespace c++
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- create a bitset of 1024 bits,
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- namespaces c++
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- caesar cipher program in c++
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- E/flutter (20384): [ERROR:flutter/third_party/txt/src/minikin/FontFamily.cpp(184)] Could not get cmap table size! E/flutter (20384): F/flutter (20384): [FATAL:flutter/third_party/txt/src/minikin/FontCollection.cpp(95)] nTypefaces == 0
- Category
- C++
- Title
- length of string c++
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- error: invalid conversion from 'Node*' to 'int'
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- char size length c++
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- mysqli connect
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- how to sort an array according to another array c++
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- how to initialize an struct object in c++
- Category
- C++
- Title
- built in function in c++ for binary to decimal
- Category
- C++
- Title
- cannot jump from switch statement to this case label c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- sorting of array in c++
- Category
- C++
- Title
- maximum subarray sum in c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- Arrays hackerrank solution in c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- accept the noun and the output of plural c++
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- initialize map c++
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- array syntax in c++
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- double max value c++
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- count function c++
- Category
- C++