Found 33676 Articles for Programming

Set vs Map in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

Set is an abstract data type in which each element has to be unique because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, but it is possible to remove and add the modified value of that element.A Map is an associative container that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values.So, it is clear from above that, set contains the only key, and map contains a value with ... Read More

Set find() function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

601 Views

Set find() function in C++ STL returns an iterator to the element which is searched in the set container. The iterator points to the position just after the last element in the set, if the element is not found.AlgorithmBegin    Define function printS() to print elements of set container.    initialize an empty set container s. Insert some elements in s    set container. Call function to print elements of set container.    Call the set find() function to find an element from s set container.    If element is in the set then       Print elememt is ... Read More

When is copy constructor called in C++?

Revathi Satya Kondra
Updated on 26-May-2025 16:41:09

1K+ Views

The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to Initialize one object from another of the same type. Copy an object to pass it as an argument to a function. Copy an object to return it from a function. If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer variables and has some dynamic ... Read More

Functors in C++

Revathi Satya Kondra
Updated on 26-May-2025 16:50:30

376 Views

The functors are the function objects in C++. The functor allows an instance object of some class to be called as if it were an ordinary function. Let us consider a function that takes one argument. We can use this function as function object to do some task on a set of data. The Functors are widely used in STL algorithms like transform(), sort(), etc. Functor vs Regular Function: Need of Functor? Imagine we have a function that takes only one argument, like this: int increment(int x) { return x + 1; } Now, what ... Read More

Return from void functions in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 13:16:07

18K+ Views

The void functions are called void because they do not return anything. "A void function cannot return anything" this statement is not always true. From a void function, we cannot return any values, but we can return something other than values. Some of them are like below. A void function can return A void function cannot return any values. But we can use the return statement. It indicates that the function is terminated.ExampleThe following example demonstrates a void function with the return statement: #include using namespace std; void my_func() { cout

What should we assign to a C++ pointer: A Null or 0?

Revathi Satya Kondra
Updated on 12-Jun-2025 14:25:46

1K+ Views

In C++, a pointer stores the address of another variable, which means that the pointer itself does not contain a value of its own. However, you can assign a null value or a 0 to a pointer, in which case the pointer will not point to the address of any other variable. NULL: It is special constant that indicates the pointer does not point to any valid memory location i.e., an Empty Pointer. 0: It is an older way to represent a null pointer to indicate that the pointer points to nothing. nullptr: It is introduced in C++11, it ... Read More

What is the size of a pointer in C/C++?

Revathi Satya Kondra
Updated on 27-May-2025 17:14:33

10K+ Views

The size of a pointer in C/C++ is not fixed. It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor, for example for a 32 bit computer the pointer size can be 4 bytes and for a 64 bit computer the pointer size can be 8 bytes. So for a specific architecture pointer size will be fixed. It is common to all data types like int *, float * etc. Depending on the system architecture, pointer size may vary. The following table shows the pointer size based on the ... Read More

How to retrieve multiple ResultSets from a stored procedure using a JDBC program?

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

6K+ Views

Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.Retrieving Results from a procedure:You can call an existing stored procedure using the CallableStatement. The prepareCall() method of the Connection interface accepts the procedure call in string format and returns a callable statement object.CallableStatement cstmt = con.prepareCall("{call sampleProcedure()}");Execute the above created callable statement using ... Read More

How to connect to a MongoDB database using a JDBC program?

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

1K+ Views

MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document.Before you start connecting MongoDB in you need to make sure that you have MongoDB JDBC driver. If not, download the jar from the path Download mongo.jar and, add it to your classpath.ExampleFollowing JDBC program establishes connection with the MongoDB database and creates a collection in it.import com.mongodb.client.MongoDatabase; import com.mongodb.MongoClient; import com.mongodb.MongoCredential; public class CreatingCollection {    public static void main( String args[] ) {       // Creating a Mongo client       MongoClient ... Read More

What is the easiest way to initialize a std::vector with hardcoded elements in C++?

Revathi Satya Kondra
Updated on 12-Jun-2025 13:45:58

660 Views

In C++, a std::vector is a container that is a part of the STL (Standard Template Library). It enables dynamic arrays which can adjust their size automatically. Depending on the requirements and version of C++ being used, there are many ways to initialize a std::vector with hardcoded elements. Initializing a std::vector with Hardcoded Elements Some of the approaches to initialize a std::vector with hardcoded elements in C++: Using Initializer List Using assign() Function Using accumulate() function Initializing Vector Using Initializer List An initializer list is a ... Read More

Advertisements