0% found this document useful (0 votes)
17 views1 page

C Programming Constants and Variables Guide

Uploaded by

ifyoucan014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

C Programming Constants and Variables Guide

Uploaded by

ifyoucan014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

(a) An integer constant must have at least one digit.

(b) It must not have a decimal point.

(c) It can be any of zero, positive or negative. If no sign precedes an integer constant, it is assumed to be positive.

(d) No commas or blanks are allowed within an integer constant.

(e) The allowable range for integer constants is -2147483648 to +2147483647.

Ex.: +325.34 426.0 -32.76 -48.5792

Truly speaking, the range of an Integer constant depends upon the compiler. For compilers like Visual Studio, GCC, it is -2147483648 to
+2147483647, whereas for compilers like Turbo C or Turbo C++, the range is -32768 to +32767.

Rules for Constructing Real Constants

Real constants are often called Floating Point constants. Real constants could be written in two forms—Fractional form and Exponential form.
Following rules must be observed while constructing real constants expressed in fractional form:

(a) A real constant must have at least one digit.

(b) It must have a decimal point.

(c) It can be either positive or negative. Default sign is positive.

(d) No commas or blanks are allowed within a real constant.

Ex.: +325.34 426.0 -32.76 -48.5792

The exponential form is usually used if the value of the constant is either too small or too large. It, however, doesn't restrict us in any way from
using exponential form for other real constants.

In exponential form, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is
called exponent. Thus 0.000342 can be written in exponential form as 3.42e-4 (which in normal arithmetic means 3.42 x 10-4).

Following rules must be observed while constructing real constants expressed in exponential form:

(a) The mantissa part and the exponential part should be separated by a letter e or E.

(b) The mantissa part may have a positive or negative sign. Default sign is positive.

(c) The exponent must have at least one digit, which may be a positive or negative integer. Default sign is positive.

(d) Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

Ex.: +3.2e-5 4.1e8 -0.2E+3 -3.2e-5

Rules for Constructing Character Constants

(a) A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.

(b) Both the inverted commas should point to the left. For example, ‘A’ is a valid character constant, whereas ‘A’ is not.

Ex.: ’A’ ’I’ ’5’ ’=’

Types of C Variables

A particular type of variable can hold only the same type of constant. For example, an integer variable can hold only an integer constant, a real
variable can hold only a real constant and a character variable can hold only a character constant. Hence there are as many types of variables in
C, as the types of constants in it.

In any C program many calculations are done. The results of these calculations are stored in some cells (locations) of computer’s memory. To
make the retrieval and usage of these values easy, the memory cells are given names. Since the value stored in each location may change, the
names given to these locations are called variable names.

You might also like