When learning how to set the data sending and receiving buffer, do the following experiment:
void main (){ LPBYTE m_data=new BYTE[16]; memcpy(m_data,"example",sizeof(m_data)); string str=" "; str[0]=m_data[3]; cout<<str<<endl;}
The memcpy (m_data, "example", sizeof (m_data) function copies the binary bytes of "example" in the memory directly to the buffer pointed to by m_data, the copy size is the third parameter;
Sizeof (data type)
The return value is the number of bytes occupied by the data type.
Sizeof (variable name)
The return value is the number of bytes occupied by the variable.
I don't know why m_data [k] When k> 3, the output is always? (M_data is a pointer variable)
You can use an integer instead of sizeof (m_data) to obtain the ideal result.
Lab
1 # include <stdio. h> 2 int main (void) 3 {4 char CH = 'a'; 5 Int I = 99; 6 double X = 66.6; 7 char * P = & Ch; 8 int * q = & I; 9 double * r = & X; 10 printf ("% d \ n", sizeof (P), sizeof (Q ), sizeof (R); // specify the number of bytes of pointer variables of different types. 11 return 0; 12}
The running result is 4 4 4.
Therefore, it is found that pointer variables of any type occupy 4 bytes. We also know that sizeof of any char (signed, unsigned, or normal) type is 1! Whether the storage space of char is actually a byte or not.
In this way, we can understand that sizeof (pointer variable) is not the size of the area to which the Pointer Points, but a value of 4, that is, sizeof (pointer variable) occupies 4 memory and does not care about the size of the area to which it points.