I was asked a question in C yesterday, and I did not know the answer, since I had not used C since college, so I thought that maybe I could find the answer here, and not just forget about it.
If a person has a definition, for example:
#define count 1
Can this person find the variable name countusing 1, which is inside it?
count
I didnβt think so, since I thought that the count would point to 1, but I donβt see how 1 could indicate a count.
: , . # , , , . , , - "1" - .
@Cade Roux, #define , :
#define COUNT (1) ... int myVar = COUNT; ...
:
... int myVar = (1); ...
, , "" .
"count" 1, ?
, - , , , # define'd , pre-processor, "count", "1".
, , C - , , Java #. , , /, .
. ( )
, .
#define , count 1. , count, .
#define
1
, , . .
, C, # .
#define displayInt(val) printf("%s: %d\n",#val,val) #define displayFloat(val) printf("%s: %d\n",#val,val) #define displayString(val) printf("%s: %s\n",#val,val) int main(){ int foo=123; float bar=456.789; char thud[]="this is a string"; displayInt(foo); displayFloat(bar); displayString(thud); return 0; }
foo: 123 bar: 456.789 thud: this is a string
#define count 1 - , count.
void copyString(char* dst, const char* src, size_t count) { ... }
count 1, :
void copyString(char* dst, const char* src, size_t 1) { ... }
C , . C , , , , . C .
, "", "1". /find, , .
-, , C .
count . . , .
, , :
#define SHOW(sym) (printf(#sym " = %d\n", sym)) #define count 1 SHOW(count); // prints "count = 1"
# .
#
""?
"count", 1.
( ) 1 , :
if (x > count) ...
if (x > 1) ...
, , " " .
#define , ""
, , , . , "count" 1.
, , , , ? . , .
int count = 1; int count2 = 1;
, ?
-, #define , .
, "count" .
C- . . , Java #, C , .
, "#", , "" . , , count, , "count" "1".
, , "".
. , , , , "1" "count" .
, - .
C ( ), -
int i = count;
,
, , , , iDontKnowWhat, , contans 1, , 'count'.
? #define , ( ). , , "", , , - . , , "count" "1".
, /. #defines . -E , , , #directives.
, , . (count == 1) (1 == 1).
, , , , .
, ( ?), , #define enums. :
#define ZERO 0 #define ONE 1 #define TWO 2
enum { ZERO, ONE, TWO };
x = TWO;
#defines, TWO, 2.
Source: https://habr.com/ru/post/1697460/More articles:Is there a nice easy multi-platform C ++ timer queue? - c ++How to read console output on j2me mobile phones? Where does System.out.println () go? - javaCan I create INTERNATIONAL permalinks? - internationalizationHow to change slow parameterized inserts to fast copy (even from memory) - performance.NET client app: how to get to web services in case of a proxy server? - .netCapturing text with the right mouse button on the contents of an Outlook message - vbaHow to programmatically close an InfoPath form in C #? - c #Flex: loading assets into external modules - flexWinForms in Excel (2002) and Add-ons - .netDisabling client cache from Jetty server for REST requests - httpAll Articles