Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of *& and **& in C++

I found these symbols in a function declaration several times, but I don't know what they mean.

Example:

void raccogli_dati(double **& V, double **p, int N) {    int ultimo = 3;    V = new double * [N/2];    for(int i=0; i < N/2; i++) {      V[i] = new double[N/2], std :: clog << "digita " << N/2 - i                  << " valori per la parte superiore della matrice V: ";      for(int j=i; j < N/2; j++)        std :: cin >> V[i][j], p[ultimo++][0] = (V[i][j] /= sqrt(p[i][0]*p[j][0]));   }    for(int i=1; i < N/2; i++)      for(int j=0; j < i; j++)         V[i][j] = V[j][i]; } 
like image 520
sdffadsf Avatar asked Apr 26 '11 11:04

sdffadsf


People also ask

What is the meaning of & *?

The word ampersand is a mix of Latin and English and a condensed version of the phrase "and per se and," which means "(the character) '&' by itself is 'and'." Definitions of ampersand. a punctuation mark (&) used to represent conjunction (and) type of: punctuation, punctuation mark.

What does * * * mean in texting?

Asterisk. Meaning: You're afraid the person isn't as cool as you. The main reason people use asterisks in a text is to censor a word, for example: "I like deep-fried sandwiches so my friends call me the C*** of Monte Cristo. Little do they know I'm plotting my elaborate revenge on them."

What does an asterisk mean in texting?

Word forms: asterisks An asterisk is the sign *. It is used especially to indicate that there is further information about something in another part of the text.

What is the meaning of UwU?

Uwu is an emoticon depicting a cute face. It is used to express various warm, happy, or affectionate feelings. A closely related emoticon is owo, which can more specifically show surprise and excitement. There are many variations of uwu and owo, including and OwO, UwU, and OwU, among others.


2 Answers

That is taking the parameter by reference. So in the first case you are taking a pointer parameter by reference so whatever modification you do to the value of the pointer is reflected outside the function. Second is the simlilar to first one with the only difference being that it is a double pointer. See this example:

void pass_by_value(int* p) {     //Allocate memory for int and store the address in p     p = new int; }  void pass_by_reference(int*& p) {     p = new int; }  int main() {     int* p1 = NULL;     int* p2 = NULL;      pass_by_value(p1); //p1 will still be NULL after this call     pass_by_reference(p2); //p2 's value is changed to point to the newly allocate memory      return 0; } 
like image 61
Naveen Avatar answered Nov 05 '22 05:11

Naveen


First is a reference to a pointer, second is a reference to a pointer to a pointer. See also FAQ on how pointers and references differ.

void foo(int*& x, int**& y) {     // modifying x or y here will modify a or b in main }  int main() {     int val = 42;     int *a  = &val;     int **b = &a;      foo(a, b);     return 0; } 
like image 35
Cat Plus Plus Avatar answered Nov 05 '22 03:11

Cat Plus Plus