Ayush Gupta has Published 527 Articles

Coroutines in C/C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 10:14:42

290 Views

In this tutorial, we will be discussing a program to understand coroutines in C/C++.Coroutines are control instructions which switch the execution control between two routines which returning any of them.Example Live Demo#include int range(int a, int b){    static long long int i;    static int state = 0;    switch ... Read More

Creating a C/C++ Code Formatting tool with help of Clang tools

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 10:11:22

237 Views

In this tutorial, we will be discussing a program to create a C/C++ code formatting tool with the help of clang tools.SETUPsudo apt install python sudo apt install clang-format-3.5Then we will create a python file in location where the current user has read and write permissions.Exampleimport os cpp_extensions = (".cxx", ... Read More

Counts of distinct consecutive sub-string of length two using C++ STL

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 10:04:44

156 Views

In this tutorial, we will be discussing a program to count distinct consecutive sub-string of length two using C++ STL.For this we will provided with a string. Our task is to count and print all the unique substrings of length two from the given string.Example Live Demo#include using namespace std; void ... Read More

Counting Inversions using Set in C++ STL

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 10:02:31

271 Views

In this tutorial, we will be discussing a program to count inversions using set in C++ STL.Inversion count is a measure of how near the array is to be completely sorted. If the array is already sorted, the inversion count will be 0.Example Live Demo#include using namespace std; //returning inversion count ... Read More

Count the number of 1’s and 0’s in a binary array using STL in C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 10:00:27

423 Views

In this tutorial, we will be discussing a program to count the number of 1’s and 0’s in a binary array using STL in C++.For this we will be provided with an array. Our task is to count the number of 0’s and 1’s present in the array.Example Live Demo#include ... Read More

Count smaller elements on right side using Set in C++ STL

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 09:58:45

315 Views

In this tutorial, we will be discussing a program to count smaller elements on right side using set in C++ STL.For this we will be provided with an array. Our task is to construct a new array and add the number of smaller elements on the right side of the ... Read More

Count smaller elements in sorted array in C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 09:55:50

313 Views

In this tutorial, we will be discussing a program to count smaller elements in sorted array in C++.In this we will be given a number and our task is to count all the elements present in the sorted array which are smaller than the given number.Example Live Demo#include using namespace ... Read More

Core Dump (Segmentation fault) in C/C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 09:54:10

5K+ Views

In this tutorial, we will be discussing a program to understand core dump (segmentation fault) in C/C++.It happens due to reasons like when code tries to write on read only memory or tries to access corrupt memory location.ExampleModifying a string literalint main(){    char *str;    str = "GfG";   ... Read More

Converting Strings to Numbers in C/C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 09:52:05

306 Views

In this tutorial, we will be discussing a program to understand how to convert strings into numbers in C/C++.C/C++ provides two ways to convert strings into numbers.Example Live DemoUsing sscanf()#include int main(){    const char *str = "12345";    int x;    sscanf(str, "%d", &x);    printf("The value of x : ... Read More

Convert a String to Integer Array in C/C++

Ayush Gupta

Ayush Gupta

Updated on 16-Mar-2020 09:50:25

3K+ Views

In this tutorial, we will be discussing a program to understand how to convert a string into integer array in C/C++.For this we will create a new array. Traverse through the given string, if the character is a comma “, ”, we move on to the next character else add ... Read More

Advertisements