Předávání a vracení polí z funkcí

{“https:\/\/www.jdoodle.com\/a\/8Os?format=text”:”#include <iostream>\nusing namespace std;\n\n\/\/ Form\u00e1ln\u00ed parametr pole pomoc\u00ed ukazatele\nint sumArray1(int* p, int count) {\n int sum = 0;\n for(int i = 0; i < count; i++) {\n sum += p[i];\n }\n return sum;\n}\n\n\/\/ Form\u00e1ln\u00ed parametr pole pomoc\u00ed deklarace pole\nint sumArray2(int p[], int count) {\n int sum = 0;\n for(int i = 0; i < count; i++) {\n sum += p[i];\n }\n return sum;\n}\n\n\/\/ Form\u00e1ln\u00ed parametr pole pomoc\u00ed deklarace pole s jeho velikost\u00ed\nint sumArray3(int p[5], int count) {\n int sum = 0;\n for(int i = 0; i < count; i++) {\n sum += p[i];\n }\n return sum;\n}\n\nint main() {\n const int count = 10;\n int array[count] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n \n cout << "Sou\u010det hodnot v poli je " << sumArray1(array, count) << endl;\n cout << "Sou\u010det hodnot v poli je " << sumArray2(array, count) << endl;\n cout << "Sou\u010det hodnot v poli je " << sumArray3(array, count) << endl;\n}\n”,”https:\/\/www.jdoodle.com\/a\/8Ov?format=text”:”#include <iostream>\nusing namespace std;\n\nint* getArray() {\n static int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n return array;\n}\n\nvoid printField(int index) {\n cout << "Hodnota na indexu " << index << " je " << getArray()[index] << endl;\n}\n\nint main() {\n printField(4);\n getArray()[4] = 100;\n printField(4);\n}”}


Předávání a vracení polí z funkcí
Ohodnoťte tento článek