0% found this document useful (0 votes)
0 views

Data Types

The document explains data types, which define the kind of value a variable can hold and the operations applicable to it. It outlines the importance of data types in programming and details four commonly used types: Integer, Double, String, and Character, along with examples and common uses for each. This information is essential for effective variable management and data manipulation in programming.

Uploaded by

Kendrick Amiana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Data Types

The document explains data types, which define the kind of value a variable can hold and the operations applicable to it. It outlines the importance of data types in programming and details four commonly used types: Integer, Double, String, and Character, along with examples and common uses for each. This information is essential for effective variable management and data manipulation in programming.

Uploaded by

Kendrick Amiana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA TYPES

It refers to the type of value a variable has and what type of mathematical, relational, or
logical operations can be applied without causing an error.
IMPORTANCE OF DATA TYPES
Data types help programmers define the kind of data they are storing in a variable or element,
thus indicating the same to the program during execution.
MOST COMMONLY USED DATA TYPES
1. Int or Integer- A data type representing whole numbers.
Example:
<?php
for ($i = 1; $i <= 5; $i++) {
echo "Iteration: $i\n";
}
?>
Common Uses:
 Math operations (e.g., addition, subtraction, multiplication)
 Loop counters (e.g., for loops)
 Storing ages, quantities, and IDs
 Indexing arrays/lists
2. Double- A data type that can represent any numerical value in the compiler, including
decimal values.
Example:
<?php
$grade1 = 85.5;
$grade2 = 90.2;
$average = ($grade1 + $grade2) / 2;
echo "Average Grade: $average\n";
?>
Common Uses:
 Prices and money calculations
 Scientific measurements (e.g., weight, temperature)
 Averages and percentages
3. String- A data type representing a sequence of characters.
Example:
<?php
$name = "John";
echo "Welcome, $name!";
?>
Common Uses:
 Usernames and names
 Messages or notifications
 Concatenating (joining) words together
4. Char or Character- A data type used for single letters.
Example:
<?php
$grade = 'A';
echo "Student's Grade: $grade\n";
?>
Common Uses:
 Single-letter grades (A, B, C, D, F)
 Gender representation ('M' for Male, 'F' for Female)
 Shortcut codes (e.g., 'Y' for Yes, 'N' for No)

You might also like