Articles on Trending Technologies

Technical articles with clear explanations and examples

Iterator Invalidation in C++ program

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 185 Views

In this tutorial, we will be discussing a program to understand iterator invalidation in C++.While iterating over the elements of a container object, sometimes it can become invalidated if we don’t apply bound checks. This mainly occurs due to the change in the shape and size of the container object.Example Live Demo#include using namespace std; int main() {    //declaring a vector    vector v{1, 5, 10, 15, 20};    //changing vector during execution    //which will cause bound invalidation    for (auto it=v.begin();it!=v.end();it++)       if ((*it) == 5)          v.push_back(-1);    for (auto ...

Read More

MakeFile in C++ and its applications

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 310 Views

In this tutorial, we will be discussing a program to understand MakeFile in C++ and its applications.The task is to break the entire program with MakeFile. It is usually done by making .cpp files and .h files with all the classes/functionalities and link them together.Examplemain.cpp#include #include "function.h" using namespace std; //main execution program int main(){    int num1 = 1;    int num2 = 2;    cout

Read More

Lower bound in C++

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 361 Views

In this tutorial, we will be discussing a program to understand the lower bound in C++.lower_bound() method in C++ is used to return the very first number in the container object which is not less than the given value.Example Live Demo#include int main(){    std::vector v{ 10, 20, 30, 40, 50 };    std::cout

Read More

Iseek() in C/C++ to read the alternate nth byte and write it in another file

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 803 Views

In this tutorial, we will be discussing a program to understand how to read the alternate nth byte and write it in another file.For this, we will be provided with two .txt files. Our task is to write the contents from one file to another file using Iseek() which is used to change the pointer of the file descriptor.Example#include #include #include #include void func(char arr[], int n){    int f_write = open("start.txt", O_RDONLY);    int f_read = open("end.txt", O_WRONLY);    int count = 0;    while (read(f_write, arr, 1)){       if (count < n) ...

Read More

Internal details of std::sort() in C++

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 296 Views

In this tutorial, we will be discussing a program to understand the internal details of std::sort() in C++.std::sort() function is used to sort down an array using a comparison of the elements. If we look at the in-depth functionality of std::sort() it uses IntroSort algorithm to sort the elements of a container object.Example Live Demo#include using namespace std; int main(){    int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};    int n = sizeof(arr)/sizeof(arr[0]);    sort(arr, arr+n);    cout

Read More

INT_MAX and INT_MIN in C/C++ and Applications

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 3K+ Views

In this tutorial, we will be discussing a program to understand INT_MAX and INT_MIN in C/C++.INT_MIN and INT_MAX are macros that are defined to set the minimum and maximum value for a variable/element.Example Live Demo#include int main(){    printf("%d", INT_MAX);    printf("%d", INT_MIN);    return 0; }Output2147483647 -2147483648ApplicationCalculating MIN value in an arrayExample Live Demo#include //calculating minimum element in an array int compute_min(int arr[], int n){    int MIN = INT_MAX;    for (int i = 0; i < n; i++)    MIN = std::min(MIN, arr[i]);    std::cout

Read More

Integer literal in C/C++ (Prefixes and Suffixes)

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 2K+ Views

In this tutorial, we will be discussing a program to understand integer literal in C/C++ (Prefixes and suffixes).Integer literals are literals for integer values directly represented in the source code. Further, they are of two types −Prefixes − Prefixes denotes the base of the value. For example, 0x10 indicates hexadecimal value with 0x.Suffixes − Suffixes denotes the type of the value. For example, 8465484156155LL denotes a long long integer.Example Live Demo#include using namespace std; int main(){    //prefixes    cout

Read More

Insertion sort using C++ STL

Ayush Gupta
Ayush Gupta
Updated on 01-Apr-2020 854 Views

In this tutorial, we will be discussing a program to understand the insertion sort using C++ STL.In this we use std::upper_bound to find the element at the wrong position, then rotate the unsorted part of the array to make it sorted.Example Live Demo#include //function to perform insertion sort void insertionSort(std::vector &vec){    for (auto it = vec.begin(); it != vec.end(); it++){       auto const insertion_point =       std::upper_bound(vec.begin(), it, *it);       std::rotate(insertion_point, it, it+1);    } } //printing the array void print(std::vector vec){    for( int x : vec)    std::cout

Read More

Importance of MethodHandles class in Java 9?

raja
raja
Updated on 31-Mar-2020 308 Views

MethodHandles class introduced in Java 7 version. This class primarily added some static methods to better the functionality, and falls into several categories like Lookup methods that help to create method handles for methods and fields, Combinator methods that combine or transform pre-existing method handles into new ones, and factory methods to create method handles that emulate other common JVM operations or control flow patterns. MethodHandles class has enhanced in Java 9 to introduce many changes and added new static methods like arrayLength(), arrayConstructor(), zero(), and etc.Syntaxpublic class MethodHandles extends ObjectExampleimport java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; public class MethodHandlesTest {    public void MethodHandle1() {   ...

Read More

MongoDB: combining AND and OR?

AmitDiwan
AmitDiwan
Updated on 31-Mar-2020 689 Views

Let us first create a collection with documents −> db.demo293.insertOne({FirstName:"Chris", LastName:"Brown", Age:24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e4d45075d93261e4bc9ea32") } > db.demo293.insertOne({FirstName:"David", LastName:"Miller", Age:23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e4d45265d93261e4bc9ea33") } > db.demo293.insertOne({FirstName:"John", LastName:"Smith", Age:24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e4d45385d93261e4bc9ea34") } > db.demo293.insertOne({FirstName:"Adam", LastName:"Doe", Age:21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e4d46cf5d93261e4bc9ea35") }Display all documents from a collection with the help of find() method −> db.demo293.find();This will produce the following output −{ "_id" : ObjectId("5e4d45075d93261e4bc9ea32"), "FirstName" : "Chris", "LastName" : "Brown", "Age" : 24 } { "_id" : ObjectId("5e4d45265d93261e4bc9ea33"), ...

Read More
Showing 48451–48460 of 61,248 articles
Advertisements