Constants                C Language Constants
 
    A constant expression has the value and type of the constant value it
    represents.  A character constant has type int.  The type of an
    integer constant depends on its magnitude and the use of an optional
    suffix.  It may have type int, long int, unsigned int, or unsigned
    long int.  Floating-point constants have double type.  There is no
    such thing as a float constant.  String literals are stored as char
    arrays.  A constant expression may also include enumeration set
    members and the cast and sizeof operators.  The & operator can also
    be used in certain circumstances.
 
      Notes:    Integral constants beginning with 0x (or 0X) are
                interpreted as having a hexadecimal base. Those beginning
                with a 0 are treated as having octal base.
 
                If an integer constant has the suffix L (or l), it has
                type long. If it does not have this suffix, its type
                depends on its magnitude. If the value will fit in an
                int, it has type int. The progressive sizes tested next
                are unsigned int, long, and finally unsigned long, until
                the value fits or a compilation error is generated.
 
                There is no such thing as a negative numeric constant. If
                a minus sign precedes a numeric constant it is treated as
                the unary minus operator, which, along with the constant,
                constitutes a numeric expression.  This is important with
                -32768, which, while it can be represented as an int,
                actually has type long int, since 32768 has type long. To
                get the desired result, you could use (int) -32768,
                0x8000, or 0177777.
 
                When a string literal is used in an expression, it
                represents the address of the first element in the array
                of chars. Hence, expressions like "abcdef"[i] are valid.
                The array representing a string always has a terminating
                '\0' character. This terminator is not included in the
                length of the string as returned by strlen, although
                sizeof("abc") is four, since that is the size of the char
                array. strlen("abc") returns three.
 
                The sizeof operator can be used with any constant
                expression.
 
                The preprocessor operator defined can be used in constant
                expressions with the #if and #elif directives.
 
  -------------------------------- Example ---------------------------------
 
           'a', '\377', '\\'              /* type int */
           1234, 033, 0xab, -2345         /* type int */
           0101010, 0x80F0                /* type unsigned int */
           123456, 0x123L, -23l           /* type long int */
           0x80101010                     /* type unsigned long int */
           1.234, -3456. 2.3e35           /* type double */
           "This is a string\n\n"         /* type array of char */

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster