tab
is pointing to a string literal and it is undefined behavior to modify a string literal. An alternative that would work would be a char array:
char tab[] = "0123456789\n" ;
Note, you don't need to terminate a sting literal with a null, it will be terminated for you in this case and also in your original code.
The relevant quote from the draft C99 standard on modifying a string literal would be from 6.4.5
String literals paragraph 6 which says (emphasis mine going forward):
It is unspecified whether these arrays are distinct provided their elements have the
appropriate values. If the program attempts to modify such an array, the behavior is
undefined.
and for null terminating the string literal would be back in paragraph 5
In translation phase 7, a byte or code of value zero is appended to each multibyte
character sequence that results from a string literal or literals.66) [...]
and in the case of initializing the array the section is 6.7.8
Initialization:
An array of character type may be initialized by a character string literal, optionally
enclosed in braces. Successive characters of the character string literal (including the
terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.