>1)can't understand where i should use "typedef" and why not to use merely "struct".What's the difference?
Using typedef on a struct allows you to use the typedef in declarations without the struct keyword:
Code:
struct my_struct {
...
};
...
struct my_struct instance; /* Valid */
my_struct instance; /* Invalid */
Code:
typedef struct my_struct {
...
} my_struct;
...
struct my_struct instance; /* Valid */
my_struct instance; /* Also valid */
This is the only difference, you're using the typedef for readability purposes.
>2)I also don't undrerstand the difference between strustures and unions.
A structure is a heterogeneous collection of objects, the size of the structure is the size of the sum of the objects plus any padding between them.
Code:
struct A {
int a;
double d;
char c;
};
struct A has an int and a double and a char. The size of an instance of A is sizeof (int) + sizeof (double) + sizeof (char) + any padding.
A union on the other hand, is also a collection of heterogeneous objects, but a union can only hold one of them at any given time. The size of the union is the size of its largest item.
Code:
union B {
int a;
double d;
char c;
};
union B has an int or a double or a char. The size of B is sizeof (double).
>3)Also, in what cases should i use Bitwise operators?
Whenever you need to work with individual bits. There are many applications.