Home > Back-end >  Just learning pointer, also don't how to use, hope leaders help, when I run after input output,
Just learning pointer, also don't how to use, hope leaders help, when I run after input output,

Time:04-24

CodePudding user response:

Not the cause of the output is still not back from the while loop, that is, while is when=='\ n' exit;

Change

 # include & lt; Stdio. H> 

# define MAX_ARR_SIZE (50)
Int main (void)
{
An int array [MAX_ARR_SIZE], * p;

int i=0;

While (I & lt; MAX_ARR_SIZE & amp; & The scanf (" % d ", & amp; Array [i++])==1)
;

P=array + I - 2;

for (; P & gt;=array; P -)
Printf (" % d \ n ", * p).

return 0;
}

For your reference ~

 # include & lt; Stdio. H> 

# define MAX_ARR_SIZE (50)
Int main (void)
{
An int array [MAX_ARR_SIZE], * p;

int i=0;

P=array;
While (p & lt; Array + MAX_ARR_SIZE & amp; & The scanf (" % d ", p++)==1)
;

//p=array + I - 2;

For (p=p - 2; P & gt;=array; P -)
Printf (" % d \ n ", * p).

return 0;
}

For your reference ~

CodePudding user response:

reference 1/f, confident boy reply:
no output is still not back from the while loop, that is, while is when=='\ n' exit;

Change

 # include & lt; Stdio. H> 

# define MAX_ARR_SIZE (50)
Int main (void)
{
An int array [MAX_ARR_SIZE], * p;

int i=0;

While (I & lt; MAX_ARR_SIZE & amp; & The scanf (" % d ", & amp; Array [i++])==1)
;

P=array + I - 2;

for (; P & gt;=array; P -)
Printf (" % d \ n ", * p).

return 0;
}

For your reference ~

 # include & lt; Stdio. H> 

# define MAX_ARR_SIZE (50)
Int main (void)
{
An int array [MAX_ARR_SIZE], * p;

int i=0;

P=array;
While (p & lt; Array + MAX_ARR_SIZE & amp; & The scanf (" % d ", p++)==1)
;

//p=array + I - 2;

For (p=p - 2; P & gt;=array; P -)
Printf (" % d \ n ", * p).

return 0;
}

For reference ~

Terminate the input way of Linux use CTRL + d, Windows with CTRL + z

CodePudding user response:

Why do I write the program back not to come out, can you explain it? Not input line will exit?

CodePudding user response:

The
reference 3 floor m0_53683570 response:
why the program I wrote back not to come out, can you explain it? Not input line will exit?

The scanf return values are not equal to '\ n', have a look at the scanf returns a value you know:

 return the number of input items successfully matched and assigned, which can be fewer than provided for, or even 
Zero in the event of an early matching failure.
Return the number of input items successfully matched and assigned, which can be fewer than provided for, or even
Zero in the event of an early matching failure.

This is the scanf returns a value, you can refer to the ~
  • Related