Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 6 of 43

How does a C program executes?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 6K+ Views

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 More

How to modify a const variable in C?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 6K+ Views

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 More

How does free() know the size of memory to be deallocated?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 2K+ Views

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 More

Multiline macros in C

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 4K+ Views

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 More

What are the differences between JavaScript and PHP cookies?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 900 Views

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 More

Get distinct first word from a string with MongoDB?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 266 Views

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 More

Query array of nested string with MongoDB?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 266 Views

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 More

MongoDB. max length of field name?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 1K+ Views

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 More

Creating an index on a nested MongoDB field?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 2K+ Views

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 More

MongoDB query select and display only a specific field from the document?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 2K+ Views

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
Showing 51–60 of 427 articles
« Prev 1 4 5 6 7 8 43 Next »
Advertisements