-
char *t;
char pointer, points to a place in memory.
- This means that t receives the first text index [0] in the same way t goes to the '\ 0' (term character)
- This will give an error, the compiler uses 'for char and' for char array. This is an error because
t = texto;
only receives a value. The right one would be *t = 'oi';
-
texto[0] = "Oi";
Let's separate what is texto[0]
and t = 'O';
. Only printf("\nOs valores são %i, %.2f, %c.\n",*i,*f,*t);
without the asterisk inform to publish the address that is text the same as say t
. The second with the asterisk is to inform that to show only what is contained in the variable *t
(this is the reason that shows the first variable).
This resolved code would be
t = texto; *t = 'i';'
printf("\nOs valores são %i, %.2f, %s.\n",*i,*f,t);'
How could you write hi in variable t
?
First that printf("%s", texto);
has 20 positions starting from index 0 through 19
The addresses would be something like this
texto[0] = 485201314;
texto[1] = 485201315;
texto[2] = 485201316;
texto[3] = 485201317;
texto[4] = 485201318;
.
.
.
texto[19] = 485201332;
Notice the pattern of adding the array. This then comes to us thinking that it would only be doing this texto[0]
Did you understand the operation?
If you ask to print the Oi above it will be printed Oillo Because The t
will print up to \ 0.
So let's think:
texto[20]
has this phrase: *t = 'O'; *(t + 1) = 'i';
the last one is the end character of an array
texto[0] = 'H';
texto[1] = 'e';
texto[2] = 'l';
texto[3] = 'l';
texto[4] = 'o';
texto[5] = 'char *t;
char *comeco_array;
t = texto;
comeco_array = texto;
';
You changed the first address to printf
and the second to texto
the rest continued until HelloO
so it left i
You could also walk through the array through Oillo
, but this would lose the t++
value. For solution could use two values thus
t = texto; *t = 'i';'
printf("\nOs valores são %i, %.2f, %s.\n",*i,*f,t);'
The texto[0]
would be to change ( t
) values and t++
would be to print from comeco_array
.
With texto[0]
printf("%s", t);
will print from where it is forward, if you put t
it will print like this: t++
because it starts where ello
is currently.
Was I clear?