I am practicing on #define
and typedef
. I think I got a good hold on the matter, according to this valid discussion.
Currently, I am on this simple chunk of code:
#include <stdio.h>
/*typedef char *string; with typedef the code works correctly*/
#define string char *
int main(void){
string a[] = {"I", "like", "to", "fight,"},
b[] = {"pinch", "and", "bight."};
printf("%s %s %s %s %s %s %s\n",
a[0], a[1], a[2], a[3], b[0], b[1], b[2]);
return 0;
}
I know that define
gives directive to the preprocessor. In this case, to substitute string
with char *
. Because of that, a
is correctly declared as char *a[]
, while b[]
is not!
The problem could easily be addressed with
string b[] = {"pinch", "and", "bight."};
but my textbook challenge the reader by telling that the code with #define
can work just by precisely adding one single character. I have been unable to figure out the solution. It is just for the sake of curiosity that I propose this simple problem to the community. Hence, thanks in advance for your time!