Programming Articles - Page 2701 of 3366

Array — Efficient arrays of numeric values in Python

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

333 Views

Array is a very popular data structure in C/C++, Java etc. In these languages array is defined as a collection of more than one elements of similar data type. Python doesn't have any built-in equivalent of array. It's List as well as Tuple is a collection of elements but they may of different types.Python's array module emulates C type array. The module defines 'array' class. Following constructor creates an array object:array(typecode, initializer)The typecode argument determines the type of array. Initializer should be a sequence with all elements of matching type.Following statement creates an integer array object:>>> import array >>> arr ... 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

233 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

595 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

_Noreturn function specifier in C

Ravi Ranjan
Updated on 11-Jul-2025 18:16:55

241 Views

The _Noreturn function specifier in C indicates to the compiler that the function will either exit or run in an infinite loop. This function never returns the control to the main function or wherever it was called in the program. If the _Noreturn function uses the return statement, the compiler will generate a warning or show an undefined behavior. Syntax of _Noreturn Function Specifier The syntax of _Noreturn function specifier is given below: _Noreturn data_type function_name() { --- code lines --- } _Noreturn with exit() Function in ... Read More

What happens when a function is called before its declaration in C?

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

351 Views

If we do not use some function prototypes, and the function body is declared in some section which is present after the calling statement of that function. In such a case, the compiler thinks that the default return type is an integer. But if the function returns some other type of value, it returns an error. If the return type is also an integer, then it will work fine, sometimes this may generate some warnings.Example Code#include main() {    printf("The returned value: %d", function); } char function() {    return 'T'; //return T as character }Output[Error] conflicting types for 'function' ... Read More

What is the purpose of a function prototype in C/C++?

Aman Kumar
Updated on 12-Jun-2025 14:58:45

6K+ Views

In this article, we will explore the purpose of using function prototypes in C or C++. What are Function Prototypes? The function prototypes tell the compiler about the number of arguments and the required data types of function parameters; they also tell the compiler about the return type of the function. With this information, the compiler cross-checks the function signatures before calling it. If the function prototypes are not mentioned, then the program may be compiled with some warnings and sometimes generate some strange output. Purpose of a Function Prototype When a function is called before it is defined, and ... Read More

How can we return multiple values from a function in C/C++?

Aman Kumar
Updated on 18-Jun-2025 18:38:24

28K+ Views

In C or C++, we cannot return multiple values from a function directly. In this Article, we will see how to use some trick to return more than one value from a function. Returning Multiple Values from a Function We can return multiple values from a function by using the method. Below is the list of methods that are used to return multiple values from a function in C/C++: Using Pointers Using Structures Using Arrays Returning Multiple Values Using Pointers Pass the arguments by their addresses ... Read More

Advertisements