[From a comment] could you please share the resource where it's stated that preprocessor can't compare strings?
No error is reported for #define COUNTRY "India" because preprocessor macros may be defined to be any tokens—they do not have to be numbers; they can be strings or operators or multiple tokens of various kinds.
An error is reported for #if COUNTRY == "USA" because the #if directive requires a constant-expression. This is specified in the 2018 C standard, in clause 6.10, paragraph 1. 6.10.1 1 further specifies that it shall be an integer constant expression (except that it may also contain defined identifier and defined ( identifier ).
6.6 6 says:
An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, _Alignof expressions, and floating constants that are the immediate operands of casts…
The string literals "India" and "USA" are not integer constants, enumeration constants, character constants, sizeof expressions, _Alignof expressions, or floating constants. Therefore, #if COUNTRY == "USA" violates the constraints of the C standard.
Additionally, note that C does not compare strings with the == operator. In "India" == "USA", each string literal would be converted to the address of its first element, and then those two addresses would be compared. Of course, any two different strings will always have different addresses. However, in "USA" == "USA", the C standard does not specify whether there are two arrays both containing “USA” or just one array, so the == could evaluate to either true or false. So not use == for comparing strings. You can use strcmp, declared in the <string.h> header. (But it still cannot be used in a #if directive.)
could you please share the resourceWell, ok, but the C language standard states what is permitted, not what you can't. So that would be here #if whereasconstant-expressionis defined per here, and it just does not mention string comparison as allowed form of constant-expression. Also see more user-friendly site: en.cppreference.com/w/c/language/constant_expression . And anyway, in normal code"string" == "string2"compares pointers, not string content, so that would not work.