Interview Hello World explanation

后端 未结 5 861
名媛妹妹
名媛妹妹 2021-01-30 05:57

This classic ioccc entry is a Hello World program written in C. Can anyone please provide an explanation of how it works?

Original code (syntax highlighting intentionall

5条回答
  •  不思量自难忘°
    2021-01-30 06:10

    The string index of i["..."] causes the loop to execute for the length of the string. i++ + the hello world string means each iteration passes the string starting one letter deeper to the local read function.

    first iteration = "hello.." second iteration = "ello.."

    The read function's first parameter simplifies to 0, stdout's file descriptor. The last parameter simplifies to 1, so only one character is written per call. This means each iteration will write the first character of the string passed to stdout. So following the example strings from above:

    first iteration = "h" second iteration = "e"

    The string index in the for loop is the same length as the hello world string, and as [] is commutative, and strings are null terminated, the last iteration will return the null character and exit the loop.

提交回复
热议问题