Printing Null Character (“\x00”) in Python vs C

女生的网名这么多〃 提交于 2019-12-20 03:33:15

问题


When I code and run the statement:

   print "\x00\x00\x00"

in Python it outputs three blank spaces followed by a newline. But in C, when I code and run the statement:

   char hex[] = "\x00\x00\x00";
   printf("%s\n", hex);

it interprets the NULL bytes like I thought it would: it doesn't do anything. So why in Python are NULL bytes treated as spaces?...


回答1:


So why in Python are NULL bytes treated as spaces?

It's not. Your terminal/console is treating them like spaces. C just happens to stop at the first NUL, whereas Python outputs them. Try writing three NULs to stdout instead.



来源:https://stackoverflow.com/questions/10770940/printing-null-character-x00-in-python-vs-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!