Performance Difference Between i++ and ++i in C++

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

940 Views

There is a big distinction between the suffix and prefix versions of ++.In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression.In the postfix version (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i. So basically it first assigns a value to expression and then increments the variable.Let's look at some code to get a better understanding.Example Code#include using namespace std; int main() ... Read More

MySQL Query to Group By Multiple Columns

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

844 Views

You can use IF() to GROUP BY multiple columns. To understand the concept, let us create a table. The query to create a table is as followsmysql> create table MultipleGroupByDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CustomerId int,    -> ProductName varchar(100)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MultipleGroupByDemo(CustomerId, ProductName) values(1000, 'Product-1'); Query OK, 1 row affected (0.20 sec) mysql> insert into MultipleGroupByDemo(CustomerId, ProductName) values(1001, 'Product-2'); Query OK, 1 row affected (0.18 ... Read More

Getting a Subvector from a Vector in C++

Samual Sam
Updated on 30-Jul-2019 22:30:25

5K+ Views

This is a C++ program for getting a subvector from a vector in C++AlgorithmBegin   Declare s as vector s(vector const &v, int m, int n) to    initialize start and end position of vector to constructor.       auto first = v.begin() + m.         auto last = v.begin() + n + 1.       Declare a variable vector of vector type.          Pass the value of first and last position of vector.       Return vector.    Declare a template T.    Declare a function show().       ... Read More

Example on ToggleButton in Android

Chandu yadav
Updated on 30-Jul-2019 22:30:25

251 Views

Before getting into example, we should know what is togglebutton in android, Toggle button is extended view of Button view. It going to represent of state of button as checked and unchecked. Here is the simple solution about toggle button in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the above code we have added toggle button, when user click on toggle button it going to change the state.Step 3 ... Read More

Find Document by Field Name with Specific Value in MongoDB

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

646 Views

To find the document by field name with a specific value, you can use $exists operator. Let us create a collection with documents> db.findByFieldName.insertOne( { "Client":{ "ClientDetails":{ "ClientName":"Larry", "ClientAge":29 }, "ClientProjectDetails":{ "ProjectName":"Online Book Store", "TeamSize":10, "TechnologyUsed":"Spring Boot" } } } ); { "acknowledged" : true, "insertedId" : ObjectId("5c9e93b2d628fa4220163b64") } > db.findByFieldName.insertOne({ ... "   Client":{ ... "      ClientDetails":{ ... "         ClientName":"Chris", ... "         ClientAge":27 ...        }, ...       "ClientEducationDetails":{ ... "         isEducated":true, ...          "CollegeName":"M.I.T." ... ...   ... Read More

Get Checksum of a Byte Array in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

1K+ Views

Create a Byte Array for which you want the Checksum −byte[] arr = "This is it!".getBytes();Now, create a Checksum object −Checksum checksum = new Adler32(); checksum.update(arr, 0, arr.length);The update() above updates the current checksum with the specified array of bytes.Now, get the checksum with getValue() method, which gives the current checksum value.Example Live Demoimport java.util.zip.Adler32; import java.util.zip.Checksum; public class Demo {    public static void main(String[] argv) throws Exception {       byte[] arr = "This is it!".getBytes();       Checksum checksum = new Adler32();       checksum.update(arr, 0, arr.length);       long res = checksum.getValue();   ... Read More

Select from MySQL Where Last Value in a String

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

275 Views

You can use LIKE operator with wildcards to select the records where last value in a string = x, for example ‘10’, ‘15’, etc.Let us first create a table −mysql> create table DemoTable (    ClientId varchar(20) ); Query OK, 0 rows affected (0.68 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('CLI-101'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-110'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-201'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('CLI-210'); Query OK, 1 row affected (0.13 sec) ... Read More

CharBuffer equals Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

187 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.CharBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and the same sequence of elements. The method equals() returns true if the buffers are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer1 = CharBuffer.allocate(n);         ... Read More

Pre and Post Increment Operator Behavior in C, C++, Java, and C#

George John
Updated on 30-Jul-2019 22:30:25

4K+ Views

The Pre increment and post increment both operators are used as increment operations. The pre increment operator is used to increment the value of some variable before using it in an expression. In the pre increment the value is incremented at first, then used inside the expression.if the expression is a = ++b; and b is holding 5 at first, then a will hold 6. Because increase b by 1, then set the value of a with it.Example Code#include using namespace std; main () { int a, b = 15; a = ++b; cout

Find Document with Array Containing Specific Value in MongoDB

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

814 Views

You can use find() method to find document with array that contains a specific value. The syntax is as follows:db.yourCollectionName.find({"yourArrayFieldName":"yourValue"}, .......N).pretty();To understand the above syntax, let us create a collection with documents. The query to create a collection with documents is as follows:>db.findSpecificValue.insertOne({"StudentId":1, "StudentName":"Larry", "FavouriteSubject":["C", "C++", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6e8996140577d89182b8d0") } >db.findSpecificValue.insertOne({"StudentId":2, "StudentName":"Larry", "FavouriteSubject":["MongoDB", "MySQL", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6e89b1140577d89182b8d1") }Display all documents from a collection with the help of find() method. The query is as follows:> db.findSpecificValue.find().pretty();The following is the output:{    "_id" : ObjectId("5c6e8996140577d89182b8d0"),    "StudentId" ... Read More

Advertisements