Q:

When should we use const in a C program?

0

When should we use const in a C program?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

There are the following places where we need to use the const keyword in the programs.

  • In the call by reference function argument, if you don’t want to change the actual value which has passed in function.
    int PrintData ( const char *pcMessage);
  • In some places, const is better than macro because const handled by the compiler and have a type checking.
const int ciData = 100;
  • In the case of the I/O and memory-mapped register, const is used with the volatile qualifier for efficient access.
const volatile uint32_t *DEVICE_STATUS = (uint32_t *) 0x80102040;
  • When you don’t want to change the value of an initialized variable.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the meaning of the below declarations?... >>
<< What does the keyword const mean?...