Site icon Learn Web Development & Programming, Artificial Intelligence, WordPress, Shopify Articles

Constants in C

constants-in-c

Constants values are those values which can’t alter or change during program execution. These fixed (constants) value are also known as literals. Constants can be any data types like an integer constant, a floating constant, a character constant, or string literal.

Integer literal:

An integer literal is a sequence of digits and denotes a number. An integer literal is either signed or unsigned. The sign of a literal determines how C– decides whether it stats into its type:

Examples:

Floating-point literal:

A floating-point literal denotes a floating-point number. It has  an integer part, a decimal point, a fractional  and an exponent part. It is a checked compile-time error when the floating-point literal can’t be represented by k bits where ‘k’ is the native word size. A floating-point literal may not begin with a dot.

Example:

Character literals:

A character literal is a value of type bits 8 by default. It is specified as an ASCII character enclosed in single quotes:’a’ denotes the decimal value 97 (ASCII code for ‘a’). A character literal can be a plain character (e.g., ‘x’), an escape sequence (e.g., ‘\t’), or a universal character (e.g., ‘\u02C0’).

After execution of above , we will get below result:

String literal:

A string literal is an abbreviation for a sequence of character literals and can be used only to define the initial value of data. A String literal is terminated by double quotes and must contain only printable characters. Each character is value of type bits 8. You can break a long line into multiple lines using string literals and separating them using white spaces.

 

Exit mobile version