Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Anvi Jain
Page 6 of 43
How does a C program executes?
Here we will see how C programs are executed in a system. This is basically the compilation process of a C program from source code to executable machine code. The following diagram shows how a C source code file gets converted into an executable program − C Source Code (.c file) Preprocessor (.i file) ...
Read MoreHow to modify a const variable in C?
In C, const variables are designed to be immutable after initialization. However, there are ways to modify their values using pointers, though this practice leads to undefined behavior and should be avoided in production code. Syntax const data_type variable_name = value; int *ptr = (int*)&const_variable; // Cast away const *ptr = new_value; // Modify through pointer Example 1: Attempting Direct Modification (Compile Error) Direct assignment to a const variable results in a compilation error − #include int main() { const int x = 10; ...
Read MoreHow does free() know the size of memory to be deallocated?
The free() function is used to deallocate memory that was allocated using malloc(), calloc(), or realloc(). The syntax of free() is simple − it only takes a pointer as an argument and deallocates the memory. Syntax void free(void *ptr); The interesting question is: how does free() know the size of the memory block to deallocate when it only receives a pointer? How free() Determines Memory Block Size When you allocate memory using dynamic memory allocation functions, the memory management system stores metadata about each allocated block. This metadata typically includes the size of ...
Read MoreMultiline macros in C
In C programming, multiline macros allow you to define complex operations that span multiple lines. Unlike single-line macros, each line in a multiline macro must be terminated with a backslash '' character to indicate line continuation. When using multiline macros, it's recommended to enclose the entire macro definition in parentheses to avoid potential syntax errors. Syntax #define MACRO_NAME(parameters) ({\ statement1;\ statement2;\ statement3;\ }) Example 1: Basic Multiline Macro Here's an example demonstrating how to create and use a multiline macro for printing ...
Read MoreWhat are the differences between JavaScript and PHP cookies?
Cookies are text files stored on the client's browser to remember user information across web pages. Both JavaScript and PHP can work with cookies, but they operate differently − JavaScript handles cookies on the client-side while PHP manages them on the server-side. JavaScript Cookies JavaScript cookies are manipulated directly in the browser using the document.cookie property. They're ideal for client-side data storage and immediate user interactions. Setting a Cookie with JavaScript // Set a cookie that expires in 7 days document.cookie = "username=john; expires=" + new Date(Date.now() + 7*24*60*60*1000).toUTCString() + "; path=/"; Reading ...
Read MoreGet distinct first word from a string with MongoDB?
To get distinct first words from a string field in MongoDB, use the distinct() method combined with JavaScript's map() and split() functions to extract and return the first word from each string. Syntax db.collection.distinct("fieldName", query).map(function(str) { return str.split(" ")[0]; }); Sample Data db.distinctFirstWordDemo.insertMany([ { "_id": 100, "StudentName": "John", "StudentFeature": "John is a good player", ...
Read MoreQuery array of nested string with MongoDB?
To query array of nested string in MongoDB, you can use dot notation to access nested array elements. This allows you to search for specific string values within arrays that are nested inside other objects. Syntax db.collection.find({"parentField.nestedArrayField": "searchValue"}) Sample Data Let us first create a collection with documents containing nested arrays of strings ? db.nestedStringDemo.insertMany([ { "CustomerName": "John", "CustomerOtherDetails": [ ...
Read MoreMongoDB. max length of field name?
MongoDB supports the BSON format data and has no explicit maximum length limit for field names. However, the practical limit is constrained by the overall BSON document size limit of 16MB. Syntax db.collection.insertOne({ "fieldNameOfAnyLength": "value" }); Example: Inserting Document with Very Long Field Name Let us create a collection with a document containing an extremely long field name ? db.maxLengthDemo.insertOne({ "maxLengthhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh": "This is demo" }); { "acknowledged": true, "insertedId": ObjectId("5ce97ac978f00858fb12e926") } ...
Read MoreCreating an index on a nested MongoDB field?
To create an index on a nested MongoDB field, use dot notation to specify the path to the nested field within the createIndex() method. This improves query performance when searching or sorting by nested field values. Syntax db.collection.createIndex({ "parentField.nestedField.deepField": 1 }) Where 1 indicates ascending order and -1 indicates descending order. Sample Data Let us create a collection with nested documents ? db.createIndexOnNestedFieldDemo.insertMany([ { "UserDetails": { "UserPersonalDetails": ...
Read MoreMongoDB query select and display only a specific field from the document?
To select and display only specific fields from MongoDB documents, use the projection parameter in the find() method. Set the desired field to 1 (or true) to include it, and use _id: 0 to exclude the default ObjectId field. Syntax db.collection.find( {}, { fieldName: 1, _id: 0 } ); Sample Data Let us create a collection with sample documents ? db.querySelectDemo.insertMany([ { UserId: 100, UserName: "Chris", UserAge: 25 }, { UserId: 101, UserName: "Robert", UserAge: ...
Read More