xcode - Why does the strange value come out with an unnecessary % conversion in the code in C language? -


I started learning programming a few days ago, so basically I have no knowledge.

Starting with I, and I have written a very simple code:

  int main (const arg) [arg] [printf ("% D +% d ", 1 + 3); Return 0; }  

With the above code, I got the value of 4 + 1606416608 and later found that the return value is wrong because I have added more than% d, so my question is How did this strange value really come out? If someone knows, please help me thank you!

Do you know what you did beforehand, so to explain that Special implementation possibly:

When you call printf , a new stack frame is pushed onto the call stack. Phone stack is the first time an outlet with a 'frame' according to a column fax. So if main is called logstuff , which is called printf then there will be three consecutive main frames, logstaff, then printf when printf , Its structure is removed from the structure and the execution continues with logoff.

Therefore the frame usually includes the parameters passed in the function and the storage for the local variable. These things can be one and the other, this implementation is dependent.

There is a stream of unknown parameters with a variadic function such as printf Bit pattern will be inserted into a suitable place in the frame but C is not a reflective language, meaning each bit of patine It does not happen naturally: any one can be an integer, a float, or something else, it is not a language that invests in border checks. You are counting on writing code that works correctly.

printf determines the type and number of unknown parameters from the stars so if you gave it wrong information, then interpret this bit pattern with something other than their true meaning And it seems that there is actually less or less than there.

You had said it was more. So what probably happened is that the parameters were equal to an array and it reads a value beyond the end of the array. Since all this implementation is dependent, that value may have been used to represent anything. This caller may be aware that this may be unused storage for another local variable. This bookkeeping may be a format string, it can be interpreted incorrectly as an integer.

This is not a reliable value. It may not always be safe to read.


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -