From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using constants

Using constants

- [Instructor] Constants are values that never change. They can appear immediately as a literal value, or you can declare a constant expression. In this code on line seven, you see literal constants four and five. The result of adding these values is assigned to integer variable A. The printf statement outputs the value of variable A. And the computer knows that four and five equal nine. This is good. In this code, literal character constants appear inside a parade of putchar functions. Hello. Here you see a string literal, text enclosed in double quotes. The puts function at line five outputs the string literal. Greetings computer. Here you see a constant declaration at line five. The const keyword classifies the integer identifier count as a constant value assigned four. Creating a constant in this manner requires that it be initialized to a value just like this in a single statement. The compiler issues an error if you attempt to change the value of a constant elsewhere in the…

Contents