See a code today, just at the beginning did not understand, the code is as follows: #include #include using namespace std;void main () {string a= "www.ok2002.com"; string b= "Study C + + program"; A.append (b,0,sizeof (b) +2);coutresults showed:
1. The result type of the sizeof operator is size_t. In the header file, typedef is of the unsigned int type.
This type ensures that it can accommodate the maximum object size.
2. sizeof is an operator and strlen is a function.
3. sizeof can be
The difference and connection between sizeof and strlenThe result type of the 1.sizeof operator is size_t, which is a typedef of type unsigned int in the header file.This type guarantees that the byte size of the largest object being built can be
Example 1: Char ss [100] = "0123456789 ";
The result of sizeof (SS) is 100. SS indicates the pre-allocated size in the memory, which is 100*1;
The strlent (SS) returns 10. Its internal implementation is to calculate the length of the string in a
Http://blog.sina.com.cn/s/blog_5c717fa001012ml7.html
Http://baike.baidu.com/view/1078660.htm
Sizeof function: calculate the number of bytes in the Data Space
1. Comparison with strlen ()Strlen calculates the number of characters in the character
Sizeof of struct, sizeof struct
First, there are several rules:
1. the offset between a struct member and a struct member is an integer multiple of the maximum simple type (memory usage) contained by the member (if the member is a struct, it is
Sizeof function: calculate the number of bytes in the Data Space
1. Comparison with strlen ()
Strlen calculates the number of characters in the character array. It ends with "\ 0" and does not count as an array element of '\ 0.
Sizeof memory space
sizeof function:The number of bytes, such as the int type is 4 bytes under the 32 platform, Char is 1 bytes, and any type of pointer is 4 bytes.Stelen function:The length of the string, not including '/'.The following is an example of distinguishing
The result type of the 1.sizeof operator is size_t, which is a typedef of type unsigned int in the header file.This type guarantees that the byte size of the largest object being built can be accommodated.2.sizeof is an operator and strlen is a
Because it is often necessary to clear the array when writing small topics using C + +, note the use of the sizeof operator for the memset function.Memset is characterized by the sequential memory (including the given address) after the given
Use of 1.sizeof: The sizeof operator gives the storage size of its operands in bytes.The sizeof operator cannot be used for a function type, not a full type, or a bit field. Not all types refer to data types with unknown storage size, such as array
Copyright belongs to the original author. I am only a typographical engineer.
1. sizeoFStructure of applications
See the following structure:
StructMystruct{DoubleDda1;CharDDA;IntType;};
What will happen if sizeof is used for the structure
sizeof operatorproduces the operand size associated with the size of the char type.Grammar
sizeof unary-expression sizeof (type-name)
NoteThe result of the sizeof operator is the size_t type, which is the containing file stddef. The
From http://zhidao.baidu.com/question/12033577.html? An = 0 & Si = 2 & WTP = wk1. The result type of the sizeof operator is size_t. In the header file, typedef is of the unsigned int type.This type ensures that it can accommodate the maximum object
Sizeof () function: calculate the number of bytes in the Data Space
1. Comparison with strlen ()Strlen () is used to calculate the number of characters in the character array. It ends with "\ 0" and does not count as an array element of '\ 0.The
1. sizeof return value type is size_t, which is defined in : typedef unsigned int size_t. This type ensures that it can accommodate the maximum object size.
2. sizeof is an operator and strlen is a function.
3. sizeof can be a type parameter. strlen
In doing this problem:32-bit environment, int *p=new int[10]; the value of sizeof (P) is ()A, 4 B, ten C, D, 8I thought the correct answer for the C,int type is 32 bits, four bytes, 10 natural is 40, the result is the correct answer is a, only the
1. Union: C/C ++ keywords (union)
The Declaration of the shared body and the definition and structure of the shared body variables are very similar. Format:
Union shared body name {data type member name;...} variable name;
The shared body
sizeof (array name) and sizeof (* array name)
Example
#include int main (){int a[5]={1,2,3,4,5};printf ("sizeof array name =%d\n", sizeof (a));printf ("sizeof * array name =%d\n", sizeof (*a));}
Run Results
sizeof Array name =20sizeof * Array
Sizeof computing depends on memory allocation, sizeof Memory Allocation
This article records some calculations about sizeof, mainly including the following four situations: (if there is an error, please leave a message)Use sizeof () to calculate the
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.