Programming Articles - Page 1986 of 3366

Last element of vector in C++ (Accessing and updating)

Sunidhi Bansal
Updated on 21-Feb-2025 16:28:57

1K+ Views

In this article, we will learn how to access and update the last element of a vector in C++. A vector in C++ is a dynamic array that can adjust its size automatically, allowing us to store and manage a collection of elements. Sometimes, we need to access or update the last element for tasks like changing data or performing calculations. Let's look at a simple example to better understand: Given a vector: std::vector vec = {10, 20, 30, 40, 50}; The last element of the vector is 50. If we want to update the last element to 100, ... Read More

remainder() in C++ program

Sunidhi Bansal
Updated on 22-Apr-2020 12:34:10

352 Views

In this article, we will be discussing the working, syntax, and examples of remainder() function in C++.What is remainder()?remainder() function is an inbuilt function in C++ STL, which is defined in header file. remainder() is used to find the remainder of the parameters.This function takes two arguments, one for the numerator and second for the and computes its remainder and returns a floating-point which is rounded to the nearest.This function computes −remainder = numerator – roundquot * denominator;In which “remainder” is the resulting numerator being the first argument and denominator is the second argument and roundquot is the rounded ... Read More

rand() and srand() in C/C++

Sunidhi Bansal
Updated on 22-Apr-2020 12:32:02

11K+ Views

In this article, we will be discussing the working, syntax, and examples of rand() and srand() function in C++ STL.What is rand()?rand() function is an inbuilt function in C++ STL, which is defined in header file. rand() is used to generate a series of random numbers. We use this function when we want to generate a random number in our code.Like we are making a game of ludo in C++ and we have to generate any random number between 1 and 6 so we can use rand() to generate a random number.The random number is generated by using an ... Read More

ratio_not_equal() in C++ with examples

Sunidhi Bansal
Updated on 22-Apr-2020 12:29:20

162 Views

In this article, we will be discussing the working, syntax, and examples of ratio_not_equal template in C++ STL.What is ratio_not_equal template?ratio_not_equal template is inbuilt in C++ STL, which is defined in header file. ratio_not_equal is used to compare the two ratios that are unequal. This template accepts two parameters and check whether the given ratios should not be equal. Like we have two ratios, 1/2 and 3/9 which are not equal so it stands true for the given template. This function returns true when the two ratios are unequal.So, when we want to check for the inequality of the ... Read More

ratio_equal() in C++ with example

Sunidhi Bansal
Updated on 22-Apr-2020 12:27:34

270 Views

In this article, we will be discussing the working, syntax, and examples of ratio_equal() function in C++ STL.What is ratio_equal template?ratio_equal template is inbuilt in C++ STL, which is defined in header file. ratio_equal is used to compare the two ratios. This template accepts two parameters and checks whether the given ratios are equal or not. Like we have two ratios, 1/2 and 3/6 which are equal when we simplify them but the numbers are not equal so C++ has an inbuilt template to check whether the two ratios are equal or not and return true if they are ... Read More

stack top() in C++ STL

Sunidhi Bansal
Updated on 22-Apr-2020 12:25:00

7K+ Views

In this article, we will be discussing the working, syntax, and examples of stack::top() function in C++ STL.What is Stack in C++ STL?Stacks are the data structure that stores the data in LIFO (Last In First Out) where we do insertion and deletion from the top of the last element inserted. Like a stack of plates, if we want to push a new plate into the stack we insert on the top and if we want to remove the plate from the stack, we then also remove it from the top.What is stack::top()?stack::top() function is an inbuilt function in C++ ... Read More

stack swap() in C++ STL

Sunidhi Bansal
Updated on 22-Apr-2020 12:23:19

397 Views

In this article, we will be discussing the working, syntax, and examples of stack::swap() function in C++ STL.What is Stack in C++ STL?Stacks are the data structure that stores the data in LIFO (Last In First Out) where we do insertion and deletion from the top or the last element inserted. Like a stack of plates, if we want to push a new plate into the stack we insert on the top and if we want to remove the plate from the stack, we then also remove it from the top.What is stack::swap()?stack::swap() function is an inbuilt function in C++ ... Read More

stack push() and pop() in C++ STL

Sunidhi Bansal
Updated on 22-Apr-2020 12:21:30

8K+ Views

In this article we will be discussing the working, syntax, and examples of stack::push() and stack::pop() function in C++ STL.What is Stack in C++ STL?Stacks are the data structure which stores the data in LIFO (Last In First Out) where we do insertion and deletion from the top of the last element inserted. Like a stack of plates, if we want to push a new plate into the stack we insert on the top and if we want to remove the plate from the stack we then also remove it from the top.What is stack::push()?stack::push() function is an inbuilt function ... Read More

stack empty() and stack size() in C++ STL

Sunidhi Bansal
Updated on 22-Apr-2020 12:19:25

5K+ Views

In this article we will be discussing the working, syntax and examples of stack::empty() and stack::size() function in C++ STL.What is Stack in C++ STL?Stacks are the data structure that stores the data in LIFO (Last In First Out) where we do insertion and deletion from the top of the last element inserted. Like a stack of plates, if we want to push a new plate into the stack we insert on the top and if we want to remove the plate from the stack we then also remove it from the top.What is stack::empty()?stack::empty() function is an inbuilt function ... Read More

stack emplace() in C++ STL

Sunidhi Bansal
Updated on 22-Apr-2020 12:17:11

621 Views

In this article we will be discussing the working, syntax, and examples of stack::emplace() function in C++ STL.What is Stack in C++ STL?Stacks are the data structure that stores the data in LIFO (Last In First Out) where we do insertion and deletion from the top of the last element inserted. Like a stack of plates, if we want to push a new plate into the stack we insert on the top and if we want to remove the plate from the stack we then also remove it from the top.What is stack::emplace()?stack::emplace() function is an inbuilt function in C++ ... Read More

Advertisements