Is there any difference if i pass int **a
in any function and at same place i pass int& a
, will both create any difference?. Ex
Bool issafe(int**arr, intx, int y)
Bool issafe(int& arr, intx, int y)
There is a lot of difference between the '*' notation and '&' notation.
Let us have a look at what both mean, in a general sense and little bit of technical detail.
&x
simply means Address of x . It will be a an address value, often represented in hexadecimal notation.
It is often used to pass by reference in functions: func(int &x, char a);
This will pass x
by reference, but a
by value.
*p
means Pointer to a memory address . We may assign an address to this pointer using the following format:
int *p = x
or
int *p; p = &x
Once the pointer is pointing to an address, *p
and x
can be used interchangeable through the rest of the program.
Usage of **
occurs when we need a pointer to a pointer.
For example, if we need to make aa 2D Array, we can use the **
notation.
One pointer points to the first element of the first row in the matrix, while the other pointer points to the first row in the list of rows .
Thus, to answer your question in a few conclusive words: Yes, there is a big difference in int ** a
and int & a
, so much so that they go one level beyond being opposites like *
and &
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.