Difference Between Namespace and Class in C++

Aman Kumar
Updated on 18-Jun-2025 18:44:13

6K+ Views

In this article, we will see the differences between namespace and class in C++. Namespace and classes are two different concepts, so let's discuss them: Classes are datatypes. It is an expanded version of the structures. Classes can contain data members and functions as members, but namespaces can contain variables and functions by grouping them into one and cannot be created as objects; it is used as additional information to differentiate similar functions, classes, variables, etc. Variables, functions with the same name can be placed in different namespaces. What is Namespace? The namespace is a feature that provides a way ... Read More

Variadic Function Templates in C++

Aman Kumar
Updated on 18-Jun-2025 18:43:09

312 Views

What is Variadic Function In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., a function that accepts a variable number of arguments. So, In C++ programming, we can say that a function that accepts a variable number of arguments is variadic function. Why Variadic Function Templates Are Used? In C++, templates can only have a fixed number of parameters, which must be specified at the time of declaration. However, variadic templates can help to solve this issue. Syntax to Create Variadic Function Following is the variadic function template syntax: template return_type function_name(arg var1, ... Read More

Difference Between a Virtual Function and a Pure Virtual Function in C++

Aman Kumar
Updated on 18-Jun-2025 18:40:06

7K+ Views

In C++, virtual and pure virtual functions are key features supporting polymorphism both allow different classes to respond uniquely to the same function call. What is Virtual Function A virtual function in C++ is a member function in a base class, which allows a function to be overridden in the derived class. This process helps in enabling runtime polymorphism. A virtual function is declared in the base class using the virtual keyword. Syntax Following is the syntax of the virtual function: class BaseClassName { public: virtual void func_name() { // implementation ... Read More

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

C++ Conversion Operators Guide

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

Placement New Operator in C++

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

1K+ 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

Heap Overflow and Stack Overflow Explained

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

583 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

Generate UnsupportedOperationException in Java

Vivek Verma
Updated on 18-Jun-2025 18:31:11

466 Views

In Java, an exception is an event that occurs during the execution of a program. When an Exception occurs, the normal flow of the program is disrupted, and the program/application terminates abnormally, which is not recommended; therefore, these exceptions can be handled. What is UnsupportedOperationException in Java? An UnsupportedOperationException is a subclass of the RuntimException class in Java, and it can be thrown to indicate that the requested operation is not supported. The UnsupportedOperationException class is a member of the Java Collections Framework. This exception is thrown by almost all of the concrete collections like List, Queue, Set, and Map. ... Read More

Uses of Generic Collections in Java

Vivek Verma
Updated on 18-Jun-2025 18:30:32

7K+ Views

What are Generic Collections in Java? In Java, the Generic collections were introduced in Java 5. These collections disable the type-casting, and there is no need for explicit type-casting if we use generic collections. The generic collections are type-safe and detect type-related errors at compile time. It allows the datatypes to pass as parameters to classes or interfaces. The Compiler is responsible for checking the compatibility of the types. Syntax Following is the way to create generic collections in Java: class or interface Where type specifies the type of the object, such as: Integer, String, Character, etc.. You can create generic ... Read More

Differences Between Collection and Collections in Java

Vivek Verma
Updated on 18-Jun-2025 18:25:58

8K+ Views

In Java, Collection and Collections are important components of the Collections Framework. The Collection has various sub-interfaces such as Set, List, and Queue. The Collections provides static methods to perform various operations on collections, such as sorting, searching, and synchronization. Let's learn them one by one with proper definitions, syntax, and a suitable example. The Collection Interface In Java, the Collection is an interface, which is considered the root interface in the collection hierarchy. It represents a group of objects, which are known as its elements. Some collections allow duplicate values and specific orders, whereas some do not allow duplicates ... Read More

Previous 1 ... 3 4 5 6 7 ... 7807 Next
Advertisements