Search:

# C Programming Articles

Submit Article
 RSS Feeds

# Constants

Posted By: Morgan Brown     Category: C Programming     Views: 5914

### Integer Constants

• An integer constant refers to a sequence of digits
• There are three type of integers Decimal, Octal and Hexadecimal
• Decimal integers consists of set of digits, preceded by optional + or - sign
• Embedded spaces, commas, and non digit characters are not allowed

### Examples of Integer Constants

 Valid Constants Invalid Constants 123 987612347ul 15 750 -321 987612347UL 20,000 0 +78 \$1000 65432L 0xAB 089 545U 0X10A 0xGH 545u 035 12.5 567891

### Examples of Valid Real Constants

 0.0083 0.65e4 -0.75 12e-2 435.36 1.5e+5 247 3.18E3--Underline word is Exponent -0.75 -1.2e-1 --Underline word is Mantissa 0.95 Embedded space is not allowed

### Examples of Numeric Constants

 Constant Valid Remarks 698354L Yes Long integer 25,000 No , not allowed +5.0E3 Yes Unary + allowed 3.5e-5 Yes 7.1e4 No White space NA -4.5e-2 Yes 1.5E+2.5 No Exp must be int \$255 No \$ not allowed 0X7B Yes Hexadecimal int

### Single Character Constants

• A (single) character constant contains a single character within pair of single quotes
• ‘5’  ‘X’ ‘;’  ‘ ‘     are examples of character constants
• Note that ‘5’ is different than 5
• Character constant have integer values, known as ASCII values
• Printf (“%d”,’a’); and printf(“%c”,97);

### String Constants

• Is a sequence of characters enclosed in double quotes ex. “Hello!” or “1997”
• ‘x’ is different than “x”!
• A character string does not have any ASCII value associated with it
• Few other examples are “Well Done!” “?..!” “5+3” “!@\$”

### Backslash Character Constants

 Constant Meaning Constant Meaning '\a' Audible alert '\v' Vertical tab '\b' Back space '\'' Single quote '\f' Form feed '\'" Double quote '\n' New line '\?' Question mark '\r' Carriage return '\\' Back slash '\t' Horizontal tab '\0' Null

### Symbolic Constants

• The scanf() function and &
• Defining symbolic constants
• Modifiability and understandability
• Usually written in capitals
• # is needed but ; is not allowed in the end
• Assignment statement is not allowed
• It can reside anywhere before usage

Share:

Didn't find what you were looking for? Find more on Constants Or get search suggestion and latest updates.

 Morgan Brown author of Constants is from London, United Kingdom. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!