Lesson 72: Declarative Instructions

Basic Data Types

  • Integers (int): whole numbers, either positive, negative, or zero (e.g., 1, 2, -4, 0), used for counting, indexing, and calculations.
  • Floating-point numbers (float): decimal numbers (e.g., 3.14, -0.5, 0.0), used for calculations requiring decimal precision.
  • Characters (char): single characters — letters, digits, or special characters (e.g., ‘a’, ‘B’, ‘1’, ‘@’), used for text processing and input/output.
  • Strings (string): sequences of characters (e.g., “hello”, “123”), used for text processing, input/output, and storing text data.
  • Boolean values (bool): true or false values, used for logical operations, conditional statements, and decision-making.

Declaring Variables and Constants

Variables are names given to memory locations storing data, declared using the syntax type variable_name;. For example, int x; declares an integer variable named x, and float y; declares a floating-point variable named y.

Constants are values that cannot be changed during program execution, declared using the syntax const type constant_name = value;. For example, const float PI = 3.14; declares a constant named PI with value 3.14, and const int MAX_SIZE = 100; declares a constant named MAX_SIZE with value 100.

Leave a comment

Your email address will not be published. Required fields are marked *

sponsors Ads