Smita Kapse

Smita Kapse

388 Articles Published

Articles by Smita Kapse

Page 6 of 39

Modulus of Negative Numbers in C

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 2K+ Views

In C programming, the modulus operator (%) can be used with negative numbers, but the result depends on the sign of the dividend (left operand). The sign of the result always matches the sign of the dividend, regardless of the divisor's sign. Syntax result = dividend % divisor; Rule for Sign Determination The sign of the modulus result follows this rule − If dividend is positive, result is positive If dividend is negative, result is negative The divisor's sign does not affect the result's sign Example 1: Positive Dividend, Negative ...

Read More

Benefits of C over other languages

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 2K+ Views

The C programming language was developed by Dennis Ritchie during early 1970. It was developed to redesign the UNIX operating system. Earlier the B language, which was used for UNIX system, had different drawbacks. It did not support structures, and did not understand datatypes. For this reason, the C language was introduced. C has high level functionality, and detailed features for OS programming. The UNIX kernel was developed using C. Advantages of C Language Medium Level Language: C is a medium level language. It has both, the lower level and higher level functionality. We can use ...

Read More

C/C++ Struct vs Class

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 489 Views

In C programming, there is no class keyword − only structures (struct) are available. However, understanding the conceptual differences between struct and class is important for C programmers who may work with C++. In C, structures are used to group related data together. Syntax struct structure_name { data_type member1; data_type member2; // ... more members }; Example: Basic Structure in C In C, all structure members are accessible by default − #include struct my_struct { ...

Read More

Get and Set the stack size of thread attribute in C

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 2K+ Views

To get and set the stack size of thread attribute in C, we use the pthread_attr_getstacksize() and pthread_attr_setstacksize() functions. These functions allow us to query and modify the minimum stack size allocated to a thread's stack. Syntax int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); pthread_attr_getstacksize() This function retrieves the current stack size from a thread attribute object. It returns 0 on success, otherwise returns an error number. Parameters: attr − Pointer to the thread attribute object stacksize − Pointer to store the retrieved stack size in bytes ...

Read More

Display a value with $addToSet in MongoDB with no duplicate elements?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 246 Views

The $addToSet operator in MongoDB ensures that duplicate elements are not added to an array field. When used with aggregation pipeline, it creates a set of unique values from the specified field. Syntax db.collection.aggregate([ { $group: { _id: null, fieldName: { $addToSet: "$arrayField" } } } ]); ...

Read More

Extract particular element in MongoDB within a Nested Array?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 689 Views

To extract particular elements in MongoDB within nested arrays, use the $elemMatch operator to match array elements and projection to return only specific fields from the matched documents. Syntax db.collection.find( { "arrayField": { $elemMatch: { "nestedArrayField": { ...

Read More

Retrieving an embedded object as a document via the aggregation framework in MongoDB?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 359 Views

To retrieve an embedded object as a document in MongoDB, use the aggregation framework's $replaceRoot stage. This operator promotes the specified embedded document to the top level, effectively replacing the entire document structure. Syntax db.collection.aggregate([ { $replaceRoot: { newRoot: "$embeddedFieldName" } } ]); Create Sample Data db.embeddedObjectDemo.insertMany([ { "UserDetails": { "UserName": "John", "UserAge": ...

Read More

Retrieving array values from a find query in MongoDB?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 184 Views

To retrieve array values from a MongoDB find query, use dot notation to access array fields and their nested properties. This allows you to query specific elements within arrays and filter documents based on array content. Syntax db.collection.find({"arrayField.nestedProperty": "value"}); Sample Data db.retrievingArrayDemo.insertMany([ { "UserDetails": [ { "UserName": "John", "UserAge": 23 } ], "UserCountryName": ...

Read More

Removing empty fields from MongoDB

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 542 Views

To remove empty fields from MongoDB documents, use updateMany() with the $unset operator. This operation identifies documents with empty string values and removes those fields entirely. Syntax db.collection.updateMany( { "fieldName": "" }, { $unset: { "fieldName": 1 } } ); Sample Data Let us create a collection with documents containing empty fields ? db.removeEmptyFieldsDemo.insertMany([ { "StudentName": "" }, { "StudentName": "Chris" }, { "StudentName": "" }, { "StudentName": ...

Read More

How to return documents of a collection without objectId in MongoDB?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 2K+ Views

To return documents of a collection without objectId in MongoDB, use projection with _id:0 in the find() method. This excludes the automatically generated _id field from the query results. Syntax db.collection.find(query, { _id: 0 }); Sample Data db.returnDocumentWithoutObjectId.insertMany([ { "Name": "Carol", "Age": 25 }, { "Name": "Sam", "Age": 21 }, { "Name": "John", "Age": 23 } ]); { "acknowledged": true, "insertedIds": [ ...

Read More
Showing 51–60 of 388 articles
« Prev 1 4 5 6 7 8 39 Next »
Advertisements