define macro is expanded during the preprocessing stage, const is expanded during compilation and runtime
define does not have a type and does not perform security checks, const does have a type, and security checks will be performed during the compilation phase
define occupies code space; const is a variable definition, which occupies data segment space and is more efficient
define macro definition is just a simple text replacement in the preprocessing stage of the compiler. That is, when compilation officially starts, SIZE in your code will be replaced with 100. If there is a compilation error or a problem occurs during runtime, you can only know that there is a problem with 100, and SIZE is invisible to you, which is not conducive to debugging. Using constants will not have such problems.
Your code below may look awkward, but it’s fine. b is a variable allocated on the stack, which naturally occupies memory space.
I’m not very good at learning C language. Please correct me if I’m wrong^_^
char b[4] ;
char (*pb)[4] = &b;//正常
b is an array of 4B; pb is an array pointer pointing to the memory space of b, so you can get the address of pb by reading the content of b. But pb+1 points to after the last byte of b.
define macro is expanded during the preprocessing stage, const is expanded during compilation and runtime
define does not have a type and does not perform security checks, const does have a type, and security checks will be performed during the compilation phase
define occupies code space; const is a variable definition, which occupies data segment space and is more efficient
define macro definition is just a simple text replacement in the preprocessing stage of the compiler. That is, when compilation officially starts, SIZE in your code will be replaced with 100. If there is a compilation error or a problem occurs during runtime, you can only know that there is a problem with 100, and SIZE is invisible to you, which is not conducive to debugging. Using constants will not have such problems.
Your code below may look awkward, but it’s fine. b is a variable allocated on the stack, which naturally occupies memory space.
@老老哥不了Assignment uses lea
to open up 16 bytes on the stack, 8 for arrays, 4 for pa, and 4 unused
I’m not very good at learning C language. Please correct me if I’m wrong^_^
b
is an array of4B
;pb
is an array pointer pointing to the memory space ofb
, so you can get the address ofpb
by reading the content ofb
. Butpb+1
points to after the last byte ofb
.