Summary of the differences between constants and read only variables in C
- 2020-06-12 10:29:40
- OfStack
Constants and read-only variables differ in the following ways:
1. Constants must be initialized at declaration time and cannot be modified once a value is specified. Read-only fields can be initialized at declaration time, or they can be initialized in the constructor and cannot be modified after construction.
2. Constants are static, while read-only fields can be static and dynamic
3.Const can be used for fields and local variables; readonly can only decorate fields