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)
float pi = 3.14159; // decimal floating-point constant
float num = 2.5e-3; // exponential floating-point constant (equivalent to 0.0025)
char letter = 'a'; // character constant
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.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.