Found 7197 Articles for C++

How to generate different random numbers in a loop in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

4K+ Views

Let us see how to generate different random numbers using C++. Here we are generating random numbers in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C++ library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below −void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number ... Read More

Returning multiple values from a C++ function

Aman Kumar
Updated on 12-Jun-2025 17:51:03

9K+ Views

In C++, we cannot return multiple values from a function directly. But, by using some methods (i.e., techniques), we can return multiple values from a function. How to Return Multiple Values from a Function? A function can return only one value using the return statement. We can return multiple values (more than one value) from a function by using the "call by address" and "call by reference" approach in the invoker function. Return Multiple Values from a Function Using Call by Address In C++, the call is an address, also known as a call by pointer. It passes ... Read More

Checking if a double (or float) is NaN in C++

Aman Kumar
Updated on 18-Jun-2025 18:47:53

14K+ Views

In this article we will check whether a double or floating point number is NaN (Not a Number) in C++. Checking if a Double or Floating Point Number is NaN To check, we can utilise the isnan() method. The isnan() function is available in the cmath library. This function was introduced in C++ version 11. So From C++11 next, we can use this function. The isnan() function is used to determine whether a double or floating point number is not-a-number (NaN) value. Return true if num is NaN, false otherwise. C++ Program to Check Double or Float Number is NaN ... Read More

How do you get assembler output from C/C++ source in gcc?

Aman Kumar
Updated on 30-Jun-2025 13:22:39

3K+ Views

In this article, we will see how to generate the assembler output from C or C++ code using GCC. What is GCC The GCC, which stands for GNU Compiler Collection, is a set of compilers and development tools available for various operating systems such as Linux, Windows, and a wide variety of other OSs (operating systems). It supports mostly C and C++, but also Objective-C, Ada, Go, Fortran, and D. The Free Software Foundation (FSF) created GCC and distributed it as totally free (as in libre) software. How to Get Assembler Output The GCC has a great feature that allows ... Read More

Order of evaluation in C++ function parameters

Aman Kumar
Updated on 04-Aug-2025 16:02:00

249 Views

In C++, when we pass multiple arguments to a function, a common question arises, in what order are these arguments evaluated? Is it from left to right, right to left, or does it depend on the compiler? In this article, we will learn how function parameter evaluation works in C++, why the order of evaluation is important, and how it can vary across different compilers. Is the Order of Evaluation Defined in C++? The C++ standard does not guarantee a fixed order of evaluation for function arguments. This means compilers are free to evaluate arguments from left to ... Read More

RTTI (Run-time type Information) in C++ program

Aman Kumar
Updated on 15-May-2025 15:39:38

2K+ Views

In C++, RTTI (Run-time type information) is a process that disclose information about an object data types at runtime and available one for the classes that have at least one virtual function. It allow the type of an object to be determine during the program execution. Runtime Casts The runtime cast checks that the cast is valid. It is the simplest approach to confirm the runtime type of an object using a pointer or reference. It is especially beneficial when we cast a pointer from a base class to a derived type. There are two types of casting: ... Read More

Copy elision in C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

226 Views

The Copy Elision is also known as the Copy Omission. This is one of the compiler optimization technique. It avoids the unnecessary copying of objects. Almost any current compiler uses this Copy Elision technique.Let us see how it works by the help of one example code:Example Code#include using namespace std; class MyClass {    public:       MyClass(const char* str = "\0") {  //default constructor          cout

How to Parse Command Line Arguments in C++?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

583 Views

It is possible to pass some values from the command line to your C++ programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard-coding those values inside the code.The command line arguments are handled using main() function arguments where argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program. Following is a simple example which checks if there is any argument supplied from ... Read More

What does the operation c=a+++b mean in C/C++?

Aman Kumar
Updated on 30-Jul-2025 15:03:20

2K+ Views

In C/C++, the expression c = a++ + b indicates that the current value of a is added to b, and the result is assigned to c. After this assignment, a is incremented by 1 (post-increment), which means the increment of a happens after its value is used in the expression. Well, let a and b initialize with 2 and 5, respectively. This expression can be taken as two different types. c = (a++) + b c = a + (++b) The above two expressions contain both post and pre-increment ... Read More

Is there a performance difference between i++ and ++i in C++ program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

The effective result of i++ and ++i are same. The only difference is that the i++ increases the value of i after assigning it, and for ++i, it increases the value first, then assigns its value. We can see the difference in the following code.Example Code#include using namespace std; int main() {    int x = 3, y, z;    y = x++;    z = ++x;    cout

Advertisements