Help in output

http://ideone.com/vOtKvk vs. http://ideone.com/THzpAS
can anyone pleasee explain me the difference in both of these?

Difference:

Here’s a nice article explaining what really is the difference between the two. In a nutshell, example 1 is using str as a string literal and example 2 uses it as an array of characters.

Below, I’m showing what’s happening in the assembly to reconfirm what Antoine Wood has said in the aforementioned article.

Example 1

Here’s the assembler directive for str.

1

Example 2

Here’s how the array of characters str is being formed.

2

The mov instructions are used to move the integers (first operand), that represent the concatenated bytes of characters of the string into consecutive memory locations pointed by the second operand, i.e., ebp (Base Pointer) register content + the offsets. Here’s where you can learn the meaning of movl, movw and movw in further details.

Note

str in function getString in both examples are examples of dangling pointers. Hence, both of these produce unpredictable results. :slightly_smiling_face:

1 Like