Celebrate open version - BOLG station without garbage

xiaoxiao2021-03-06  95

Just built blog, I feel very easy, this is the test article ---- Compare Sizeof and Strlen usage ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- --------------------------------------- 1. Strlen - a function size_t strlen const char * string; need string.h support, return the number of characters in the string (not included / 0 ).strlen ("Hello !" )==6

2.SizeOf - One Operator SIZEOF Unary-ExpRessionSizeof (Type-Name)

A variable or type of storage is given in the form of bytes. The return value type is size_t (unsigned int). If you operate the HEAP variable array, only the length of the pointer can be obtained.

Char szhello [] = "Hello, World!" SIZEOF SZHELLO = 13; SIZEOF (Szhello) = 13;

Char * pstr = szhello; sizeof pstr = 4; sizeof (pstr) = 4;

SIZEOF * PSTR = 1; sizeof (* pstr) = 1;

Char Szpath [MAX_PATH]

If you define this in the function, SizeOf (szpath) will be max_path, but when Szpath is declared as a virtual ginseng (Void (char szpath [max_path)), sizeof (szpath) will be 4 (pointer size)

Example:

Char * ss = "0123456789"; SIZEOF (SS) result 4 === "SS is a character pointer SIZEOF (* SS) result 1 === * SS is the first character string constant

CHAR SS [] = "0123456789"; SIZEOF (SS) result 11 === "SS is an array, calculated to / 0 position, so 10 1SizeOf (* SS) result 1 ===" * SS is the first character

Char SS [100] = "0123456789"; SIZEOF (SS) result is 100 === "SS indicates that the size of 100 × 1Strlen (SS) in memory is 10 ===" Strlen is a function within the internal implementation of a cycle. Before calculating / 0

INT SS [100] = "0123456789"; SIZEOF (SS) result 400 === "SS indicates that the size 100 × 4Strlen (SS) error ===" STRLEN parameters can only be char * and must be '' / 0 '' ending

Char = "abc"; char p [] = "A / N"; SIZEOF (Q), SizeOf (P), Strlen (Q), Strlen (P); result is 4 3 3 2

转载请注明原文地址:https://www.9cbs.com/read-96545.html

New Post(0)