INFO: How C Interprets Integer Constants with Leading ZeroesLast reviewed: August 26, 1997Article ID: Q35037 |
The information in this article applies to:
SYMPTOMSTwo similar assignment statements produce very different results when the application prints values assigned. For example:
a = 20; printf("%d", a); /* this prints "20" */ a = 020; printf("%d", a); /* but this prints "16" */ CAUSEAny number with a leading "0" (zero) is interpreted to be an octal number (base 8).
RESOLUTIONRemove the leading zero from the decimal number.
MORE INFORMATIONAll character constants of the form "\<o>", "\<o><o>", "\<o><o><o>", (where <o> is a digit) and their string equivalents are specified in octal as well. For example, \33 and \033 each specify the ESC character (decimal 27, hexadecimal 1B). To specify a character constant in hexadecimal, use "\x<h><h>", where <h> is a hexadecimal digit. C does not provide a method to specify a decimal number in a character constant; you can use a decimal integer constant instead (for example, ch = 27). Keywords : CLngIss Version : MS-DOS:6.00a,6.00ax,7.0; OS/2:6.0,6.00a; WINDOWS:1.0,1.5,1.51,1.52; WINDOWS NT:1.0,2.0,2.1,4.0,5.0 Platform : MS-DOS NT OS/2 WINDOWS Issue type : kbinfo |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |