🎙️ Introduction
Hello everyone!
Welcome to Chapter 8 – Data Types, Variables & Constants.
In programming, everything revolves around data. Whether we are building a small calculator program or a large software system, we always deal with storing, processing, and manipulating data. But before we can store any information inside a program, the computer must clearly understand what type of data we are using. That is where data types, variables, and constants come into...Read More
🔹 Step 1: Understanding Data in Programming
First, let us understand what data means in programming. Data simply refers to information. This information can be in different forms such as numbers, decimal values, characters, or text. For example, a student’s age is a number, a product’s price is a decimal value, a grade is a character, and a name is a group of characters...Read More
🔹 Step 2: What is a Data Type?
A data type specifies the type of data that a variable can store. It tells the compiler three important things: what kind of value will be stored, how much memory should be allocated, and what operations can be performed on that value.
In simple words, a data type defines the nature of the data.
For example, if we want to store a person’s age, we use an integer data type. If we want to store the price of an item, we use...Read More
🔹 Step 3: Basic Data Types in C
C language provides several basic or primary data types.
The first one is int. The int data type is used to store whole numbers such as 10, 25, or -5. It cannot store decimal values. It is commonly used for counting and indexing.
The second one is float. The float data type is used to store decimal numbers like 3.14 or 9.5. It is suitable for storing...Read More
🔹 Step 4: What is a Variable?
Now let us move to variables.
A variable is a name given to a memory location where data is stored. It acts like a container that holds a value. The value stored in a variable can change during program execution.
For example, if we declare a variable to store age, we can assign it a value like 20. Later in the program, we can change it to 25 if needed. That is why it is called a variable — because its ...Read More
🔹 Step 5: Rules for Naming Variables
C language has specific rules for naming variables. A variable name must start with a letter or an underscore. It cannot start with a number. Special characters such as @, #, or % are not allowed. Also, we cannot use reserved keywords like int, float, or return...Read More
🔹 Step 6: Types of Variables Based on Scope
Variables in C can also be classified based on where they are declared.
A local variable is declared inside a function and can only be used within that function. It is not accessible outside.
A global variable is declared outside all functions...Read More
🔹 Step 7: What is a Constant?
Now let us understand constants.
A constant is a value that cannot be changed during the execution of a program. Once assigned, its value remains fixed.
For example, the value of π (pi) is always 3.14. It should not change. In such cases, we use a constant instead of a...Read More
🔹 Step 8: Types of Constants
C supports different types of constants.
Integer constants are whole numbers like 10 or 50.
Floating constants are decimal numbers like 3.14 or 9.8.
Character constants are single characters like ‘A’.
String constants are groups of characters enclosed in...Read More
🔹 Step 9: Difference Between Variable and Constant
The main difference between a variable and a constant is that a variable’s value can change during execution, while a constant’s value remains fixed.
Variables are used when data needs to be modified...Read More
🔹 Step 10: Why These Concepts Are Important
Data types, variables, and constants are the foundation of programming. Every program stores data. Every calculation uses variables. Every fixed value is stored as a constant.
If you understand these concepts clearly, you can easily move to advanced topics like operators, control statements...Read More
📌 Summary
In this chapter, we learned that data represents information in a program. Data types define the type and size of data. Variables store values that can change during execution. Constants store fixed values that cannot change. Choosing the correct data type and understanding how variables and constants work is essential for writing...Read More
Top comments (0)