0
I am studying C and I am doubtful in the difference of the following lines:
(*depois).agora = 20
and
*depois.agora = 20;
From what I understand the point .
has priority and the compiler would try to solve depois.agora
and after that would settle *(depois.agora)
So, depois
is the memory address. if I try to access *(depois.agora)
, I wouldn’t be picking up the value that’s contained in the address depois.agora
?
What would be the difference between the 2 lines?
#include <stdio.h>
struct horario
{
int hora;
int minuto;
int segundo;
};
int main(void)
{
struct horario agora;
struct horario *depois;
depois = &agora; // depois aponta para agora, ou seja, armazena o endereco de memoria de agora
(*depois).agora = 20; // "atalho": depois->agora = 20
*depois.agora = 20; // errado, por quê?
// * = operador de derreferência
return 0;
}
then[0] will walk to the memory location stored by the pointer, for what I saw produces the same effect as using *after?
– Bart
@Bart The indexing operator (
[]
) references the pointer, so it allows accessing the memory address pointed, but is conceptually incorrect for a pointer that does not point to an array.– Isac