Whatever you put inside the parenthesis is considered/has to be a condition. So it could be while (a == 5)
or if a variable is itself a condition you can put the variable directly in the parenthesis. For example every integer, except for 0, is considered as true
, so if I have while (10)
this condition will always be true
(and will probably cause an infinite loop).
Now the value NULL
is interpreted as false
. The ! just changes the condition to its opposite. So true
becomes false
and false
becomes true
. Take a look at the example below:
#include <stdio.h>
int main(void)
{
if (NULL)
{
printf("NULL is interpreted as 'true'\n");
}
else if (!NULL)
{
printf("NULL is interpreted as 'false'\n");
}
return 0;
}
It will print
NULL is interpreted as 'false'
Now on struct
s. You basically create a struct
whenever you want a type for a variable, that holds more than one type of variables. For example if we had a store with PCs and wanted to store them somehow, you could create a struct
that would contain each PC's variables (i.e. CPU speed, RAM etc). The struct
would look like that:
struct pc
{
float cpu_frq;
int gb_of_ram;
};
Now every time you wanted to create a variable of this type inside your program you would have to do it that way:
struct pc pc_name;
pc_name.cpu_frq = 3.2;
pc_name.gb_of_ram = 8;
In order to not have to type the whole struct name (i.e. struct pc
) we use a typedef
, which creates an 'alias' for a variable type. So you can change to
typedef struct pc {
float cpu_frq;
int gb_of_ram;
} apc;
and declare your variables as
apc pc_name;
pc_name.cpu_frq = 3.2;
pc_name.gb_of_ram = 8;
So to answer directly your question the top node
is the name of the struct
and the bottom node
is the 'alias' name of the struct.
If you didn't use the typedef
at top, what is now the 'alias', would be declaration of variables. So that
struct pc {
float cpu_speed;
int gb_of_ram;
} apc;
would have this as consequence:
apc.cpu_speed = 3.2;
apc.gb_of_ram = 8;
If something is unclear (probably many things as I didn't use a really great example) ask away!