add collections

add pointers
This commit is contained in:
2025-09-16 18:10:24 +02:00
parent 27a9acdee6
commit d8f6014fab
12 changed files with 634 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
#include <iostream>
#include "functions.h"
using namespace std;
int main()
{
// general
int* pNumber = nullptr; // pointer definition, always initialize a pointer (at least with nullptr)
pNumber = new int(0); // creates a new integer value on the heap
cout << "size of pointer: " << sizeof(pNumber) << endl;
cout << "size of pointer data: " << sizeof(*pNumber) << endl;
*pNumber = 789;
//pNumber = new int(0); // BAD BAD - memory leak, because we override an existin g pointer address with a new one without saving or deleting the old one
// here are 100s lines of code
if (pNumber != nullptr)
{
delete pNumber;
pNumber = nullptr;
}
// pointer as references outside local scope
int number = 10;
changeInteger(number);
number = changeIntegerPerReturn(number);
changeIntegerPerPointer(&number);
changeIntegerPerPointer(pNumber);
changeIntegerPerReference(number);
return 0;
}