Literals in C Language

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

In C, a literal is a value that is written directly in the source code of a program. Literals are used to initialize variables and constants, and to specify values in expressions. C supports several types of literals, including:

Integer literals: These are whole numbers, such as 42 or -5. They can be written in decimal, octal (by prefixing with 0), or hexadecimal (by prefixing with 0x) notation.

Floating-point literals: These are numbers with decimal places, such as 3.14 or -2.718. They can be written in decimal notation or in scientific notation using the letter 'e' or 'E' to represent the exponent.

Character literals: These are single characters, such as 'A' or '$'. They are written in single quotes.

String literals: These are sequences of characters, such as "Hello" or "Goodbye". They are written in double quotes.

Boolean literals: These are the values true and false.

Enumeration literals: These are used to assign names to integer values in an enumeration.

It's important to note that literals are constants and their value cannot be changed once it's assigned. Also, when a string literal is assigned to a character array, it's necessary to add a null character at the end of the string to mark the end of the string.

Copy code

char str[6] = "Hello";  // It requires an extra element to store the null character

Literals provide a convenient way to specify values in C programs, and their values are known at compile time. This makes them useful for initializing variables, constants, and arrays, and for specifying values in expressions and control structures.

2. Variable and Data Types

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?