/* related posts with thumb nails */

variables and constants:

VARIABLES: A variable is an identifier that denotes a storage location used to store a data value. Unlike constants, a variable may take different values in different times during the execution of the program. A variable name can be chosen by the programmer in a meaningful way so as to reflect what it represents in the program. Some examples of variable names are:

1. average

2. height

3. total_height

4. classAverage

A variable names may consist of alphabets, digits, the underscore(_) and dollar characters, subject to the following conditions:

1. They must not begin with a digit.

2. Uppercase and lowercase are distinct. This means that the variable Total is not the same as total or TOTAL.

3. It should not be a keyword.

4. White space is not allowed.

5. Variable names can be of any length.

CONSTANTS: Constants are values which can never be changed. Constants can be directly used in expressions or they are assigned to variables.

o Integer constants: An integer type of variables can hold integer constants. There are three types of integers, namely, decimal, octal and hexadecimal integers.

Ex: int x=30

o Real (Float) constants: A real variable can hold float constants. They are whole numbers followed by a decimal point and fractional part. They may be expressed in scientific (exponential) notation.

Ex: float pi=3.14, x=0.64e4

o Char constants: A character variable can hold only one character. Character constant must be enclosed in single quotes.

Ex: char ch= ‘Q’

o String constants: String constant is a character array that can hold string values. Strings must be enclosed in double quotes.

Ex: String s= “kiran”, s1=”1234”;

o Boolean (logical) constants: Boolean constants are true and false. Unlike java, languages like C, C++ use integers to represent true or false.

Ex: boolean x=true

o Backslash Character Constants: These are used in output for formatting. All of these are similar to the ones which are available in C language. The constants and their meanings are listed below.






form feed


new line


carriage return


horizontal tab


single quote


double quote



Related Topics:


Post a Comment