Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lauw27862h@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?
-
@lauw278 will you come back to read the answers or will you just abandon the rant as you did with the other two?
-
@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. -
AlgoRythm5001540sHow 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
#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;
}
question