दुर्भाग्यवश, सी const
चर में वास्तव में नहीं हैं।
नीचे सी 99 मानक से निष्कर्ष हैं।
6.6 Constant expressions
(7) More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following:
— an arithmetic constant expression,
— a null pointer constant,
— an address constant, or
— an address constant for an object type plus or minus an integer constant expression.
(8) An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions. Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof operator whose result is an integer constant.
इस प्रकार, c
और a
निरंतर भाव नहीं हैं और के रूप में इस्तेमाल नहीं किया जा सकता: इस प्रकार
6.4.4 Constants
Syntax
constant:
integer-constant (e.g. 4, 42L)
floating-constant (e.g. 0.345, .7)
enumeration-constant (stuff in enums)
character-constant (e.g. 'c', '\0')
मानक स्थिर भाव परिभाषित करता है:
6.7.8 Initialization
- All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.
स्थिरांक इस प्रकार परिभाषित कर रहे हैं आपके मामले में प्रारंभिक।
स्रोत
2012-10-05 17:25:20
देखो: सी में इस समस्या को संभालने के लिए हमेशा की तरह पूर्वप्रक्रमक बजाय का उपयोग करें। पूछने से पहले कृपया इस साइट को खोजें। –
मैं आपके कोड को ठीक से संकलित कर सकता हूं। आप किस कंपाइलर/सिस्टम का उपयोग कर रहे हैं? – none
@ गोकेशन: क्या आप किसी भी मौके से सी ++ कंपाइलर का उपयोग कर रहे हैं? –