0

What's the problem here

Greetings coders, I've created a traversal code but it isn't working and error is hiting. Kindly check my code and let me know how can I solve this error. Thank you in advance! https://code.sololearn.com/cD6VgNwoX0IQ/?ref=app

25th Aug 2022, 3:34 AM
Adarsh Addee
Adarsh Addee - avatar
3 Antworten
+ 6
you declared display function that accepts two integers: void display(int arr, int size) but you're passing an interger array and an integer: display(arr, size); so it complains about it. you can either declare the display function as: void display(int arr[], int size) or void display(int *arr, int size) also: function main lacking it's pharanteses (). with an array the last index is array size - 1 because indexes start from 0 (in this case 4, that is 0 to 4 which are 5 elements) so you need to discard the '=' and use '<' comparison operator. all together: void display(int arr[], int size){ for(int i = 0; i < size; i++){ printf("%d ", arr[i]); } } int main(int argc, char *argv[]){ int arr[] = {1, 3, 5, 7, 9}; int size = sizeof(arr)/sizeof(arr[0]); display(arr, size); return 0; } what I added to main as arguments are not mandatory yet it's strongly advised.
25th Aug 2022, 4:28 AM
Tina
Tina - avatar
+ 1
25th Aug 2022, 9:41 AM
Adarsh Addee
Adarsh Addee - avatar
0
Charlotte Whitehead Problem is solved now. You can check it
25th Aug 2022, 11:10 AM
Adarsh Addee
Adarsh Addee - avatar