Found 33676 Articles for Programming

IntStream sequential() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

441 Views

The sequential() method of the IntStream class in Java is used to return a sequential IntStream. The syntax is as follows:IntStream sequential()First, create an IntStream and elements in a range using the range() method:IntStream intStream1 = IntStream.range(11, 21);Now, for a sequential IntStream, use the sequential() method like this:IntStream intStream2 = intStream1.sequential();The following is an example to implement IntStream sequential() method in Java:Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream1 = IntStream.range(11, 21);       IntStream intStream2 = intStream1.sequential();       intStream2.forEach(System.out::println);    } }Output11 12 ... Read More

C++ Program to Implement Hash Tables with Quadratic Probing

Aman Kumar
Updated on 28-May-2025 16:51:57

2K+ Views

Hash Table A hash table is a data structure which is used to store key-value pairs and uses hash function to compute an index into an array of buckets or slots in which an element will be inserted or searched in average-case constant time. Why are Collision a Problem? A collision is a problem because even a perfect hash function can generate the same index for multiple keys, causing a collision. To resolve these, we use techniques like − Chaining Linear Probing Quadratic Probing Quadratic Probing ... Read More

Variable number of arguments in C++

Aman Kumar
Updated on 28-May-2025 16:51:15

7K+ Views

Sometimes, you may come across a scenario where you want to have a function that can take a variable number of arguments, i.e., parameters, instead of a predefined number of parameters. The C/C++ programming language provides a solution for this scenario, and you are allowed to define a function that can accept a variable number of parameters based on your requirement. Following are the ways to use variable number of arguments − C-style Variadic Functions (with stdarg.h) C-style variadic functions in C++ use stdarg.h macros like va_start, va_arg, and va_end to handle a variable number of arguments at runtime. int ... Read More

Heap overflow and Stack overflow in C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

6K+ Views

Heap OverflowHeap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables.Heap overflow occurs when −A) If we allocate dynamic large number of variables −int main() {    float *ptr = (int *)malloc(sizeof(float)*1000000.0)); }B) If we continuously allocate memory and do not free after using it.int main() {    for (int i=0; i

How do I clear the cin buffer in C++?

Aman Kumar
Updated on 06-Jun-2025 19:39:15

2K+ Views

Before knowing the solution to clearing the cin buffer in C++, let us first see what the buffer is in C++. What is The Buffer in C++ A buffer is a temporary storage area that holds data while standard I/O devices are in use. In C++, a stream also work as a buffer. When a key is pressed, the input is not immediately sent to the program; instead, it is stored in a buffer. The operating system keeps this data in the buffer until the program is allocated time to process it. Why We Clear The cin Buffer in C++ ... Read More

Heap overflow and Stack overflow

Aman Kumar
Updated on 18-Jun-2025 18:31:25

651 Views

Heap and stack overflows are both types of buffer overflows that occur when a program attempts to write data beyond the allocated boundary of a buffer. Heap Overflow Heap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables. Following are the regions where heap overflow occurs − If we allocate dynamic large number of variables int main() { float *ptr = (int *)malloc(sizeof(float)*1000000.0)); } If we continuously allocate memory and do not free after using it. int main() { for (int i=0; i

What uses are there for “placement new” in C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

206 Views

In this section we will see what is the placement new operator in C++. This placement new is another variation of new operator. The normal new operator performs two things. It allocates memory, and then constructs an object in allocated memory.The new operator allocates memory in the heap section and constructs objects there. But for the placement new operator, it constructs object at the given address. To deallocate memory, we can use delete keyword if the memory is allocated using new operator. But for placement new there is no placement delete feature.So in a nutshell, placement new allows you to ... Read More

Placement new operator in C++

Aman Kumar
Updated on 18-Jun-2025 18:33:22

2K+ Views

In C++, we allocate the memory dynamically using the new operator. But there is a special version of this operator known as placement new operator. The new operator performs two things. It allocates memory, and then constructs an object in allocated memory. But for the placement new operator, it constructs object at the given address. What is Placement New? The placement new operator allows you to construct an object at a specific memory location. Its syntax lets you place an object at a pre-allocated memory address instead of letting the compiler allocate memory. new (address) Type (constructor_args); Where ... Read More

Conversion Operators in C++

Aman Kumar
Updated on 18-Jun-2025 18:35:59

2K+ Views

What is Conversion Operator Conversion operators are a type of operator overloading in C++. These operators are commonly known as type-cast operators. They enable a class or structure to specify how an object should be converted into another data type. Sometimes we need to convert concrete-type objects to some other type of objects or primitive data types. To make this conversion we can use a conversion operator. Following is the syntax to use the conversion: class ClassName { public: operator TargetType() const { // conversion logic } }; ... Read More

How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

324 Views

In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --.To solve this problem, we can solve them using binary adder logic. In that case we were designed half adder and full adder. These adders can add one bit binary numbers. By cascading multiple adders, we have can create circuit to add bigger numbers.In that adder, we have performed XOR operation among the numbers, then for the carry we were performing the ANDing logic. These features are implemented here to add two numbers.Example Code Live Demo#include using namespace std; int ... Read More

Advertisements