Variables and Data Types
4. Variables and Data Types
Variables and data types are among the first things every beginner should learn. They help a program store information and understand what kind of information it is dealing with. Without them, a program would not be able to remember names, numbers, or yes/no values.
a. What are variables?
A variable is a named place where data is stored. You can think of it like a labeled box. If you put a value into the box, you can use that value later in your program. Variables are useful because they let programs keep track of information that may change.
For example, a variable might store a student’s age, a product price, or a user name. The word “variable” is used because the value can vary. This makes programs flexible and reusable, instead of hardcoding the same value again and again.
b. Numeric Data Types
Numeric data types are used for numbers. These may include whole numbers, decimals, or very large values, depending on the language. Common numeric types are integers and floating-point numbers. Integers are used for numbers without decimals, while floating-point numbers are used for values like 3.14 or 99.5.
Numbers are important in many kinds of programs. They are used in calculations, score tracking, measurements, totals, and many other tasks. Understanding numeric data types helps beginners avoid confusion when doing math in code, especially because some languages treat whole numbers and decimal numbers differently.
c. Strings and Characters
Strings are used to store text. A string can be a word, a sentence, or even a full paragraph. For example, a name, a message, or a city title can all be stored as strings. In most languages, text is written inside quotation marks.
Characters are usually single symbols, like one letter, one number, or one punctuation mark. Some languages treat characters separately from strings, while others handle them in a slightly different way. For beginners, the main idea is simple: strings hold text, and characters usually hold one text symbol.
d. Boolean Values
Boolean values are very simple: they only have two possible states, true or false. Even though they look small, they are very powerful in programming. Booleans are used in decisions, conditions, and logical checks.
For example, a program may ask whether a user is logged in, whether a password is correct, or whether a score is above 50. The answer in each case is often true or false. Boolean values help programs decide what to do next, which is one of the most important parts of programming logic.










