Tag: C
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 …
Designing a Board Game (Mastermind) in C++ using MVC, State and Observer Design Patterns
Let’s Design a Console Based Board Game in C++. With this Design you can learn MVC, Observer and State Design Pattern. Moreover, with the same design you can also implement any other Game Like Battleship etc. Advertisements In this we will build Console Based Version of MasterMind Game. Complete Code for this is available at, Frequently …
Designing a Board Game (Mastermind) in C++ using MVC, State and Observer Design PatternsRead More
this pointer in C++ | Tutorial & Example
What is this pointer ? this pointer is pointer that is accessible only inside the member functions of a class and points to the object who has called this member function. Let’s understand by an example, Rise of this pointer : Behind the scene Let’s understand this pointer in a step by step example, Create …
Difference between lvalue and rvalue in C++
In this article we will discuss the differences between lvalue and rvalue in C++. In C, definition if lvalue and rvalue was somewhat simple, anything i.e. left of assignment operator is lvalue and right ofassignment operator is rvalue. But in C++ this definition has changed and become more interesting. Every Expression in C++ is either rvalue or …
Is rvalue immutable in C++?
In this article we will discuss if rvalues is immutable or it can be modified in C++? If you dont know the basics of lvalue and rvalue then we suggest to go through our previous article. In which we discussed the basics of lvalues and rvalues. i.e. Advertisements Difference between lvalue and rvalue in C++ …
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 …
How to fill a vector with random numbers in C++
In this article we will discuss how to fill a std::vector with random numbers using std::generate. For this task we will use a STL algorithm std::generate i.e. Advertisements template<typename _FIter, typename _Generator> void generate(_FIter start, _FIter end, _Generator gen); It will update all the elements from range start to end -1 with values generated by …
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 …
Difference between Vector and List in C++
In this article we will discuss the differences between std::vector and std::list in C++. Both vector and list are sequential containers of C++ Standard Template Library. But there are many differences between them because of their internal implementation i.e. Advertisements List stores elements at non contiguous memory location i.e. it internally uses a doubly linked …
How to erase elements from a list in c++ using iterators
In this article we will see how to erase elements from a std::list using iterators. std::list provides 2 member function to delete elements using iterators i.e. Advertisements iterator erase (const_iterator position); It deletes the element representing by passed iterator “position” and returns the iterator of element next to last deleted element. iterator erase (const_iterator first, const_iterator last); …
How to erase elements from a list in c++ using iteratorsRead More