DEV Community

shiva sai
shiva sai

Posted on

🚀 Day 1/60: Diving Into C++ Power Concepts & Building Tic-Tac-Toe!

🚀 Day 1/60: Diving Into C++ Power Concepts & Building Tic-Tac-Toe!

📊 Quick Count & Yesterday's Recap

  • Challenge Progress: Day 1 of 60
  • Yesterday's Recap: N/A — Today marks the official launch of the challenge!

👋 Who I Am

I’ve always been driven by a fascination for math and a burning curiosity about how massive, large-scale tech and AI systems actually work under the hood. Right now, I'm a hands-on Python developer diving deep into the fundamentals: mastering Data Structures & Algorithms (DSA), exploring the core concepts of AI/ML, and building a rock-solid foundation for a career in the AI industry. I’m a big believer in planning and structured thinking, and I’m using this challenge to refine my architectural workflow while learning in the open. My goal? To transform from a curious student into a high-caliber developer who can architect meaningful solutions in the modern AI landscape.


🧠 What I Learned Today

Today was an absolute powerhouse of a study session. I focused heavily on core C++ paradigms that bridge the gap between structured data and system memory management, culminating in breaking down a Tic-Tac-Toe game.

1. Dynamic Memory Allocation

Normally, when we declare variables, memory is allocated on the stack automatically before the program runs. Today, I learned how to use the new operator to request memory dynamically from the heap while the program is actively running. This is crucial when you don't know how much data a user will input beforehand.

// Requesting an array size dynamically from the heap based on user input
char *pGrade = NULL;
int size;

std::cout << "How many grades to enter in?: ";
std::cin >> size;

pGrade = new char[size];
Enter fullscreen mode Exit fullscreen mode

2. Struct Datatypes

Instead of managing separate variables for related pieces of information, struct allows me to group different data types under a single custom name. I practiced creating a student profile that bundles text (string), numbers (double), and states (bool).

struct student {
    std::string name;
    double gpa;
    bool enrolled;
};

int main() {
    // Initializing structure values smoothly
    student student1 = {"shivasai", 3.9, true};

    student student2;
    student2.gpa = 0.9;
    student2.enrolled = true;
    student2.name = "shivasai";
}
Enter fullscreen mode Exit fullscreen mode

3. Recursion

I explored the concept of a function calling itself to break a large problem down into smaller, repetitive steps. I implemented a countdown mechanic (walk) and a highly optimized factorial function using a ternary operator.

void walk(int steps) {
    if (steps > 0) {
        std::cout << "You take a step!\n";
        walk(steps - 1); // Recursive call
    }
}

int factorial(int num) {
    return (num > 1) ? num * factorial(num - 1) : 1;
}
Enter fullscreen mode Exit fullscreen mode

4. Enums (Enumerations)

Enums are excellent for improving code readability. They let us associate descriptive names with integer constants, making it easier to handle a fixed set of values using switch statements.

enum fruits { apple, mango, banana, watermelon, karthikeya };

int main() {
    fruits f1 = karthikeya;

    switch (f1) {
        case apple:
            std::cout << "Keeps the doctor away!!\n";
            break;
        case mango:
            std::cout << "Summer fruit!!\n";
            break;
        case banana:
            std::cout << "Makes an energy boost!!\n";
            break;
        case watermelon:
            std::cout << "It contains 90% water!!\n";
            break;
        case karthikeya:
            std::cout << "Chocolate boy!!\n";
            break;
    }
}
Enter fullscreen mode Exit fullscreen mode

5. Tic-Tac-Toe Architecture

To bring these concepts together, I broke down the architecture of a terminal-based Tic-Tac-Toe game. I mapped out:

  • Board representation using arrays
  • Player turn switching
  • Win-condition checking
  • Input validation loops
  • Overall game flow


📚 Resources & Tools Used

Resource Hub:

  • C++ Reference Documentation for Memory Management
  • [Insert your GitHub repository link here after uploading the Tic-Tac-Toe project]

and last some python method :

💡 Conclusion

Day 1 completely changed how I think about memory management. Understanding the difference between stack and heap allocation helps me write code with much more intention instead of simply relying on the compiler to handle everything behind the scenes.


🎯 Goals for Tomorrow (Day 2)

  • [ ] Finalize the complete Tic-Tac-Toe implementation.
  • [ ] Properly free dynamically allocated memory using delete[].
  • [ ] Transition back to Python and connect these DSA concepts to my AI/ML learning path.

#LearningInPublic #CPP #CodingChallenge #DataStructures #Developers #60DaysOfCode

Top comments (1)

Collapse
 
shiva_sai_007 profile image
shiva sai

feel free to tell what i am doing wrong .