C Programming Course Notes - Data Types

For each of the constants in the following table, indicate whether the constant is legal or illegal, what type of constant it is if legal, and why illegal otherwise:

Constant

Legal?

Explanation

486

Yes

Decimal int

98.6

Yes

Double

98.6f

Yes

Float - The f indicates float, as opposed to double.

02.479

No

No decimal allowed in an octal constant

0.2479

Yes

Double

"A"

Yes

Character string - Two chars including the null byte.

'A'

Yes

A single char. No null byte.

'ABC'

No

Single quotes are for single chars only

'\n'

Yes

The escape sequence represents a single newline character

000042

Yes

Octal. 4 * 8 + 2 = 34 in decimal

0ffH

No

No 'f' in octal. ( Resembles an old FORTRAN format. )

0xC2F9

Yes

Hexadecimal

+37.1

Yes

Double

.0000

Yes

Double

0xFLU

Yes

Hexidecimal. Value = 15, long, unsigned

0x48.6

No

No decimal point allowed in hexidecimal

0x486e1

Yes

'e' is a valid hexidecimal digit

486e1

Yes

Double. 486 * 10^1 = 4860

0486e1

No

No 'e' allowed in octal

0486

No

No '8' allowed in octal either. :-)

Từ khóa » C99 Long