Ads

Constants

Constants:

- Mathematically a constant is referred to value which doesn’t change. In C programming language it has a similar meaning, the value which cannot be changed during the program execution is known as constant.

- Like 5, 6, 7.0, 9.3, 3.4 are numeric constants, we also have character constants they are denoted in single quotes, for example ’a’, ‘c’, ’*’, ‘#’, etc.

- There are three types of constants,
i) Integer constants: 4, 5, 6, 0, 189, 96, all numbers without decimal point are considered as a integer constants.
ii) Real constants: 2.0, 3.4, 4.9, 0.567, 8.754, the numbers with decimal point are considered as real constants.
ii) Character constants: Alphabets and special symbols are considered as character constants ‘*’, ‘#’, ‘$’, ‘&’, ‘@’,’e’, ‘t’, ‘g’, etc.

NOTE: Character constants are stored in memory in form of their ASCII values.



Points to be noted:

- Constants are assigned to a variable. Ex. x=5.

- But a constant cannot be assigned to another constant. Ex 7=9, is completely invalid in C programming language because on left side of the assignment operator we need a variable which represents a particular memory location. Over here assignment operator acts as medium which saves the value on right side of it to a memory location represented by variable on left side of it.

- We can do all the operations on constants like addition, subtraction, etc. except the one mentioned above.

- A c program where you are using a constant but not assigning it to a variable is completely valid.


/* This program will not generate any error */

#include<stdio.h>
int main()
{
  45;
  76;

  return 0;
}



No comments:

Post a Comment