sizeof and Strlen

Source: Internet
Author: User

first, sizeof gets the number of bytes of an object or type


1. General type

char, int, long, double, etc.

Number of bytes returned and system-related


2. Pointer type

The pointer type is actually the address, 32 is the number of bytes in the system is 4


3, array

Array bytes equal to array type byte number * length of array


4, struct

A multiple of the total number of bytes occupied by the largest member, and the total number of bytes for all members before the maximum member, and must be a multiple of the maximum number of bytes in the largest member.


second, strlen gets the length of the string, with "" "as the end flag, and does not count it.


	int a =0;
	char c =0;
	int *PA = &a;
	char* pc =&c;
	int sa[10];
	Char sc[10]={1,1,1,1,1};
	CHAR*PSC=SC;

	struct sts1{
	    char tc;
	    int ta;
	};
	struct sts2{
	    char tc;
	    Char tc2;
	    int ta;
	};	


	printf ("A%d\n", sizeof (a));        4    
	printf ("C%d\n", sizeof (c));        1
	printf ("Pa%d\n", sizeof (PA));      4
	printf ("PC%d\n", sizeof (PC));      4
	printf ("sa%d\n", sizeof (SA));
	printf ("sc%d\n", sizeof (SC));
	printf ("PSC%d\n", sizeof (PSC));    4
	printf ("Strlen psc%d\n", strlen (PSC));  5
	printf ("Sts1%d\n", sizeof (struct sts1));     8
	printf ("Sts2%d\n", sizeof (struct sts2));     8

~end~

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.