2
lauw278
2h

#include <stdio.h>

void getElement(int arr[], int size, int index) {
if(index >= 0 && index < size) {
printf("%d", arr[index]);
} else {
printf("Index out of bounds");
}
}

int main() {
int size, index;

// Read the size of the array
scanf("%d", &size);

int arr[size];

// Read array elements
for(int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}

// Read the index to access
scanf("%d", &index);

getElement(arr, size, index);

return 0;
}

Comments
  • 1
  • 0
    Why there is no output as shown?
  • 0
    @Lensflare What do you mean?I still don't get it why in the real compiler DEV C,I'm not able to get the output after waiting for so long?Yet when using online compiler it work?
  • 1
    @lauw278 will you come back to read the answers or will you just abandon the rant as you did with the other two?
  • 3
    @lauw278 scanf is there to read the input from the command line.

    You are supposed to enter a number for the size of the array, confirm with enter, then enter the numbers for the contents of the array and then enter the index to access the element.

    Then you should see to output.
  • 1
    No sweet summer children. There is no \n. So nothing gets displayed.
  • 0
    How does this code compile? You’re defining an array by the size of a non-constant variable. Last I knew, that was a no-no in c, you’d need to malloc it
Add Comment