in Technology by
What is the difference between const and macro?

1 Answer

0 votes
by
  1. The const keyword is handled by the compiler, in another hand, a macro is handled by the preprocessor directive.
  2. const is a qualifier that is modified the behavior of the identifier but macro is preprocessor directive.
  3. There is type checking is occurred with a const keyword but does not occur with #define.
  4. const is scoped by C block, #define applies to a file.
  5. const can be passed as a parameter (as a pointer) to the function. In the case of call by reference, it prevents modifying the passed object value.

Related questions

0 votes
    What is the difference between const and readonly in C#?...
asked Jan 16, 2021 in Technology by JackTerrance
0 votes
    What is the difference between a macro and a function?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    I'm getting the following error when trying to compile my code on Angular 7.2.0 with TypeScript version ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I'm getting the following error when trying to compile my code on Angular 7.2.0 with TypeScript version ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm relatively new to C++, recently moved from C# and Java (and before that, used to work in ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Take the following code snippet: #include std::vector good; //illegal, because std::allocator is ill-formed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Is the following code supposed to compile? #include void foo() { const std::pair x = {1, 2}; ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Is the following code supposed to compile? #include void foo() { const std::pair x = {1, 2}; ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a C project where all code is organized in *.c/*.h file pairs, and I need to define ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have a C project where all code is organized in *.c/*.h file pairs, and I need to define ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    What is the meaning of the below declarations? 1. const int a; 2. int const a; 3. const int *a; 4. int * const a; 5. int const * a const;c...
asked Jan 21, 2021 by JackTerrance
0 votes
    Name the predefined macro which be used to determine whether your compiler is ANSI standard or not?...
asked Nov 9, 2020 in Technology by JackTerrance
+1 vote
    Which operator is used to continue the definition of macro in the next line in C-Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    Could anyone recommend to me a good online guide to PowerPoint VBA? Also, does anyone has advice on how ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Could anyone recommend to me a good online guide to PowerPoint VBA? Also, does anyone has advice on how ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
...