struct linklist
{
int data;
struct linklist *next;
}
Why using struct linklist
in front of *next
? One can create a pointer simply by *node
?
struct linklist
{
int data;
struct linklist *next;
}
Why using struct linklist
in front of *next
? One can create a pointer simply by *node
?
Why we are using struct linklist in front of '*next'
You don't need to use an elaborated type specifier here. So I suppose that you use it because you can.
Or perhaps you intend to use the struct across language boundaries, in which case you use it because it is necessary to use it in C.
It is possible to have a function and a struct with the same name. To keep them apart you have to use the keyword struct
.
E. g.
struct l {
int b;
};
void l(struct l &a) {
a.b = 5;
}
int main () {
struct l a;
l(a);
return 0;
}
In this case you can't leave out the keyword struct
. But this is a special case that you may find in older source codes.
Also in c you need to use the keyword. So
struct l {};
int main() {
struct l a;
}
is valid c and c++ code but
struct l {};
int main() {
l a;
}
is only valid c++ code.
Usually you don't need that keyword in c++.