Tag: Initialize
Different Ways to Initialize a vector in C++
In this article we will discuss different ways to initialize a std::vector in C++. Initializing std::vector elements with same value std::vector<int> vec_1(5, 10); It will create a vector of 5 element and initialize  each element is initialized to 10. Advertisements Initializing std::vector elements with passed argument list std::vector<int> vec_2 = {10,20,30,40,50}; It will create a vector of 5 …
5 Different ways to Initialize a vector in c++
In this article we will discuss different ways to initialize a vector in C++. Creating a vector object without any initialization will create an empty vector with no elements i.e. Advertisements std::vector<int> vecOfInts; But we generally want to initialize a vector with huge values and calling push_back() that many times to add element in vector is not an …
Different ways to Initialize a list in C++
In this article we will discuss the different ways to initialize a std::list in C++. std::list provides various overloaded constructors for creation and initialization of list. Let’s see different ways to create & initialize a std::list in C++ i.e. Advertisements Creating an Empty List in C++ std::list has a default constructor that will create an empty …
How to initialize an unordered_set in C++11
In this article we will discuss the different ways to initialize an unordered_set. Creating an empty unordered_set and then inserting elements in it is easy. But its not the practical scenario always. Many times we need to initialize an unordered_set while creation. For that it provides different overloaded constructors and we will use some of …
Different Ways to initialize an unordered_map
In this article we will discuss the different ways to initialize an unordered_map. unordered_map provides different overloaded constructors. We will use some of them to initialize an unordered_set in 3 different ways i.e. Initializing through an initializer_list Initializing through a iterable range. Initializing through an another map. Lets see them in detail, Advertisements Initializing an unordered_map …
Using std::initializer_list in constructors to initialize member variables
In this article we will discuss how to use std::initializer_list<T> to initialize member variables. Suppose we have a class Point that has 3 member variables representing x, y & Z axis coordinates. It has a parameterized constructor too i.e. Advertisements class Point { int mX; int mY; int mZ; public: Point(int a, int b, int …
Using std::initializer_list in constructors to initialize member variablesRead More
C++ : How to Initialize a map in one line using initialzer_list ?
In this article we will discuss how to initialize a map with std::initialzer_list<T>. Let’s create a map of string as key and int as value and initialize it with initializer_list i.e. Advertisements // Initialize a Map of string & int using initializer_list std::map<std::string, int> mapOfMarks = { {“Riti”,2}, {“Jack”,4} }; Here compiler will create following …
C++ : How to Initialize a map in one line using initialzer_list ?Read More
Python : How to create a list and initialize with same values
In this article we will discuss how to create a list and initialise with same values. Creating a list of same values by [] and multiply Suppose we want to create a list of strings, which contains 20 same strings i.e. ‘Hi’ Advertisements [‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, …
Python : How to create a list and initialize with same valuesRead More
Create Numpy Array of different shapes & initialize with identical values using numpy.full() in Python
In this article we will discuss how to create a Numpy Array of different shapes and initialized with same identical values using numpy.full(). numpy.full() Python’s Numpy module provides a function to create a numpy array of given shape and all elements initialized with a given value, Advertisements numpy.full(shape, fill_value, dtype=None, order=’C’) Arguments:shape: Shape of the …
How to create and initialize a list of lists in python?
Creating a list of lists in python is a little tricky. In this article, we will discuss 4 different ways to create and initialize list of lists. Wrong way to create & initialize a list of lists in python Let’s start from basic, quickest way to create and initialize a normal list with same values …
How to create and initialize a list of lists in python?Read More