Home > Back-end >  See a structure of practice, don't quite understand the output
See a structure of practice, don't quite understand the output

Time:01-21

In 0, only don't know why

CodePudding user response:

Because + + a [I] s [3] addressing an error has occurred, remove can normal output
# include
Struct s1
{
Char * s;
int i;
Struct s1 * sip;

};
Int main ()
{
The static s1 a []={{const_cast & lt; Char * & gt; (" abcd "), 1, a + 1}, {const_cast & lt; Char * & gt; (" efgh "), 2, and a + 2}, {const_cast & lt; Char * & gt; (" ijk1 "), 3, a}};
int i;
for (int i=0; i<2; I++)
{
Printf (" % d \ n ", -- a [I] I);
Printf (" % c \ n ", a [I] 's [3]).
}
return 0;
}

CodePudding user response:

Reference:
 # include 
Struct s1
{
Char * s;
Int I;
Struct s1 * sip;
};

Int main ()
{
The static s1 a []={{const_cast & lt; Char * & gt; (" abcd "), 1, a + 1}, {const_cast & lt; Char * & gt; (" efgh "), 2, and a + 2}, {const_cast & lt; Char * & gt; (" ijk1 "), 3, a}};
int i;
for (int i=0; i<2; I++)
{
Printf (" % d \ n ", -- a [I] I);
Printf (" % c \ n ", + + a [I] 's [3]).
}

return 0;
}

//output: to the operation of the value, there is no addressing problems
//I=0:0 - a [I] a [0] I, I=1 -- a [0]. I=0
//e I=0, + + a [I] 's [3] a [0]. [3]=' d 's + + a [0]. [3]=' e 's

//I=1:1 -- a [I]. I [1]. "I=2 -- a [1]. I=1
+ + a//I I=1: [I] 's [3] a [1], [3]=' h 's + + a. [1] s [3]=' I '

CodePudding user response:

To first understand the a [I]. I and a [I] 's [3] what is the output, and then understand this, it is good to understand the front added + + or -,

Since the increase and the decrement, divided into the front and rear, priority is different, can search on the net, to learn; Total want to learn it myself, not only will this problem, later had a slightly modified problem will not,
  • Related