Home > Back-end >  Can someone explain to me the application
Can someone explain to me the application

Time:05-20

# include
Void main ()
{
Char ch [2] [5]={" 6937 ", "8254"}, * p [2].
Int I, j, s=0;
for(i=0; I<2; I++)
P=ch [I] [I];
for(i=0; I<2; I++)
for(j=0; P [I] [j] & gt; '\ 0'; J +=2)
S=10 * s + p [I] [j] - '0';
printf("%d\n",s);
}

CodePudding user response:

P pointer array is an array, element is a pointer, * p [2] defines two char * type of a pointer variable;

Char ch [2] [5] defines a two dimensional array. Initialize the two strings; With just five characters' \ 0 ';

The following is the result of the need to the original poster can be deduced according to the results of two layers of circular logic,


CodePudding user response:

reference 1/f, confident boy reply:
p pointer array, which is an array, the element is a pointer, * p [2] defines two char * type of a pointer variable;

Char ch [2] [5] defines a two dimensional array. Initialize the two strings; With just five characters' \ 0 ';

Below is the result of the need to the original poster can be deduced according to the results of two layers of circular logic,

I want to know how the two layers of circulation loop

CodePudding user response:

Reference:
 # include 
Void main ()
{
Char ch [2] [5]={" 6937 ", "8254"}, * p [2].
Int I, j, s=0;
for(i=0; I<2; I++)
P=ch [I] [I];
for(i=0; I<2; I++)//in accordance with the line: I=0 - & gt;" 6937
"//I=1, & gt;" 8254
"for(j=0; P [I] [j] & gt; '\ 0'; J +=2)//I=0 j=0 p [I] [j]='6', I=0 j=2 p [I] [j]='3'
//I=1 j=0 p [I] [j]='8', I=0 j=2 p [I] [j]='5'
S=10 * s + p [I] [j] - '0';
printf("%d\n",s);//output number: 6385
}

CodePudding user response:

refer to the second floor Zhi nine lyp reply:
Quote: reference 1/f, confident boy reply:
p pointer array, which is an array, the element is a pointer, * p [2] defines two char * type of a pointer variable;

Char ch [2] [5] defines a two dimensional array. Initialize the two strings; With just five characters' \ 0 ';

Below is the result of the need to the original poster can be deduced according to the results of two layers of circular logic,

I want to know how the two layers of circulation loop

Cycle also need how to explain, you use results can be pushed to circular logic, j + 2, is it not dancing? Such as p [0] [0] is' 6 ', then the j + 2 is not '3'? These also need to how explanation?

P [0] [4] (j=0, + 2 j, j + 2) is not '\ 0', this is two strings, so p [1] [4] is also a '\ 0',
If the string, array, circulation can also learn, this is what the difficulty of ah ~
  • Related