Possible en double:
Confusion over C++ pointer and reference topicArray/pointeur/référence confusion
Supposons que je passe
int arr[10];
en tant que paramètre à une fonction.
Tous ces prototypes de fonctions sont-ils valides? En quoi diffèrent-ils en termes d'arguments et pourquoi?
C'est ce que je sais à ce jour (pas sûr si elle est correcte ou non)
1. void foo(int &arr); //a reference to an array, which preserve the size attribute?
2. void foo(int &arr[]); //the same (is it)?
3. void foo(int (&arr)[]); //I don't know
4. void foo(int &arr[10]); //is it the same as 2?
5. void foo(int (&arr)[10]);//no idea
6. void foo(int *arr); //a decayed pointer of the array, pointing to the first element of the array, losing the size attribute?
7. void foo(int *arr[]); //the same (is it?)
8. void foo(int (*arr)[]); //a pointer to an array, preserve the size
9. void foo(int *arr[10]); //the same as 7 (is it?)
10. void foo(int (*arr)[10]);//is the same as 8 (is it?)
11. void foo(int arr[]); //is the same as 6 (is it?)
12. void foo(int arr[10]); // is the same as 6 (is it?)
(Je sais que cela aura besoin d'une longue explication, désolé, je suis totalement confus ...)
Pourquoi vous ennuyez-vous? Est-ce que ce sont les devoirs? – fredoverflow
Vérifiez la parenthèse fermante dans votre code ...vous êtes absent beaucoup d'entre eux –
Je suis juste curieux, et non ce n'est pas un devoir – Chin