# Pointer and Array Pen Test Parsing

### Pointer and Array Question Resolution

Do you think you know about arrays and pointers? Look at these questions and you'll be confident that you'll be good at them.

There are 8 groups of written questions today. Please be patient to finish them. Thank you.

First

strlen-library function

For string length, stop when'\0'is encountered backwards from the starting position

sizeof - Operator - Units are bytes

Evaluate the space occupied by variables

Find the size of the space occupied by the variable created by the type

Next, I'll take you through the written test.

Group 1:

```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));
```

What do you think the answer is?

You must have thought about it.

Next, how many things do you think you can say right?

Array name:

1.sizeof (array name) - The array name represents the entire element and calculates the size of the entire array.

2. &Array name - Array name represents the entire array, taking out the address of the entire array.

3. In addition, all array names are addresses of the first element of the array.

Group 2:

```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));
```

How, how much do you understand?

Next, let's continue with the analysis.

How much is right? It doesn't matter if it's wrong. Please look at the next group.

Group 3:

Don't worry. Let's see the output first.

Wrong report. Why? Wait for me to analyze.

Group 4:

```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));```

Have you finished?

Group 5:

```int main()
{
char arr[] = "abcdef";

printf("%d\n", strlen(arr));
printf("%d\n", strlen(arr + 0));
printf("%d\n", strlen(*arr));
printf("%d\n", strlen(arr[1]));
printf("%d\n", strlen(&arr));
printf("%d\n", strlen(&arr + 1));
printf("%d\n", strlen(&arr[0] + 1));

return 0;
}```

Group 6:

```int main()
{
char* p = "abcdef";
printf("%d\n", sizeof(p));
printf("%d\n", sizeof(p + 1));
printf("%d\n", sizeof(*p));
printf("%d\n", sizeof(p[0]));
printf("%d\n", sizeof(&p));
printf("%d\n", sizeof(&p + 1));
printf("%d\n", sizeof(&p[0] + 1));

return 0;
}```

Next, continue parsing

Group 7:

```int main()
{
char* p = "abcdef";
printf("%d\n", strlen(p));
printf("%d\n", strlen(p + 1));
printf("%d\n", strlen(*p));
printf("%d\n", strlen(p[0]));
printf("%d\n", strlen(&p));
printf("%d\n", strlen(&p + 1));
printf("%d\n", strlen(&p[0] + 1));

return 0;
}```

Will I do it all here?

Is it a little difficult

The next group is more difficult

Group 8:

```int main()
{
int a[3][4] = { 0 };
printf("%d\n", sizeof(a));
printf("%d\n", sizeof(a[0][0]));
printf("%d\n", sizeof(a[0]));
printf("%d\n", sizeof(a[0] + 1));
printf("%d\n", sizeof(*(a[0] + 1)));
printf("%d\n", sizeof(a + 1));
printf("%d\n", sizeof(*(a + 1)));
printf("%d\n", sizeof(&a[0] + 1));
printf("%d\n", sizeof(*(&a[0] + 1)));
printf("%d\n", sizeof(*a));
printf("%d\n", sizeof(a[3]));

return 0;
}```

Have a look first

So how many right lines did you make?

This is all for today's sharing. If you like it, just click and connect. Thank you.

Keywords: C

Added by malam on Tue, 28 Sep 2021 21:57:23 +0300