Translate

Labels

Showing posts with label CONSTANTS. Show all posts
Showing posts with label CONSTANTS. Show all posts

Sunday, 30 December 2012

CHARACTER CONSTANT

A character is a letter, numeral or special symbol, which can be handled by the computer 
system.These available symbols define the system's character set.Enclosing a single character 
from the system's character set within single quotation marks forms a character constant. The 
characters used in C language are grouped into three classes .

  • Alphabetic characters (a,b,c,....z A,B,C,......Z)
  • Numeric characters (0 through 9)
  • Special characters (+ - * / % # = ,=.=' " () [] : )

eg:

'1'.'a','+', and '-' are the valid character constants.
 since two single quotes are used to represent the character constant, how do we represent the 
single quote itself as a character constant? It is not possible to represent a single quote character 
enclosed between two single quotes, that is, the representation ''' is invalid.
An escape sequence maybe used to represent a single quote as a  character constant. Character 
combinations consisting of a backslash \ followed by a letter are called escape sequences.

'\'' is a valid single quote character constant .
similarly some non printable character are represented using escape sequence characters.
eg:
'\a'   bell(beep)
'\b'   backspace 
'\f'    forum feed
'\r'    carriage return
'\n'   newline 
'\0'   null character
'\t'    gap

To represent the backslash itself as a character, two backslashes are used('\\')

FLOATING POINT CONSTANT

A floating point constant is a single real number.It includes integer portion, a decimal point, 
fractional point and a exponent.While representing a floating point constant, either the digits 
before the decimal point (the integer portion) or the digits after the decimal point (the fractional 
portion ) can be omitted but not both.The decimal point can be omitted if an exponent is 
included.An exponent is represented in powers of 10 in decimal system.

eg:

12.34 is a valid floating point (real) constant.It can be represented in exponent form as follows:

      1.234E1 -> 1.234*10^1 -> 12.34
      1234E2 -> 1234*10^(-2) -> 12.34
      0.1234e2 -> 0.1234*10^2 -> 12.34

 The letter E or e is used to represent the floating point constant in exponent form.

Saturday, 29 December 2012

INTEGER CONSTANT

An integer constant is a decimal number (base 10) that represents an integer value (the whole 
number ).It comprises of the digits 0 to 9.If an integer constant begins with the letter 0x or 0X, it is 
a hexadecimal(base 16) constant.If it begins with 0 then it is an octal (base 8) constant. Otherwise 
it is assumed to be decimal.

  • 64, 73,and 387 are decimal constants 
  • 0x1C, 0xAB, and 0x23 are hexadecimal constants 
  • 032, 065, 064 are octal constants


Integer constants are positive unless they are preceded by a minus sign and hence -16 is also a 
valid integer constant.Special characters are not allowed in an integer constants.The constants 
2,654 is an invalid integer constant because it contains the special character.

CONSTANTS

A constant is a numeric type or non numeric type.It can be a number, character or a character 
string that can be used as a value  in a program.As the name implies, the value of a constant 
cannot be modified. A constant is immutable.Numeric data is primarily made up of numbers and 
can include decimal points.non numeric data may be composed of numbers,letters,blanks and any 
special characters supported by the system. In other words, non numeric data consists of 
alphanumeric characters,A non numeric data can be called as a literal.Constant are characterized 
by having a value and type.

Numeric constant of three types :

  • integer constant,
  • floating_point constant,
  • character constant.