Constant

Constant

In C programming language, a constant is a fixed value that cannot be changed during the execution of the program. Constants can be of different data types, such as integer, floating-point, character, or string. Here are some examples of different types of constants in C:

 1 .   Integer constants: These are used to represent integer values. Integer constants can be written in decimal (base 10), octal (base 8), or hexadecimal (base 16) format. For example

				
					int num = 10;           // decimal integer constant
int num2 = 012;         // octal integer constant (equivalent to decimal 10)
int num3 = 0xA;         // hexadecimal integer constant (equivalent to decimal 10)

				
			
  1. Floating-point constants: These are used to represent real numbers with decimal places. Floating-point constants can be written in either decimal or exponential notation. For example:
				
					float pi = 3.14159;     // decimal floating-point constant
float num = 2.5e-3;     // exponential floating-point constant (equivalent to 0.0025)

				
			
  1. Character constants: These are used to represent individual characters. Character constants are enclosed in single quotes. For example:
				
					char letter = 'a';      // character constant
				
			
  1. String constants: These are used to represent a sequence of characters (i.e., a string). String constants are enclosed in double quotes. For example:
				
					char str[] = "Hello";   // string constant
				
			

Constants can be used in C programs to define fixed values that are used repeatedly throughout the program. By using constants, you can make your code more readable, maintainable, and flexible.

Join To Get Our Newsletter
Spread the love