文章目录
- 前言
- 一、一维数组
- 二、字符数组-1
- 三、字符数组-2
- 总结
前言
C语言指针和数组的一些笔试题
一、一维数组
#include <stdio.h>
int main()
{
int a[] = { 1,2,3,4 };
printf("%d\n", sizeof(a));
printf("%d\n", sizeof(a + 0));
printf("%d\n", sizeof(*a));
printf("%d\n", sizeof(a + 1));
printf("%d\n", sizeof(a[1]));
printf("%d\n", sizeof(&a));
printf("%d\n", sizeof(*&a));
printf("%d\n", sizeof(&a + 1));
printf("%d\n", sizeof(&a[0]));
printf("%d\n",sizeof(&a[0] + 1));
return 0;
}
二、字符数组-1
#include <stdio.h>
int main()
{
char arr[] = { 'a', 'b', 'c' , 'd', 'e', 'f' };
printf("%d\n", sizeof(arr));
printf("%d\n", sizeof(arr + 0));
printf("%d\n", sizeof(*arr));
printf("%d\n", sizeof(arr[1]));
printf("%d\n", sizeof(&arr));
printf("%d\n", sizeof(&arr + 1));
printf("%d\n", sizeof(&arr[0] + 1));
printf("%d\n", strlen(arr));
printf("%d\n", strlen(arr + 0));
//printf("%d\n", strlen(*arr)); // err
//printf("%d\n", strlen(arr[1])); // err
printf("%d\n", strlen(&arr));
printf("%d\n", strlen(&arr + 1));
printf("%d\n", strlen(&arr[0] + 1));
return 0;
}
三、字符数组-2
#include <stdio.h>
int main()
{
char arr[] = "abcdef";
printf("%d\n", sizeof(arr));
printf("%d\n", sizeof(arr + 0));
printf("%d\n", sizeof(*arr));
printf("%d\n", sizeof(arr[1]));
printf("%d\n", sizeof(&arr));
printf("%d\n", sizeof(&arr + 1));
printf("%d\n", sizeof(&arr[0] + 1));
printf("%d\n", strlen(arr));
printf("%d\n",strlen(arr + 0));
//printf("%d\n", strlen(*arr));//err
//printf("%d\n",strlen(arr[1]));//err
printf ("%d\n",strlen(&arr));
printf("%d\n",strlen(&arr + 1));
printf("%d\n", strlen(&arr[0] + 1));
return 0;
}
总结
C语言指针和数组的一些笔试题