How to output the last element of an array in C languag…
To output the last element of an array, you can access the value of the last element by its index and then output it. Assuming the array is named arr, and the index of the last element is length-1 (where length is the length of the array), you can use the following code to output the last element:
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int length = sizeof(arr) / sizeof(arr[0]); // 获取数组长度
int lastElement = arr[length - 1]; // 获取最后一个元素的值
printf("最后一个元素为: %d\n", lastElement);
return 0;
}
The output will be:
最后一个元素为: 5