Home > Back-end >  A few bytes of the string ""?
A few bytes of the string ""?

Time:01-07

And characters'
Among these are not things exactly is of a few bytes,

CodePudding user response:

If it is not wide byte character, accounting for one character (string terminator) 8 bytes
Characters', too, although there is nothing, but with one character 8 bytes to store
Of course, if is C, and the character constants, four characters of 32 bytes (C int character constants used to store, that is why the return value is an int) getchar

CodePudding user response:

 # include & lt; stdio.h> 
#include
Int main () {
Int v.
Char s [3]={' A ', 'B', '\ 0'};

Printf (" 0 x % 02 x x % 0 02 x x % 0 02 x \ n ",
(unsigned char) s [0],
(unsigned char) s [1],
(unsigned char) s [2]);//0 x41 x42 0 0 x00

Strcpy (s, "");

Printf (" 0 x % 02 x x % 0 02 x x % 0 02 x \ n ",
(unsigned char) s [0],
(unsigned char) s [1],
(unsigned char) s [2]);//0 x00 to 0 x42 0 x00

V=strlen (" ") + 1;
Printf (" % d \ n ", v);//1

//v=sizeof (");//VS2015 compile error error C2137: empty character constants
V=sizeof (");
Printf (" % d \ n ", v);//1
return 0;
}

CodePudding user response:

reference 1st floor qybao response:
if it is not wide byte character, of one character (string terminator) 8 bytes
Characters', too, although there is nothing, but with one character 8 bytes to store
If it is, of course, C, and is a character constants, four characters of 32 bytes (C int character constants used to store, that is why the return value is an int) getchar
and a string of different single quotation marks can not be empty inside must have at least one character

CodePudding user response:

reference 1st floor qybao response:
if it is not wide byte character, of one character (string terminator) 8 bytes
Characters', too, although there is nothing, but with one character 8 bytes to store
If it is, of course, C, and is a character constants, four characters of 32 bytes (C int character constants used to store, that is why the return value is an int) getchar
"" must be char [1] is not wide character
Wide character string literal is another way L ""

CodePudding user response:

How can one character 8 bytes?

CodePudding user response:

Wrong, one of eight characters

CodePudding user response:

Note: this allows an extreme case, including 64 bytes in size, all types (including char) have 64 bits wide, the sizeof returns 1 for each type,

CodePudding user response:

refer to 7th floor truth is right or wrong response:
note: this allows an extreme case, including 64 bytes in size, all types (including char) have 64 bits wide, for each type and sizeof returns 1,
it is the essence of personal understand sizeof returns number of bytes to byte is eight yuan this is two different things so see actually 1 byte of 8 bits (or even a power of 2) is not a special case
  • Related