Found 33676 Articles for Programming

How does a vector work in C++?

Revathi Satya Kondra
Updated on 30-Apr-2025 18:22:16

364 Views

In C++, a vector is a dynamic array that can grow or shrink automatically. It can store elements in a row (contiguous memory) and resizes itself when needed. When it runs out of space, it creates a bigger array, copies the old data, and adds the new one. So, you can easily add, remove, or access elements using functions like push_back(), size(), and erase(). Basic Operations (push_back, access) A vector stores elements in a contiguous memory block. You can add elements using push_back() and access them using [] or at(). Syntax Following is the syntax is as follows: vector vec; ... Read More

How to get the datatype of a column of a table using JDBC?

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

3K+ Views

You can get the datatype of a column of a table using the getColumnType() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type String column_name = rsmd.getColumnTypeName(2);Assume we have a table named employee_data in the database with the description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    | | | Name     | varchar(255) ... Read More

C++ Program to Compute Cross Product of Two Vectors

karthikeya Boyini
Updated on 26-Feb-2020 09:17:44

8K+ Views

This is a C++ program to compute Cross Product of Two Vectors.Let us suppose, M = m1 * i + m2 * j + m3 * kN = n1 * i + n2 * j + n3 * k.So, cross product = (m2 * n3 – m3 * n2) * i + (m1 * n3 – m3 * n1) * j + (m1 * n1 – m2 * n1) * kwhere m2 * n3 – m3 * n2, m1 * n3 – m3 * n1 and m1 * n1 – m2 * n1 are the coefficients of unit vector along ... Read More

Binary search in sorted vector of pairs in C++

Ravi Ranjan
Updated on 18-Aug-2025 16:08:48

601 Views

In this article, we have a sorted vector of pairs. Our task is to search for a target key using binary search in the given vector of pairs. Binary Search Algorithm The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, it should be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left or right sub-array or ... Read More

Exception handling and object destruction in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 13:11:44

888 Views

In this article, you will learn what is exception handling, object destruction, and Handing exception thrown in Object Destructor in C++. C++ Exception Handling An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw. try: This block contains the code ... Read More

Catching base and derived classes exceptions in C++

Revathi Satya Kondra
Updated on 07-May-2025 14:33:33

2K+ Views

To catch an exception for both base and derived classes, we need to put the catch block of the derived class before the base class. Otherwise, the catch block for the derived class will never be reached. This happens because C++ follows a top-down approach when checking catch blocks. So, by placing the derived class catch block first, we ensure that specific exceptions are handled correctly before falling back on the base class. Algorithm Following is the algorithm to catch Base and Derived classes Exceptions in C++: Begin Declare a class B. Declare another ... Read More

How to get the number of records in a table using JDBC?

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

489 Views

The ResultSet class doesn’t provide any direct method to get the number of records in a table.The beforeFirst() method navigates the pointer/curser of the ResultSet object to its default position before first.In the same way the last() method positions the cursor at the last row of the ResultSet object.Using these methods you can find the number of records in the current ResultSet object.ExampleAssume we have a table named customers table with contents as shown below:+----+---------+-----+---------+----------------+ | ID | NAME    | AGE | SALARY  | ADDRESS        | +----+---------+-----+---------+----------------+ | 1  | Amit    | 25  | 3000.00 ... Read More

How to declare a pointer to a function in C?

Revathi Satya Kondra
Updated on 06-May-2025 18:53:52

6K+ Views

In C, a pointer is a variable whose value is the address of another variable or memory block, i.e direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable or block address. Basic Pointer to a Function A pointer to a function is simply a variable that stores the address of a function instead of a normal data value. Syntax Following is the syntax of basic pointer to a function: Datatype *variable_name Algorithm Following is the algorithm for the basic pointer to a Function: Begin. ... Read More

The contains() method of Java AbstractCollection class

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

127 Views

The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.The syntax is as follows:public boolean contains(Object ele)Here, ele is the element to be checked for existence.To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection contains() method in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Football");   ... Read More

How to create and release a save point in JDBC?

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

970 Views

When you set a save point you define a logical rollback point within a transaction. If an error occurs past a save point, you can use the rollback method to undo either all the changes or only the changes made after the save point.Savepoint interface gives you the additional transactional control. Most modern DBMS, support save points within their environments such as Oracle's PL/SQL.Setting a save pointYou can set a save point in a database using the setSavepoint(String savepointName) method of the Connection interface, this method accepts a string value representing the name of the save point and returns a ... Read More

Advertisements