Boiz's C ++ Memo (2)

xiaoxiao2021-03-06  64

1, C function parameters into the stack order - from right to left

The following example is used to verify the C function parameters into the stack order:

Void Test (int I1, INT I2, INT I3)

{

Printf ("I1 =% D, I2 =% D, I3 =% D / N", I1, I2, I3);

}

INT i = 0;

TEST ( i, i, i);

The output result is: I1 = 3, I2 = 2, i3 = 1

2, an interesting small problem - expression and operator binding order

It is a bit confused in the VC Forum to the following expression calculations.

INT i = 1;

INT K = ( i) ( i) ( i);

INT I2 = 1;

INT K2 = ( i2) ( i2);

I also tested it, many people will think K = 2 3 4 = 9;

However, in fact, compiled in VC, DEVC 4.9 (GCC), executes the result of K = 10;

Some other people's opinions and my own tests have been concluded:

K = ( i) ( i) ( i); // is equivalent to i, i, k = i i ( i); that is, K = 3 3 4 = 10.

Therefore, the result of K2 is 6.

Of course, this deep analysis of the grammatically, interested friends can analyze the C related grammar.

转载请注明原文地址:https://www.9cbs.com/read-84194.html

New Post(0)