So I am working on an implementation of stack in C by using structs, and the following thing is bothering me
typedef struct {
int vrh, polje[MAXSTOG];
} Stog;
void init_stog(Stog *stog) {
stog->vrh = -1;
}
int dodaj(int element, Stog *stog) {
if(stog->vrh == MAXSTOG-1) {
return 0;
}
stog->vrh++;
stog->polje[stog->vrh] = element;
return 1;
}
int skini(int *element, Stog * stog) {
if(stog->vrh < 0)
return 0;
*element = stog->polje[stog->vrh];
stog->vrh--;
return 1;
}
int main(){
Stog *stog;
init_stog(stog);
dodaj(5, stog);
dodaj(3, stog);
dodaj(2, stog);
int a;
skini(&a, stog);
printf("%d ", a);
skini(&a, stog);
printf("%d ", a);
return 0;
}
Why does Stog *stog; works, even though the pointer doesn't point to anything. I understand that Stog is object_name, and it is already instantiated, so that would only be that pointer points to instantiated struct, but I don't understand the syntax when pointer is added, and I couldn't find an explanation for that anywhere.
Could you explain me is that just a c syntax thing, or I misunderstood something?
stogpoints to something writable by the running process is pretty low - is it running on an embedded system, or is it a usual Linux distrib (Debian, RedHat...) ?