Anonymous Union and Structure in C

Anvi Jain
Updated on 30-Jul-2019 22:30:25
Here we will see what is the anonymous union and structures in C. The anonymous unions and structures are unnamed unions and structures. As they have no names, so we cannot create direct objects of it. We use it as nested structures or unions.These are the examples of anonymous union and structures.struct {    datatype variable;    ... }; union {    datatype variable;    ... };In this example we are making one structure, called point, it is holding an anonymous structure. This is holding two values x, y. We can access the anonymous structure or union members directly.Example#include struct ... Read More

Ternary Operator in Python?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
Many programming languages support ternary operator, which basically define a conditional expression.Similarly the ternary operator in python is used to return a value based on the result of a binary condition. It takes binary value(condition) as an input, so it looks similar to an “if-else” condition block. However, it also returns a value so behaving similar to a function.Syntax[on_true] if [expression] else [on_false]Let’s write one simple program, which compare two integers -a. Using python if-else statement ->>> x, y = 5, 6 >>> if x>y:    print("x") else:    print("y") yb. Using ternary operator>>> x, y = 5, 6 >>> ... Read More

Create a column on my table that allows null but is set by default to empty (not null)?

Samual Sam
Updated on 30-Jul-2019 22:30:25
You need to use default keyword for this. The syntax is as follows −alter table yourTableName add yourColumnName yourDataType NULL Default '';To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table AllowNullDefaulNotNullDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> UserName varchar(20),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.65 sec)Let us add a new column that allow NULL value but default value set to NOT NULL. The query is as follows −mysql> alter table AllowNullDefaulNotNullDemo add UserAddress varchar(20) ... Read More

Internal address latch in 8085 Microprocessor

George John
Updated on 30-Jul-2019 22:30:25
The select unit of the register in the 8085 selects any one of the register pairs (BC, DE, HL, SP, PC, or WZ) for sending them to it to the latch unit specified for addressing. For example, the contents of the PC be C200H. If the selection unit be the register which selects the PC, and sends C200H from the PC to the address latch internally thereafter the latch holds the specified value and sends directly out to the pins of the address after buffering. The Most Significant Byte of the address i.e. the C2H, is sent out to the ... Read More

C++ Program to Perform the Shaker Sort

George John
Updated on 30-Jul-2019 22:30:25
Shaker sort is used to sort the given data. Shaker sort, unlike Bubble sort, orders the array in both directions. The worst complexity of this algorithm is O(n^2).AlgorithmBegin    ShakerSort() function has ‘arr’ the array of data and ‘n’ the number of values, in the argument list.    // Implement Sorting algorithm using nested for loops.    The parent loop will run on ‘i’ from 0 to n-1 and contains two loops inside.    The first loop will run on ‘j’ from i+1 to n-1 and use swap() if a[j] < a[j-1].    Decrement n.    The second loop will ... Read More

How to update or modify the existing documents of a collection in MongoDB?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25
To update or modify the existing documents of a collection in MongoDB, you need to use update() method. The syntax is as follows:db.yourCollectionName.update(yourExistingValue, yourUpdatedValue);Here, we will create a collection with name updateinformation. The query to create a collection is as follows. MongoDB creates a collection automatically when you insert some document using insert() method as shown below:> db.updateInformation.insert({"StudentName":"Larry", StudentAge:35, StudentMarks:89});The following is the output:WriteResult({ "nInserted" : 1 })Now you can display the documents with the help of find() method from the collection updateinformation. The query is as follows:> db.updateInformation.find();The following is the output displaying the documents in the collection we ... Read More

Count multiple occurrences of separate texts in MySQL?

George John
Updated on 30-Jul-2019 22:30:25
You can use aggregate function count along with if() for this. To understand the concept, let us create a table. The query to create a table is as followsmysql> create table CountOccurrencesDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> TechnicalSubject varchar(100)    -> ); Query OK, 0 rows affected (0.68 sec)Now you can insert some records in the table using insert command. The query is as followsmysql> insert into CountOccurrencesDemo(TechnicalSubject) values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into CountOccurrencesDemo(TechnicalSubject) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

LocalDate hashCode() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
The hash code value of the LocalDate can be obtained using the hashCode() method in the LocalDate class in Java. This method requires no parameters and it returns the hash code value of the LocalDate.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-15"); System.out.println("The LocalDate is: " + ld); System.out.println("The hash code is: " + ld.hashCode()); } }OutputThe LocalDate ... Read More

The toArray() method of CopyOnWriteArrayListin Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25
The toArray() method is used to return an array containing all the elements in this list in proper sequence.The syntax is as follows −Object[] toArray()To work with CopyOnWriteArrayList class, you need to import the following package −import java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class toArray() method in Java−Example Live Demoimport java.util.Arrays; import java.util.concurrent.CopyOnWriteArrayList; public class Demo { public static void main(String[] args) { CopyOnWriteArrayList arrList = new CopyOnWriteArrayList(); arrList.add(220); arrList.add(250); arrList.add(400); ... Read More

How to get a particular element from MongoDB array?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25
You can use the aggregate framework to get a particular element from the MongoDB array. To understand the concept, let us create a collection with the document. The query to create a collection with the document is as follows −> db.getParticularElement.insertOne({"InstructorName":"Larry", "InstructorTechnicalSubject":["Java", "C", "C++", "MongoDB", "MySQL", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c7ee027559dd2396bcfbfb1") }Display all documents from a collection with the help of find() method. The query is as follows −> db.getParticularElement.find().pretty();The following is the output −{    "_id" : ObjectId("5c7ee027559dd2396bcfbfb1"),    "InstructorName" : "Larry",    "InstructorTechnicalSubject" : [       "Java",       ... Read More
Advertisements