The following code:
#include <stdio.h>
#include "string.h"
int main() {
char *s ;
char *fun() ;
s = fun() ;
printf ("%s",s) ;
return 0;
}
char *fun() {
char buffer[30] ;
strcpy ( buffer, "RAM - Rarely Adequate Memory" ) ;
return ( buffer ) ;
}
Gives unexpected results whenever the size of buffer is changed and does not give the required answer.
By making char buffer[30]
static
the code prints "RAM-Rarely Adequate Memory"
which is right.
How does static make a difference?