sizeof () different when the pointer and array are evaluated

Source: Internet
Author: User

sizeof () takes the size of the number of bytes in memory of the parameter.

sizeof in the pointer and array of the need to pay attention to the place;

#include <stdio.h>

int main ()

{

char *p = NULL;

Char arr[10];

Char str[]= "Hello";

int A, B, D, E, F, g,h;

A = sizeof (*P);//pointer type. A=1;

b = sizeof (p);//sizeof asks any pointer to be 4 bytes. b=4;

d = sizeof (arr);//space occupied by array elements;d=10;

E = sizeof (arr[10]);//The space size of the 10th element. e=1;

f = sizeof (&arr);//sizeof it as an address, 4 bytes f=4;

g = sizeof (&arr[10]);//And above the same g=4;
H=sizeof (str);//The string length is included in the last "" ", so it is 6 characters h=6;

printf ("%d%d%d%d%d%d%d", A, B, D, E, F, g,h);

}

Result A=1;b=4;d=10;e=1;f=4;g=4;h=6

sizeof () is different when the pointer and array are evaluated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.