Constant in c

Constant in c

Numeric Constant in C

The Numeric constant consist of numerical digits. They may be without decimal point or may have decimal point(.). These are number of rules for defining numeric constants-

1. Numeric constant should have at least one digit.
2.There should be no comma or space is allow within the numeric constant for defining.
3. Numeric constant may be positive or negative but default sign of numeric constant is always be positive.

Integers Constant in C

There are three types of integer constant based on numbers systems such (decimal, octal, hexadecimal) so here all are integer constants or integer types constants but based on number system

Decimal constants- 0,1,2,3,4,5,6,7,8,9 (base 10)
octal constants- 0,1,2,3,4,5,6,7 (base 8)
Hexadecimal constants 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f (base 16)

lets us see some valid decimal integers constants are-

0 156 8765 3459 66558

here are some invalid decimal integers constants are in the below example-

Invalid

Remarks

8.5

illegal character(.)

67 9

No black space allowed

86,55

comma not allowed

05546

first digit can not be zero

809#55

Illegal character (#)

let us see some valid octal integers constants and take example, first digit must be 0.

0 0156 0765 08 0558

let us see and take example of some valid Hexadecimal integers constant, first two characters should be 0X or 0x. some examples are

0X89 0x6653 0X98FBC 0xAAABM 0Xabm

Real(Floating point) Constant in C

The Floating point constant are numeric number constant with decimal point. Here take example of some floating point constants –

0.9 3.459 6655.8 100.6 5.2 99.33

Character Constant in C

The character constant is the single character that is enclosed with in the single quotes. here are some valid character constants are-

Invalid

Remarks

‘lion’

There should be only one character within quotes

“N”

Double quotes are not allowed

X

single quotes missing

There is no character between single quotes

Note: Every character has unique integer value. so every associated value or integer value is machine code such as ASCII(American standard code for information interchange). its depend on machine if machine using ASCII then A character represent by 65

Here are Some ASCII values are-

A-Z

ASCI value(65-90)

a-z

ASCI value(97-122)

0-9

ASCI value(48-57)

;

ASCI value(59)
String Constant in C

A string Constant is a group of characters enclosed within double quotes(“”). At the end of string the complier automatically placed null character (‘\0’). Here are some examples of String constants-

“Saraswat”
“Nitish”
“897”
“5”
” “
“,”

Symbolic Constant in C

if in program we want to use constant as several times, we can given it a name. such as if we use 3.1414587 at many times in a program. We can give it a name PI, and uses it name PI . where we need instead of writing the constant value anywhere. These types of constant are known as Symbolic constant.

#define PI 3.141567
#define name “Nitish”
#define CH ‘c’