Skip to main content
added 2 characters in body
Source Link
Mooing Duck
  • 67.6k
  • 19
  • 107
  • 169

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*char[2]) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

edit: formatting fixed

edit2: I've written something very stupid, thanks Mooing Duck for pointing that out.

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

edit: formatting fixed

edit2: I've written something very stupid, thanks Mooing Duck for pointing that out.

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char[2]) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

edit: formatting fixed

edit2: I've written something very stupid, thanks Mooing Duck for pointing that out.

added 5 characters in body
Source Link

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

butedit:

sizeof("n") will not be equal to 2 (only if sizeof(const char*) == 2) formatting fixed

editedit2: formatting fixedI've written something very stupid, thanks Mooing Duck for pointing that out.

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

but:

sizeof("n") will not be equal to 2 (only if sizeof(const char*) == 2)

edit: formatting fixed

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

edit: formatting fixed

edit2: I've written something very stupid, thanks Mooing Duck for pointing that out.

Source Link

The following will take x consecutive chars in memory:

'n' - 1 char (type char) "n" - 2 chars (above plus zero character) (type const char*) '\n' - 1 char "\n" - 2 chars "\\n" - 3 chars ('\', 'n', and zero) "" - 1 char 

but:

sizeof("n") will not be equal to 2 (only if sizeof(const char*) == 2)

edit: formatting fixed