Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the difference between a definition and a declaration in C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 12-Jun-2025 2K+ Views

In C++, declaration and definition are often confused. A declaration tells the compiler about the name and type, while a definition allocates memory or provides implementation. In this article, we will understand their differences with examples. What is a Declaration in C++? A declaration means (in C or C++) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of the declaration. Following is the syntax to ...

Read More

Count distinct elements in an array in C++

Ravi Ranjan
Ravi Ranjan
Updated on 11-Jun-2025 8K+ Views

In this article, we have an unsorted array of integers having repetitive elements. Our task is to count the distinct elements in the given array in C++. Example Here is an example of counting the unique number in the given array: Input: array = {4, 2, 32, 26, 57, 52, 40, 2, 57, 40, 33} Output: Distinct elements in the array: 8 Here is a list of approaches for counting distinct elements in the given array: Using Nested for Loop Using Sorting ...

Read More

C++ Program to Demonstrate the Implementation of 4-Color Problem

Farhan Muhamed
Farhan Muhamed
Updated on 11-Jun-2025 922 Views

In this article, we will explain the 4 color problem to color a graph and implement the backtracking algorithm to solve it in C++. The 4 Color Problem The 4-color problem states that the maximum number of colors needed to color any planar graph (or a 2D map) is four, such that no two adjacent nodes have the same color. For example, suppose that you want to color a world map, such that no two countries sharing a border have the same color. According to this theorem, the maximum number of colors needed to do this is four. Now, ...

Read More

A Sum Array Puzzle in C++?

Ravi Ranjan
Ravi Ranjan
Updated on 11-Jun-2025 362 Views

In this article, we will solve a sum array puzzle, where we have an array with n elements. We have to create another array of n elements such that the 'ith' position of the second array will hold the sum of all elements of the first array except the 'ith' element. We have one constraint, we cannot use the subtraction operator in this problem. Example Here is an example of calculating the sum of array elements except for the ith element: Input: arr[] = {5, 6, 7, 8} Output: res[] = ...

Read More

How to get the IP Address of local computer using C/C++?

Akansha Kumari
Akansha Kumari
Updated on 11-Jun-2025 10K+ Views

In this article, we will see how to get the Host name and IP address of the local system in an easier way using C and C++ program.  Getting IP Address of Local Computer For this, some standard networking functions are available in socket programming with header files like on Windows and , , on Linux. In this article we will mainly discuss three commonly used functions: Sr.No ...

Read More

What is the use of the Optional.stream() method in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Jun-2025 2K+ Views

In this article, we will learn about the use of the Optional.stream() method in Java 9. First, we will learn about the optional class and its method. Then we will see the use cases along with an example.Optional class The Optional class was introduced in Java 8 to reduce the null pointer exception that occurs in Java. It is basically a container for the actual object that needs to be returned by a method. The point here is that if a method returns a null value, which can be null, then that method could return a value instead contained inside ...

Read More

What is the JLink tool in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Jun-2025 591 Views

What is JLink? Java Linker is a new linker tool that has been used to create our own customized JRE. Usually, we can run our program using default JRE provided by Oracle. If we need to create our own JRE then use this tool. JLink tool can help to create its own JRE with only the required class to run the application. It can reduce the size of the API developed and the dependency of using the full JRE.  In Java 9, we have a new phase between compiling the code and its execution, link time. Link time is an optional phase between the phases of ...

Read More

How to create scratch variables in JShell in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 11-Jun-2025 462 Views

JShell is a REPL interactive tool introduced in Java 9 to execute and evaluate simple Java programs like variable declarations, statements, expressions, and programs without using the main() method.In this article, we will learn to create scratch variables in JShell in Java 9. Variables in JShell In Java 9, JShell allows for the declaration and use of variables without the need for a surrounding class or method structure. One may be able to explicitly declare the variable with a type, or else it might be declared implicitly using var for type inference. C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 ...

Read More

Printing the correct number of decimal points with cout in C++

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 11-Jun-2025 17K+ Views

When working with floating-point numbers in C++, it's important to know how to control the number of decimal places displayed in the output. By default, cout may not always print the expected number of digits after the decimal point.How to Print Correct Number of Decimal Points with cout?To display numbers with a specific number of decimal places using cout, you can use the setprecision() function, which accepts an integer value representing the number of digits after the decimal to be printed and returns a stream manipulator that formats the number with the specified precision. The setprecision() function belongs to the ...

Read More

How to initialize const member variable in a C++ class?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 11-Jun-2025 18K+ Views

A const member variable in a C++ class is a data member whose value must be initialized during object construction and cannot be modified. Initializing Const Member Variable in C++ Class The const member variable must be initialized. To initialize a const member variable, you can use a member initializer list using a constructor, . The member initializer list is the special way to initialize the values to class variables while creating an object before the constructor block runs. Note: If the member is static and of an integer type, you can directly initialized with the class definition. ...

Read More
Showing 30581–30590 of 61,297 articles
Advertisements