Skip to content

Latest commit

 

History

History
121 lines (92 loc) · 2.63 KB

File metadata and controls

121 lines (92 loc) · 2.63 KB
title C Integer Constants | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-language
ms.tgt_pltfrm
ms.topic article
dev_langs
C++
helpviewer_keywords
integer constants
ms.assetid fcf6b83c-2038-49ec-91ca-3d5ca1f83037
caps.latest.revision 10
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

C Integer Constants

An "integer constant" is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents an integral value. Use integer constants to represent integer values that cannot be changed.

Syntax

integer-constant:
decimal-constant integer-suffix opt

octal-constant integer-suffix opt

hexadecimal-constant integer-suffix opt

decimal-constant:
nonzero-digit

decimal-constant digit

octal-constant:
0

octal-constant octal-digit

hexadecimal-constant:
0x hexadecimal-digit

0X hexadecimal-digit

hexadecimal-constant hexadecimal-digit

nonzero-digit: one of
1 2 3 4 5 6 7 8 9

octal-digit: one of
0 1 2 3 4 5 6 7

hexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 9

a b c d e f

A B C D E F

integer-suffix:
unsigned-suffix long-suffix opt

long-suffix unsigned-suffix opt

unsigned-suffix: one of
u U

long-suffix: one of
l L

64-bit integer-suffix:
i64

Integer constants are positive unless they are preceded by a minus sign (-). The minus sign is interpreted as the unary arithmetic negation operator. (See Unary Arithmetic Operators for information about this operator.)

If an integer constant begins with 0x or 0X, it is hexadecimal. If it begins with the digit 0, it is octal. Otherwise, it is assumed to be decimal.

The following lines are equivalent:

0x1C   /* = Hexadecimal representation for decimal 28 */  
034    /* = Octal representation for decimal 28 */  

No white-space characters can separate the digits of an integer constant. These examples show valid decimal, octal, and hexadecimal constants.

/* Decimal Constants */  
10  
132  
32179  
  
/* Octal Constants */  
012  
0204  
076663  
  
/* Hexadecimal Constants */  
0xa or 0xA  
0x84  
0x7dB3 or 0X7DB3  

See Also

C Constants