Learn C Language

Learn C Programming Language Step By Step. It’s easy to learn c programming language with real-life examples and hands-on. We are trying our best to deliver quality content.

Constant In C

« Previous Page                                                                                                                             Next Page »

Constant is an entity that doesn’t change. You know very well that any software is developed to handle some information. This information nothing but a constant that never changes. Sometimes, it is also called as data.

In other words, a fixed value that may not be altered by a program during its execution is called constant. A constant in c programming is also called as literal. Moreover, you can assume a constant as a regular variable whose value can not be modified after its definition. Any basic data type like a floating constant, an integer constant, a character constant or a string literal can be a constant in c programming. By the way, in the C language enumeration constant also exist.

Types Of Constant

Constants can be categorized as Primary constant and secondary constant.

  • Primary Constant
  • Secondary Constant

Primary Constant

Fundamental constants or basic constants are called as primary constants. There are three types of primary constant.

  • Character Constant
  • Integer Constant
  • Real Constant

Character Constant

All character symbols are character constants if they are enclosed in a single quote and of unit length.

Rules To Construct Character Constant

  • A character constant is a single alphabet, a single digit or a single special symbol enclosed within a single quote or inverted commas ‘ ‘.
  • In addition, both inverted commas should point to left.

Let’s see a few examples of Character Constant:

Integer Constant

All numbers either positive or negative without the decimal point are an integer constant. It can be a decimal, octal, or hexadecimal constant. An integer constant in c programming might have a prefix that specifies the base or radix : 0 for octal, 0x or 0X for hexadecimal.

An integer constant in c programming can also have a suffix that is a combination of U (unsigned ) and L (long). The suffix of an integer constant can be uppercase or lowercase and can be in any order.

Rules To Construct Integer Constant

  • An integer constant must have at least one digit.
  • It must not have a decimal point.
  • An integer constant can be either positive or negative.
  • If no sign precedes then integer constant is assumed to be positive.
  • No blank space or commas are allowed within an integer constant.
  • Mostly the allowable range for integer constant is -2147483648 to +214748647. However, the range of an integer constant depends upon the compiler. For compilers like visual studio, gcc, the range mentioned above is true whereas for compilers like turbo the range is -32768 to +32767.

Let’s see a few examples of Integer Constant:

Real Constant

All numbers either positive or negative wit the decimal point involved is a real constant.

Real constants are often called Floating-point constants. The real constants could be written in two forms Fractional form and Exponential Form. The exponential form is usually used if the value of the constant is either too small or too large. In addition, a floating-point constant has an integer part, a decimal point, a fractional part, and an exponent part.

Rules To Construct Real Constant

  • A real constant must have at least one digit.
  • It must have a decimal point.
  • Likewise an integer constant, real constant could be positive or negative.
  • Of course, the default sign is positive.
  • Similar to an integer constant, in real constant also commas or blanks are not allowed.

Let’s see a few examples of Real Constant:

Rules To Construct Real Constant (Type2)

Following rules must be especially observed while constructing real constant in c programming that is expressed in exponential form.

  • The mantissa part may have a positive or negative sign.
  • Moreover, the default sign of mantissa is positive.
  • Furthermore, the mantissa part and the exponential part should be separated by e or E.
  • The exponent must have at least one digit, which may be positive or negative. However, the default sign is positive.

Let’s see a few examples of Real Constant (Type2):

Secondary Constant

Secondary constants are also known as a derived constant in c programming. Because they are derived from primary constants.

Arrays, strings, pointers, structures, union, enumerators are secondary constants. Please, read about these in upcoming tutorials as these are very important and big topics. So, I have covered these topics separately.

How to Define Constants?

You can define constants in two ways :

  • Using #define preprocessor.
  • The other is using,  const keyword.

Using Preprocessor :

Using const Keyword :

Top Book Suggestion

The two books on C Programming Language that I Personally Recommend. I really loved reading these books. These books are listed for quality content, easy steps, and affordable price. You can get it from Amazon and Flipkart. 

Check The Price On Amazon:

1. C Programming Beginner’s Guide

2. Head First C: A Brain-Friendly Guide

Check The Price On Flipkart:

1. Introduction to C Programming 

2. Head First C: A Brain-Friendly Guide

« Previous Page                                                                                                                             Next Page »

Buy Premium Courses At Lowest Price. Become A Certified Developer Today!

Best Books Selected by Our Experts

Buy Premium Projects At Lowest Price

Ebooks Written by Our Experts

CoursePot.Com

Buy Premium Courses At Lowest Price. Grab Golden Opportunity To Become A Certified Developer Today!

Useful Links

Pin It on Pinterest

Share This