A

@Adarsh1999

vector dynamic array

C++
3 years ago
#include <iostream> #include <vector> int main() { int arr[10]; int *ptr = new int[10]; for (int i = 0; i < 10; ++i) { ptr[i] = i * 10; } std::vector<int> data{ 1,2,3 };

initializer_list

C++
3 years ago
std::initializer_list is a C++ class template that is part of the C++ Standard Template Library (STL). It is used to initialize objects of a class with a list of values. It is defined in the <initializer_list> header file. An initializer list

initializer_list

C++
3 years ago
#include <iostream> #include <initializer_list> #include <cassert> class Bag { int arr[10]; int m_Size{}; public: //Provides uniform initialization support for braced list of elements as arguments Bag(std::initializer_list<int> values) {

constexpr basic

C++
3 years ago
/*constexpr is a keyword in C++ that is used to indicate that a function or variable is a compile-time constant. This means that its value can be computed at compile-time, rather than at runtime. One of the main advantages of using constexpr is

constexpr

C++
3 years ago
#include <iostream> constexpr int GetNumber() { return 42; } constexpr int Add(int x, int y) { return x + y; } constexpr int Max(int x, int y) { //Needs C++14 compiler

User defined literals

C++
3 years ago
#include <iostream> #include <string> #if 0 std::string operator"" _pre(const char* str, std::size_t size) { return "prefix_" + std::string(str, size); } int main() { std::string s = "hello"_pre;

StringStream

C++
3 years ago
#include <iostream> #include <sstream> int main() { /* int a{5}, b{6} ; int sum = a + b ; std::stringstream ss ; ss << "Sum of " << a << " & " << b << " is :" << sum << std::endl; std::string s = ss.str() ; std::cout << s << std::end

Strings

C++
3 years ago
#define _CRT_SECURE_NO_WARNINGS //Suppress compiler errors for usage of non-secure C functions #include <iostream> #include <cstring> #include <string> const char * Combine(const char *pFirst, const char *pLast) { char *fullname = new char[s

Enum

C++
3 years ago
#include <iostream> #include <iostream> enum class Color { Red, Green, Blue }; int main() {

Dynamic array

C++
3 years ago
// IMP or we can use make_array or make_unique or make_Shared insted of this below which one is the recent one make unique or make array and which one is best or any other then this which is more efficient? std::make_unique is a function template

class vs struct

C++
3 years ago
Structs in C++ can have member functions just like classes, so it is incorrect to say that structs cannot use functions. For example, in the struct example I provided before: Copy code struct Point { double x; double y; };

Distructor in c++

C++
3 years ago
#include <iostream> class MyResource { private: int* resource; public: MyResource() { resource = new int[10]; std::cout << "Resource allocated" << std::endl; }

constructor in c++

C++
3 years ago
https://simplesnippets.tech/constructor-destructor-in-cpp/ #include <iostream> class MyClass { public: int x; MyClass(int val) { x = val; }

Shared pointer

C++
3 years ago
/*IMP Yes, exactly! If you need to pass the pointer between multiple functions without losing ownership or control of the resource, you should use std::shared_ptr instead of std::unique_ptr. Here's why: Key Differences: std::unique_ptr: Ownership

object vs varable

C++
3 years ago
why we call varable as on object here In C++, a variable is often referred to as an object because it is an instance of a class or a struct. A class or struct defines the behavior and properties of an object, and a variable of that class or struct

Unique pointer instead of raw ptr

C++
3 years ago
//used to save memory by moving ptr //delete memery aotomatically exit a loop //no memeory leaks #include <iostream> #include <memory> int functionA() { std::unique_ptr<int> ptr (new int(5)); std::cout << "Inside functionA, value of the i

RAW POINTER

C++
3 years ago
// sud not use in c++ In C++, a raw pointer is a type of pointer that holds the memory address of another variable. It is called a "raw" pointer because it doesn't automatically manage the memory it points to, unlike smart pointers. Here is an ex

std::move

C++
3 years ago
#include <iostream> void val(int v){ std::cout << v << std::endl; v=v+1; std::cout << v << std::endl; } int main() { int a=5;

basics Car.h

C++
3 years ago
//#pragma once class Car { private: float fuel; float speed; int passengers; static int totalCount; public: Car(); Car(float amount);

basics main.cpp

C++
3 years ago
#include "Car.h" int main() { Car c; return 0; }