The output of the following C code is T T
, but I think it should be t t
.
#include<stdio.h>
#define T t
void main()
{
char T = 'T';
printf("\n%c\t%c\n",T,t);
}
The preprocessor does not perform substitution of any text within quotes, whether they are single quotes or double quotes.
So the character constant 'T'
is unchanged.
From section 6.10.3 of the C standard:
9 A preprocessing directive of the form
# define identifier replacement-list new-line
defines an object-like macro that causes each subsequent instance of the macro name 171) to be replaced by the replacement list of preprocessing tokens that constitute the remainder of the directive. The replacement list is then rescanned for more macro names as specified below.
171) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens, not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they are never scanned for macro names or parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With