diff --git a/CPlusPlus/CPlusPlus.sln b/CPlusPlus/CPlusPlus.sln index 467ad1f..979c04a 100644 --- a/CPlusPlus/CPlusPlus.sln +++ b/CPlusPlus/CPlusPlus.sln @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Forward_Declaration", "Forw EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Classes", "Classes\Classes.vcxproj", "{4949E46C-8711-4BEF-8919-4B818B823520}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Collections", "Collections\Collections.vcxproj", "{34173AE8-DCD5-46FE-AF4D-85FB110721BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -55,6 +57,18 @@ Global {4949E46C-8711-4BEF-8919-4B818B823520}.Release|x64.Build.0 = Release|x64 {4949E46C-8711-4BEF-8919-4B818B823520}.Release|x86.ActiveCfg = Release|Win32 {4949E46C-8711-4BEF-8919-4B818B823520}.Release|x86.Build.0 = Release|Win32 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|ARM64.Build.0 = Debug|ARM64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|x64.ActiveCfg = Debug|x64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|x64.Build.0 = Debug|x64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|x86.ActiveCfg = Debug|Win32 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Debug|x86.Build.0 = Debug|Win32 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|ARM64.ActiveCfg = Release|ARM64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|ARM64.Build.0 = Release|ARM64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|x64.ActiveCfg = Release|x64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|x64.Build.0 = Release|x64 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|x86.ActiveCfg = Release|Win32 + {34173AE8-DCD5-46FE-AF4D-85FB110721BA}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CPlusPlus/Collections/Collections.vcxproj b/CPlusPlus/Collections/Collections.vcxproj new file mode 100644 index 0000000..f29036b --- /dev/null +++ b/CPlusPlus/Collections/Collections.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + 17.0 + Win32Proj + {34173ae8-dcd5-46fe-af4d-85fb110721ba} + Collections + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + + \ No newline at end of file diff --git a/CPlusPlus/Collections/Collections.vcxproj.filters b/CPlusPlus/Collections/Collections.vcxproj.filters new file mode 100644 index 0000000..ce0c35c --- /dev/null +++ b/CPlusPlus/Collections/Collections.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/CPlusPlus/Collections/main.cpp b/CPlusPlus/Collections/main.cpp new file mode 100644 index 0000000..ec1da44 --- /dev/null +++ b/CPlusPlus/Collections/main.cpp @@ -0,0 +1,92 @@ +#include +#include +#include + +using namespace std; + +int calculateIndex(int x, int y); +void printArray(int numbers[]); +void printArray(int numbers[], size_t count); + +int main() +{ + // C arrays + int numbers[10]; + + for (size_t i = 0; i < 10; i++) + { + numbers[i] = 0; + } + + numbers[0] = 10; + cout << "numbers[5]: " << numbers[5] << endl; + + int numbers2[] = { 0, 1, 2, 3, 4 }; + int numbers3[10] = { 0, 1, 2, 3, 4 }; + + // 2d array - 10 rows & 5 columns + int grid[10 * 5]; + grid[calculateIndex(3, 7)] = 10; // 4th column, 8th row + + // size/count have to be always const + const int count = 10; + int numbers4[count]; + + int length = sizeof(numbers) / sizeof(numbers[0]); // works locally only, arrays with const length + for (size_t i = 0; i < size(numbers2); i++) // std::size is working with locally const length arrays only + { + cout << numbers2[i] << " "; + } + cout << endl; + + printArray(numbers4); + printArray(numbers4, size(numbers4)); + + // "dynamic" (...) arrays + + // stl collections + vector numbers5; + vector numbers6 = { 0, 1, 2, 3, 4 }; + numbers5.push_back(10); // add an item at the end + numbers5.pop_back(); // removed an item at the end + numbers6[2] *= 2; + vector numbers7; + numbers7.reserve(100); + numbers7.shrink_to_fit(); + + printArray(numbers6.data(), numbers6.size()); + + list numbersList; + numbersList.push_back(10); + numbersList.push_front(0); + //numbersList[0] = 100; // random access is not available for lists + + return 0; +} + +int calculateIndex(int x, int y) +{ + return x + y * 5; +} + +void printArray(int numbers[]) +{ + int length = sizeof(numbers) / sizeof(numbers[0]); // works not outside of local scope + cout << "sizeof(numbers) (printArray): " << sizeof(numbers) << endl; + + //for (size_t i = 0; i < size(numbers); i++) // std::size is not working outside of local scope + //{ + // cout << numbers[i] << " "; + //} + //cout << endl; +} + +void printArray(int numbers[], size_t count) +{ + for (size_t i = 0; i < count; i++) + { + cout << numbers[i] << " "; + } + cout << endl; +} +