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
C++ Articles
Found 5,962 articles
Check if the Sum of Digits of a Number N Divides It
A number is divisible by the sum of its digits when the remainder of dividing the number by its digit sum equals zero. For example, if N = 36, the digit sum is 3 + 6 = 9, and since 36 % 9 = 0, the number 36 is divisible by its digit sum. Algorithm The algorithm follows these steps ? Extract each digit of the number using modulo operator (% 10) Add all digits to get the sum Check if the original number is divisible by this sum using modulo operator Return true if remainder ...
Read MoreCheck Duplicate in a Stream of Strings
A stream of strings is a sequential flow of string data where each element represents an individual string. In Python, we can efficiently check for duplicates in a stream using data structures like sets or dictionaries to track previously seen strings. Using a Set to Track Duplicates The most efficient approach uses a set to store unique strings we've already encountered. Sets provide O(1) average-case lookup time, making duplicate detection fast ? Example def check_duplicate_in_stream(strings): seen = set() results = [] ...
Read MoreSort the string as per the ASCII values of the characters
ASCII (American Standard Code for Information Interchange) assigns unique numeric values to characters. In Python, we can sort strings based on these ASCII values to arrange characters in ascending order. Problem Statement Given a string, we need to sort its characters according to their ASCII values in increasing order. Let's understand this with examples ? Example 1 Input: "$%7wjk()" Output: "$%()7jkw" The ASCII values are ? $ → 36 % → 37 ( → 40 ) → 41 7 → 55 j → 106 k → 107 w → 119 Example ...
Read MoreWhich is Better to Learn Machine Learning: C++, Python, or R?
Machine learning (ML) is the study of computer algorithms that learn patterns from data without explicit programming. When choosing a programming language for ML, three popular options are C++, Python, and R. Each has distinct advantages depending on your goals and experience level. What is Machine Learning? Machine Learning enables computers to identify patterns and make predictions by processing large datasets. It's widely used in healthcare, finance, e-commerce, manufacturing, and transportation. Tech giants like Google, Apple, and Microsoft rely heavily on ML to enhance user experiences and optimize operations. C++ for Machine Learning C++ is a ...
Read MoreHow can we read Python dictionary using C++?
A dictionary in Python is a collection of key-value pairs where each key must be unique. Unlike lists which are indexed by numbers, dictionaries are accessed using keys that can be immutable types like strings, numbers, or tuples. Lists cannot be used as keys because they can be modified. Dictionaries are created using {}, and key-value pairs are added with commas. We can store, retrieve, and delete values using their keys. To check if a key exists, we can use the in keyword. Reading Python Dictionaries using C++ There are several C++/Python bindings available for facilitating communication ...
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 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 MoreDifference Between C# and C++
C# and C++ are both powerful programming languages, but they serve different purposes and have distinct characteristics. Understanding their differences helps developers choose the right language for their projects. What is C#? C# is a general-purpose object-oriented programming language developed by Anders Hejlsberg and his team at Microsoft. It is pronounced as 'C sharp' and is considered a pure object-oriented programming language that runs on the .NET framework. Key characteristics of C# include − Automatic memory management through garbage collection Platform-specific (primarily Windows, though .NET Core enables cross-platform development) No ...
Read More