Metody vracení hodnot z funkce

{“https:\/\/www.jdoodle.com\/a\/8GF?format=text”:”#include <iostream>\nusing namespace std;\n\nint pole[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n\nint* getValuePtr(int index) {\n return pole + index;\n}\n\nint& getValueRef(int index) {\n return pole[index];\n}\n\nint main() {\n cout << "Pole[3] je " << *getValuePtr(3) << endl;\n cout << "Pole[7] je " << getValueRef(7) << endl;\n\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/8Gq?format=text”:”#include <iostream>\nusing namespace std;\n\nint* getValuePtr(int index) {\n static int pole[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n return pole + index;\n}\n\nint& getValueRef(int index) {\n static int pole[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n return pole[index];\n}\n\nint main() {\n cout << "Pole[3] je " << *getValuePtr(3) << endl;\n cout << "Pole[7] je " << getValueRef(7) << endl;\n\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/8GM?format=text”:”#include <iostream>\nusing namespace std;\n\nint& getValueRef(int index) {\n static int pole[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};\n return pole[index];\n}\n\nvoid printArrayValue(int index) {\n cout << "Hodnota na indexu " << index << " je " << getValueRef(index) << endl;\n}\n\nvoid swapIndexes(int index1, int index2) {\n int tmp = getValueRef(index1);\n getValueRef(index1) = getValueRef(index2);\n getValueRef(index2) = tmp;\n}\n\nint main() {\n printArrayValue(3);\n printArrayValue(6);\n \n swapIndexes(3, 6);\n cout << endl;\n \n printArrayValue(3);\n printArrayValue(6);\n \n return 0;\n}”}


Metody vracení hodnot z funkce
Ohodnoťte tento článek