Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b86d375
"Add virtual functions and dynamic binding with Entity-Player inherit…
Butcher3Years Jan 9, 2026
c891a23
This is about Pure virtual funtions and so called interfaces in other…
Butcher3Years Jan 9, 2026
a8c7e64
Add .gitignore to ignore exe files forever
Butcher3Years Jan 9, 2026
c73ca29
Contains public, private, protected
Butcher3Years Jan 9, 2026
edd8567
About Heap allocated arrays and stack allocated ;also size of them
Butcher3Years Jan 12, 2026
84c5ae1
raw strings and modern way of writting strings
Butcher3Years Jan 13, 2026
7f9c477
Demonstrating why string literals (char*) are immutable and how char[…
Butcher3Years Jan 27, 2026
d1715a8
This is about const keyword in various situations [pointers and refer…
Butcher3Years Jan 27, 2026
30be479
This is regarding usage of mutable keyword in const class methods and…
Butcher3Years Jan 27, 2026
11e6383
These are the member initialiser lists not only used for the syntax a…
Butcher3Years Jan 28, 2026
dae9571
These are the ternery operators which can be used inplace of if and e…
Butcher3Years Jan 28, 2026
3ae9981
Initialising objects in classes ;
Butcher3Years Jan 29, 2026
b9db195
This is about the new keyword usage
Butcher3Years Feb 1, 2026
2edadb4
Caution that c++ compiler can implicitly convert some class objects w…
Butcher3Years Feb 1, 2026
8d78157
About operator overloading !!!!
Butcher3Years Feb 2, 2026
d476c00
"this" keyword advantages!!
Butcher3Years Feb 3, 2026
6dd7eb7
focuses on scopedptr class and its lifetimes
Butcher3Years Feb 8, 2026
510d785
about smart pointers and types such as unique ptr , shared ptr and we…
Butcher3Years Feb 9, 2026
58f39a6
About Deep copying and shallow copying
Butcher3Years Feb 10, 2026
5f27dcd
All about arrow operator and its Overloading
Butcher3Years Feb 10, 2026
b9f8ebe
About Dynamic array and its properties
Butcher3Years Feb 11, 2026
582db7f
optimising the factors such as resizing and copying
Butcher3Years Feb 12, 2026
f4420f2
About static local in scopes especially in funtions and how to use them
Butcher3Years Feb 12, 2026
feafe87
all about static linking and glfw intro
Butcher3Years Feb 16, 2026
73901c5
I have spend shit while setting up
Butcher3Years Feb 16, 2026
f361474
this is about linking libraries to inlude and best possible paths
Butcher3Years Feb 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Arrays/Heap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//there is no way of knowing the size of array in c++;but there is a way cause when you delete this heap memory compiler needs to know the size of array but its comprimising

#include <iostream>
#include <array>

class Entity
{
public :

static const int exampleSize = 5;//constexpr will explained later which is constant expression
int* example[exampleSize];//suppose we changed it to a heap we first get the Entity memory adress which leads to the array its a jumping across the memory so [better to switch it to stack]

std::array<int, 5> another;//type and size

Entity()
{


int a[5];

int count = sizeof(a) / sizeof(int);//size means bytes ,count means no of elements

//example->size();//we cant do like this like some other languages for heap in Entity class
for(int i = 0; i < another.size(); i++)
example[i] = 2;//constructor which initializes

}
};

int main()
{

Entity e;

/*int example[5];
for(int i = 0; i < 5; i++)
example[i] = 2;*///we moved into the Entity class


//int* another = new int[5];
//for(int i = 0; i < 5; i++)
//another[i] = 2;


//delete[] another;


std::cin.get();
}
//this is based on heap allocated memory with new keyword
//we need to manually delete this
//stack created it will ends when we get out of curly bracket int example[5]
//heap created more over the stack cause of the life times most probably suppose if we need to return the array inside of our funtion

//in c++ 11 there is called standard array which has inbuilt datastructures used rather than the normal raw array
//it includes bounds checking and it keeps tracking size of arrray
Binary file added Arrays/Heap.exe
Binary file not shown.
23 changes: 23 additions & 0 deletions Arrays/Log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>

int main()
{
int example[5];
int* ptr = example;


for (int i = 0; i < 5; i++)
//example[i] = 2;//this is a text an offset to this memory of array



example[2] = 5;//for index 2 its start at 9th byte we are writting an offset of 8 bytes from a pointer
*(ptr + 2) = 6;//we are dereferencing this pointer way of writting and changing value from 5 to 6
*(int*)((char*)ptr + 8) = 6;//this is the way of writting in single bit[char] and even in int data type of 4 bytes


std::cin.get();
}

//arrays are always stored in rows ; each integer of 4 bytes total 20 bytes;
//array is just a pointer here it is a int pointer
Binary file added Arrays/Log.exe
Binary file not shown.
27 changes: 27 additions & 0 deletions Arrays/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//in java we have no modifier = default modifier
//in c# we have such as internal[these are topics in visibility]
/*Arrays in C++ are a collection of multiple elements of the same type stored in contiguous memory locations (one after another).[in rows]
They are one of the most basic and important data structures in C++.*/
//lua language starts from index 1;c++ is 0
//its like having multiple variables in a single variable
//arrays mostly work with for loops[indexable loops];without it we need to set manually the example array

#include <iostream>

int main()
{
int example[5]; //array type and name mentioned its contain 5 integers
example[0] = 2;
example[4] = 4;//last index

example[-1] = 5;
example[17] = 21;//we get memory access violation [in debug mode we get errors not in release mode]


std::cout << example[0] << std::endl;//with mentioning index, we get underlying data type
std::cout << example << std::endl;//actual array print memory adress cause its a pointer type



std::cin.get();
}
53 changes: 53 additions & 0 deletions Arrow Operator/Log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <string>

class Entity
{
public :
int x;

public :
void Print() const //need a const method to process on later
{
std::cout << "Hello!" << std::endl;
}
};

class scopedptr
{
private :
Entity* m_Obj;
public :
scopedptr(Entity* entity)
:m_Obj(entity)
{
}

~scopedptr()
{
delete m_Obj;
}

//Entity* GetObject() { return m_Obj; }
Entity* operator->()//we are overloading it
{
return m_Obj;
}

const Entity* operator->() const
{
return m_Obj;
}
};



int main()
{
const scopedptr entity = new Entity();//like Entity* entity = new Entity(); and for const scoped we need const version of the overloading
//entity.GetObject()->Print();
entity->Print();

std::cin.get();
}

56 changes: 56 additions & 0 deletions Arrow Operator/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <string>

class Entity
{
public :
int x;

public :
void Print() const
{
std::cout << "Hello!" << std::endl;
}
};

class scopedptr
{
private :
Entity* m_Obj;
public :
scopedptr(Entity* entity)
:m_Obj(entity)
{
}

~scopedptr()
{
delete m_Obj;
}
};



int main()
{

Entity e;
e.Print();


Entity* ptr = &e;

ptr->Print();//DEREF Entity ptr

ptr->x = 2;
//Entity& entity = *ptr;//DEREF
//ptr.Print();//JUST A POINTER or we can do (*ptr).Print();
//entity.Print();



std::cin.get();
}

// ABOUT HOW ARROW OPERATOR AFFECTS STRUCT AND CLASS POINTERS
// AS an Operator we can overload it and use it on our own custom classes
26 changes: 26 additions & 0 deletions Arrow Operator/offset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <string>

struct Vector3
{
float x, y, z;//if x,z,y we have different layout in memory even though same kinda class
};


int main()
{
int offset = (int)&((Vector3*)0)->y;//kinda give me a invalid memory without ref and after it will give offset
std::cout << offset << std::endl;


/*or
&((Vector3*)nullptr)->x;
*/

std::cin.get();
}

//suppose we need to find offset of this y variable was in the memory
//x is 0 y is 4 and z is 8 bytes in the struct!
//in C++, offset refers to the distance, measured in bytes, from a reference pointβ€”typically the beginning of a data structure (like a struct or class)β€”to a specific member or memory location.
//useful when we serialising data in game engines
94 changes: 94 additions & 0 deletions Copying--Copying Constructor/Deep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//"DEEP COPYING" works through copying constrctor[is a constructor which called for second string when actually copies it ]

#include <iostream>
#include <string>
#include <cstring>

class String
{
private :
char* m_Buffer;
unsigned int m_size;//see size
public :
String(const char* string)
{
m_size = strlen(string);
m_Buffer = new char[m_size + 1 ];
memcpy(m_Buffer, string, m_size);
m_Buffer[m_size] = 0;

}

/* String(const String& other)//taking const ref to same class [copy constrctor] and we want memory in ptr not the pointer
: m_Buffer(other.m_Buffer), m_size(other.m_size)
{

}
this is default copy constrctor in c++
*/

String(const String& other)
: m_size(other.m_size)
{
std::cout << "Copied String!" << std::endl;
m_Buffer = new char[m_size + 1];//creating a new buffer
memcpy(m_Buffer, other.m_Buffer, m_size + 1);//same like before string class but a new buffer one also we know previous string have null termination
}


// String(const String& other) = delete; then coppy constrctor wont work same like unq ptr

/* OR

String(const String& other)
{
memcpy(this, &other, sizeof(String));
}
*/

~String()
{
delete m_Buffer;
}

char& operator[](unsigned int index)
{
return m_Buffer[index];
}

friend std::ostream& operator<<(std::ostream& stream, const String& string);
};


std::ostream& operator<<(std::ostream& stream, const String& string)
{
stream << string.m_Buffer;
return stream;
}

void PrintString(const String& string)//by attaching ref and const it wont copies again and we cant edit existing string
{
String copy = string;//power of const ref
std::cout << string << std::endl;
}

int main()
{

String string = "Cherno";
String second = string;

second[2] = 'a';

// std::cout << string << std::endl;
//std::cout << second << std::endl;

PrintString(string);
PrintString(second);//simply needlessly copying it and we actually copying it 2 more copies

std::cin.get();
}

//AFTER THIS SECOND STRING CANT CHANGE FIRST ONE
//By const ref we can do copies how much we wanted and this time copied String for string SECOND

Loading