Constant in C language
Constant in C Language
An element of program whose value cannot be changed at the time of execution of program is called constant. It is also called Constant or Literals. In all programming language constants may be in any of the data types, e.g. integer, float, character etc.
Rules for constructing integer constant
1. It must have at least one digit
2. It may not have a decimal point
3. It may be positive or negative
Have you signed up with Rakuten yet? It's the best site for earning Cash Back. Get a $40 bonus when you sign up with the link below and spend $40. It's free! 🤩
sign up now!
Have you signed up with Rakuten yet? It's the best site for earning Cash Back. Get a $40 bonus when you sign up with the link below and spend $40. It's free! 🤩
sign up now!
4. The range of integer constant is between -32,768 to +32,767
5. No comma or blank spacing is allowed in integer constant.
Rules for constructing floating point constant
1. It must have at least one digit
2. In must have a decimal point
3. It may be positive or negative
4. No comma or blank space is allowed in floating point constant.
Rules for constructing character constant
1. It is a single alphabet, digit or special symbol
2. The length of character constant is 1 character
3. Character constant is enclosed within single quotes (Example char c = ‘A’;).
Use of constants in program
In using of constants in some or most programs there are two ways of using constants in the C program and these are:
1. Using const and
2. Using #define
Example
Const int rollno = 201;
Const float marks = 85.6;
Const grade = ‘A’;
Have you signed up with Rakuten yet? It's the best site for earning Cash Back. Get a $40 bonus when you sign up with the link below and spend $40. It's free! 🤩
sign up now!
Have you signed up with Rakuten yet? It's the best site for earning Cash Back. Get a $40 bonus when you sign up with the link below and spend $40. It's free! 🤩
sign up now!
Comments
Post a Comment