Write a function getNeighbors which will accept an integer array, size of the array and an index as parameters. This function will return a new array of size 2 which stores the neighbors of the value at index in the original array. If this function would result in returning garbage values the new array should be set to values {0,0} instead of values from the array.

icon
Related questions
Question
Write a function getNeighbors which will accept an integer array, size of the array and an index as
parameters. This function will return a new array of size 2 which stores the neighbors of the value at index
in the original array. If this function would result in returning garbage values the new array should be set
to values {0,0} instead of values from the array.
Transcribed Image Text:Write a function getNeighbors which will accept an integer array, size of the array and an index as parameters. This function will return a new array of size 2 which stores the neighbors of the value at index in the original array. If this function would result in returning garbage values the new array should be set to values {0,0} instead of values from the array.
int main() {
std::cout << std::endl;
35
00
const int SIZE = 5;
int a[SIZE] = {1,2,3,4,5);
int *b = getNeighbors (a, SIZE, 3);
print (b, 2);
int *c = getNeighbors (a, SIZE, 0);
print (c, 2);
std::cout << std::endl;
return 0;
Example Output
Transcribed Image Text:int main() { std::cout << std::endl; 35 00 const int SIZE = 5; int a[SIZE] = {1,2,3,4,5); int *b = getNeighbors (a, SIZE, 3); print (b, 2); int *c = getNeighbors (a, SIZE, 0); print (c, 2); std::cout << std::endl; return 0; Example Output
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer