Files
Linux-C-Notes/C05-数组/simple1.c
2024-05-26 15:39:14 +08:00

38 lines
655 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <stdio.h>
#include <stdlib.h>
#define M 3
int main( )
{
// int arr[M] = {1};
// static int arr[M];
int arr[] = {1, 2, 3, 4, 5, 6};
printf("%d\n", sizeof(arr) / sizeof(arr[0]));
printf("%d\n", sizeof(arr));
// out: 12
printf("arr = %p\n", arr);
// arr = {4, 5, 6};
// arr常量不可赋值
// for (int i = 0; i < M; i++)
// {
// scanf("%d", &arr[i]);
// }
arr[3] = 10;
printf("arr[3] = %d\n", arr[3]);
// out: arr[3] = 10
// 正常输出,起始越界了
for (int i = 0; i < M; i++)
{
printf("%p --> %d\n", &arr[i], arr[i]);
}
exit(0);
}