In C++, it is faster to process a sorted array than an unsorted array because of branch prediction. In computer architecture, a branch prediction determines whether a conditional branch (jump) in the instruction flow of a program is likely to be taken or not.Let’s take an example −if(arr[i] > 50) { Do some operation B } else { Do some operation A }If we run this code for 100 elements in unsorted and sorted order below things will be happened −For sorted array −1, 2, 3, 4, 5, …… 50, 51………100 A, A, A, A, A A, B ... Read More
The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is this? Its because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating ... Read More
Just because we haven't reached the EOF, doesn't mean the next read will succeed.Consider you have a file that you read using file streams in C++. When writing a loop to read the file, if you are checking for stream.eof(), you're basically checking if the file has already reached eof. So you'd write the code like −Example#include #include using namespace std; int main() { ifstream myFile("myfile.txt"); string x; while(!myFile.eof()) { myFile >> x; // Need to check again if x is valid or eof if(x) { ... Read More
To set the outline width, use the outlineWidth property. You can try to run the following code to set the width of the outline around an element with JavaScript −ExampleLive Demo #box { width: 450px; background-color: orange; border: 3px solid red; margin-left: 20px; } Click below to add Outline Width. ... Read More
To set the outline style, use the outlineStyle property. The outline can be solid, dotted, dashed, etc.ExampleYou can try to run the following code to set the style of the outline around an element with JavaScript −Live Demo #box { width: 450px; background-color: orange; border: 3px solid red; margin-left: 20px; } ... Read More
If the content renders outside the element box, use the overflow property to add a scroll. This will ease visitors in reading the entire content.ExampleYou can try to run the following code to learn how to work with overflow property in JavaScript −Live Demo #box { width: 450px; height: 150px; background-color: orange; border: 3px solid red; margin-left: 20px; ... Read More
If the content overflows, the workaround with overflowX property to solve the left/ right edge issues and set a scroll. Adding a scroll allows visitors to easily read the entire content.ExampleYou can try to run the following code to learn what is to be done with the left/ right edges of the content on overflow with JavaScript −Live Demo #box { width: 350px; height: 150px; background-color: orange; ... Read More
Use the marginRight property in JavaScript, to set the right margin. You can try to run the following code to set the right margin of an element with JavaScript −ExampleLive Demo #myID { border: 2px solid #000000; } This is demo text. Add right margin function display() { document.getElementById("myID").style.marginRight = "150px"; }
Use the minHeight property in JavaScript to set the maximum height. You can try to run the following code to set the minimum height of an element with JavaScript −ExampleLive Demo #box { width: 300px; background-color: gray; overflow: auto; } Click below to set Minimum height. Min Height ... Read More
Use the maxWidth property in JavaScript to set the maximum width.ExampleYou can try to run the following code to set the maximum width of an element with JavaScript −Live Demo Click below to set Maximum width. Max Width This is a div. This is a div. This is a div. This is a div. This is a div. This is a div. This is a div. This is a div. This is a div. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP