>>>>>>>no risk of overflowing anything
because - if it'll be no space malloc() will just return null ?
as I know
char s [] ;
char *s;
are equal - so if i write
char s [5] ;
char *s = malloc (5 * sizeof(char));
will these both be equal ?
as you said - not - but why - only because we can't check that char s [5] ;
works properly in a particular situation ?
They are not equal...
char string[255]; is created on the program's stack.
char* s = malloc(255 * sizof(char)); is created in the system memory pool (called the "Heap").
The program's stack has a practical size limit of about 1 megabyte, which can get used up pretty quickly in busy code. The Heap is the size of your system's memory (less that used by other programs) and on a 4gb machine you often have 2 or 3gb of memory available for malloc(). However, since this is memory taken from the system pool, you have to free() it as soon as you're done with it.
malloc() only returns null if your memory allocation fails. If it succeeds the return value is a pointer to the block of memoy you've just allocated for your array, struct, whatever... The size of the block is *at least* the number of bytes you asked for... eg. 255 * sizeof (char) == 255 bytes of reserved space.
What you need to understand here is C's rules of
Scope... Basically a scope is created by passing the { brace and ends when you pass the } brace (it's more complex than that, but that's good enough to give you the idea)... You cannot access stack based variables that are in a different scope... the result is undefined behaviour and --usually-- programs that misbehave in wildly mysterious ways... like my little array-return sample.
Edit:
In all due respect...
As I've suggested before... you seriously need to get a decent C programming book and work through it page by page, do all the examples, take all the quizzes; repeat the parts you don't understand until you do understand them... then turn to the next page.
It may sound like I'm scolding you... but what I'm really trying to do is get you started off in the right direction. Trust me on this... C is not something you can learn by fiddling around with it. It takes deliberate study.