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 on Trending Technologies
Technical articles with clear explanations and examples
How can a Python function return a function?
In Python, functions are treated as first-class objects, which means all functions in Python are treated like any other object or variable. You can assign a function to a variable, pass it as an argument to another function, return it from a function, or even store it in data structures like lists. One very useful feature in Python is that a function can return another function. This means you can define a function inside another function and return it as a result. This is used in advanced programming concepts like closures, decorators, and higher-order functions. Syntax Following ...
Read MoreWhat are Python function attributes?
In Python, everything is an object, and functions are no exception. Since functions are objects, they can have attributes — custom data attached to them, just like attributes on a class instance. This allows you to store metadata, counters, configuration, or any arbitrary data directly on a function. Function attributes are different from function parameters. Parameters are inputs passed during a function call, while attributes are persistent data stored on the function object itself. Syntax You can set and access function attributes using the dot (.) operator, or using setattr() and getattr() built-in functions − ...
Read MoreC/C++ Ternary Operator
The ternary operator (?:) in C/C++ is a shorthand for an if-else statement. It is the only operator in C/C++ that takes three operands, which is why it is called "ternary". Syntax (expression-1) ? expression-2 : expression-3 This operator returns one of two values depending on the result of an expression. If expression-1 evaluates to Boolean true, then expression-2 is evaluated and its value is returned as the final result. Otherwise, expression-3 is evaluated and its value is returned. Ternary Operator Flow condition ? ...
Read MoreAnti Clockwise spiral traversal of a binary tree?
Here we will see one interesting problem. We have a binary tree and we have to traverse it in an anti-clockwise manner. The traversal alternates between printing levels from right-to-left (starting from the top) and left-to-right (starting from the bottom), creating a spiral-like anti-clockwise pattern. For the binary tree shown below, the anti-clockwise traversal sequence is − 1, 8, 9, 10, 11, 12, 13, 14, 15, 3, 2, 4, 5, 6, 7 Binary Tree — Anti-Clockwise Traversal ...
Read MoreA comma operator question in C/C++ ?
The comma (, ) in C/C++ programming language has two contexts − As a separator − Used to separate variable declarations, function arguments, and initializer values. In this context, the comma is not an operator. As an operator − The comma operator is a binary operator that evaluates the first expression, discards its result, then evaluates and returns the value of the second expression. This operator has the lowest precedence of all C/C++ operators — even lower than the assignment operator. Syntax result = (expr1, expr2); // ...
Read MoreDifference between %p and %x in C/C++
Here we will see what are the differences between %p and %x in C or C++. The %p format specifier is used to print pointer values (memory addresses), while %x is used to print unsigned integers in hexadecimal format. Though pointers can also be displayed using %u or %x, the correct and portable way to print a pointer is %p. The visible difference is that %p prints with leading zeros and is platform-width aware (16 hex digits on 64-bit systems, 8 on 32-bit), while %x prints only the significant digits without padding. Syntax printf("%p", pointer); ...
Read MoreWhy are global and static variables initialized to their default values in C/C++?
Global and static variables are initialized to their default values because it is mandated by the C and C++ standards. The compiler assigns zero at compile time, and it costs nothing extra to do so. Both static and global variables behave the same way in the generated object code — they are allocated in the .bss segment (Block Started by Symbol), and when the program is loaded into memory, the OS zeroes out this entire segment automatically. In contrast, local (automatic) variables are stored on the stack and are not initialized — they contain whatever garbage value was previously ...
Read MoreAdding an element at a given position of the array in Javascript
In this article, we are going to learn how to add an element at a given position of the array in JavaScript. An array is a special variable that can hold more than one value. JavaScript provides several ways to insert an element at a specific index, including the built-in splice() method and the spread operator approach. Syntax The most common way to insert an element at a given position is using the splice() method − array.splice(index, 0, element); Here, index is the position where the element should be inserted, 0 means no elements ...
Read MoreWhich one is the Python module to obfuscate javascript?
You can use the jsmin module to minimize and obfuscate JavaScript code using Python. Minification removes whitespace, comments, and unnecessary characters from JavaScript files, reducing file size without changing functionality. Installing jsmin Install jsmin using pip − $ pip install jsmin Syntax Following is the basic syntax for using jsmin in Python − from jsmin import jsmin minified_code = jsmin(javascript_string) The jsmin() function takes a JavaScript source string as input and returns the minified version as a string. Minifying a JavaScript File To use jsmin in ...
Read MoreConstruct an ER diagram for a company in DBMS?
An Entity-Relationship (ER) diagram is a visual representation of the data model for a database. It shows entities, their attributes, and the relationships between them. In this article, we construct an ER diagram for a company database step by step. Problem Draw an ER model for a company considering the following constraints − In a company, an employee works on many projects which are controlled by one department. One employee supervises many employees. An employee has one or more dependents. One employee manages one department. Solution ...
Read More