Primitive Data Structures

Primitive Data Structures – Complete English Guide

Primitive Data Structures are basic data types that are directly stored in computer memory. They represent simple data and serve as a foundation for complex data structures. Understanding them is very important for programming.

Key Points:

  • They are the simplest and most basic types of data storage.
  • Usually store a single value.
  • They act as building blocks for programming.
  • Stored directly in memory, providing fast access.
  • Available in almost all programming languages (C, C++, Java, Python).

1. Integer (int)

Definition: An integer is a whole number (positive, negative, or zero) stored without decimal points.

  • Supports arithmetic operations: +, -, *, /
  • Memory size: 4 bytes (usually in C/C++)
  • Real-life examples: age, marks, number of items, counter, loop iteration
  • Can be signed or unsigned; signed integers can store negative values.
int age = 21;          
int temperature = -5;  
int items = 100;       
    

2. Float (Decimal Numbers / Real Numbers)

Definition: A float (or real number) is a number that is represented with decimals.

  • Stores fractional numbers.
  • Decimal calculations are accurate in arithmetic operations.
  • Memory size: 4 bytes (C/C++)
  • Real-life examples: price, weight, height, temperature, GPA
  • Comparisons can be tricky due to precision errors.
float price = 99.99;   
float weight = 65.5;   
float temperature = 36.6;
    

3. Character (char)

Definition: A character represents a single symbol, letter, or number.

  • Stores only one character.
  • Stored in memory using ASCII or Unicode.
  • Memory size: 1 byte.
  • Real-life examples: initials, grade symbols, keyboard input, single-letter variables.
  • Characters can also be converted to integers using their ASCII values.
char grade = 'A';   
char initial = 'N'; 
char symbol = '#';  
    

4. Boolean (bool)

Definition: Boolean stores only true or false values.

  • Used for logic and decision making.
  • Used in conditional statements (if, while, for loops).
  • Memory size: 1 byte (language dependent)
  • Real-life examples: login status, switch on/off, flag variables
  • Booleans are essential for controlling program flow.
bool isStudent = true;   
bool isLoggedIn = false; 
    

5. String (Array of Characters)

Definition: A string is a sequence of characters, usually used to store text.

  • Continuous sequence of characters.
  • The null character (\0) defines the end of the string (in C/C++).
  • Length can be variable or fixed.
  • Real-life examples: name, city, message, email, password
  • Strings support concatenation, comparison, and substring extraction.
char name[] = "Nitesh";       
char city[] = "Indore";       
char message[] = "Hello World"; 
    

Quick Summary Table

Data Type What It Stores Example Memory Size Additional Notes
Integer Whole numbers (without decimals) 10, -5, 0 4 bytes Signed and unsigned integers
Float Decimal / fractional numbers 5.5, 99.99 4 bytes Precision can be tricky
Character Single letter / symbol / number 'A', '#', '5' 1 byte Stored using ASCII / Unicode
Boolean True / False true, false 1 byte For logic and decision making
String Sequence of characters (text) "Hello", "Nitesh" Variable Supports concatenation, substring, comparison

Tips for Exams & Programming

  • These are the base types of programming; memorize them well.
  • Operations differ for each type: arithmetic, logic, comparison, concatenation.
  • Stored directly in memory and serve as the foundation for complex structures.
  • Remembering them with real-life examples makes it easier to retain.
  • Revising the table and examples is crucial for exams.

Comments

Popular posts from this blog

What is Overflow & Underflow (in Stack/Queue)?

Data Abstraction

Queue – FIFO, types: Simple, Circular, Priority, Deque