Category Archives: C/C++

random header | Set 2 (Distributions)

Set 1 (Generators) Distributions I. Uniform : uniform_int_distribution: It produces random integer values i, which are uniformly distributed on the closed interval [a,b], which is described by the following probability mass function: operator(): It generates the random number that are distributed according to the probability function. min: It returns the greatest lower bound of the… Read More »

User Defined Literals in C++

User Defined Literals (UDL) are added in C++ from C++11. Although, C++ provides literals for a variety of built-in types but these are limited. Examples of literals for built-in types : // Examples of classical literals for built-in types. 42 // int 2.4 // double 3.2F // float ‘w’ // char 32ULL // Unsigned long… Read More »

random header in C++ | Set 1(Generators)

This header introduces random number generation facilities. This library allows to produce random numbers using combinations of generators and distributions. Generators: Objects that generate uniformly distributed numbers. Distributions: Objects that transform sequences of numbers generated by a generator into sequences of numbers that follow a specific random variable distribution, such as uniform, Normal or Binomial.… Read More »

Using a variable as format specifier in C

It is known that, printf() function is an inbuilt library function in C programming language in the header file stdio.h. It is used to print a character, string, float, integer etc. onto the output screen. However, while printing the float values, the number of digits following the decimal point can be controlled by the user.… Read More »

Command line arguments in C/C++

The most important function of C/C++ is main() function. It is mostly defined with a return type of int and without parameters : int main() { /* … */ } We can also give command-line arguments in C and C++. Command-line arguments are given after the name of the program in command-line shell of Operating… Read More »

Builtin functions of GCC compiler

These are three important builtin functions in GCC compiler: _builtin_popcount(x): This function is used to count the number of one’s(set bits) in an integer. Example: if x = 4 binary value of 4 is 100 Output: No of ones is 1. Output: Count of 1s in binary of 5 is 2 __builtin_clz(x): This function is… Read More »

Placement new operator in C++

Placement new is a variation new operator in C++. Normal new operator does two things : (1) Allocates memory (2) Constructs an object in allocated memory. Placement new allows us to separate above two things. In placement new, we can pass a preallocated memory and construct an object in the passed memory. new vs placement new… Read More »

Advanced C++ with boost library

Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. For example, they are helpful for handling large numbers having range beyond the long long, long double data type (264) in C++. Installation Please refer this Article for installation of boost. We can download the zip file. After that… Read More »

Array Type Manipulation in C++

This article demonstrates some of the inbuilt functions that can be used to query and manipulate array types, even a multidimensional array. These functions can be useful in cases we need information or manipulate array we initiated with different dimensions. These functions are defined in header file . Some of the functions include : is_array()… Read More »