Introduction
One way to think about programming is that a program applies a series of instructions to a set of data in order to produce some result. For example, consider the software that is used to calculate income taxes. All of the programs in this list have one thing in common... they encode the rules of calculating income taxes.
The rules are defined by Canadian tax laws. For any individual using this software, the results (how much taxes need to be paid or refunded) is based on the data supplied to the software by the user and other data sources. The program is the same no matter who uses it. However, the data used depends on what is entered and thus the final tax balance will be different for each user.
In this chapter, we will look at data and how we represent them in our programs.
Learning Outcomes
After completing this chapter, students will be able to:
- Explain the relationship between bits, bytes, and data storage and calculate the number of values that can be represented using bits
- Distinguish between different data types (char, int, float, double) and select appropriate types for specific programming tasks
- Declare and initialize variables and constants using proper C syntax and naming conventions
- Understand data abstraction and explain how computers interpret binary data as different types of information
- Apply type conversions including narrowing, promoting, and explicit casting, and predict the consequences of each
- Use printf() and scanf() with format codes and modifiers to perform interactive input and output
- Write interactive C programs that read user input, store data in variables, and display formatted output