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 Ayush Gupta
Page 5 of 44
Convert the string of any base to integer in JavaScript
The parseInt() function in JavaScript converts strings representing numbers in any base (2-36) to decimal integers. This is useful when working with binary, octal, hexadecimal, or other numeral systems. Syntax parseInt(string, radix); Parameters string − The value to parse. If not a string, it's converted using the ToString method. Leading whitespace is ignored. radix − An integer between 2 and 36 representing the base of the numeral system. If omitted, defaults to 10 (except for strings starting with "0x" which default to 16). Examples Converting Different Bases to Decimal ...
Read MoreDifferences between web-garden and a web-farm in Javascript
In web application deployment, understanding the difference between Web Garden and Web Farm architectures is crucial for scaling JavaScript applications effectively. Both approaches handle increased traffic differently through process-based and server-based scaling respectively. What is a Web Garden? A Web Garden is a web hosting system that comprises multiple "processes" running on a single server. This means we have one physical machine executing multiple worker processes to handle incoming requests concurrently. Single Server (Web Garden) Process 1 ...
Read MoreIseek() in C/C++ to read the alternate nth byte and write it in another file
The lseek() function in C is used to change the file offset (position) of the file descriptor. It allows us to read data from specific positions in a file by moving the file pointer. In this tutorial, we'll demonstrate how to read alternate nth bytes from one file and write them to another file. Note: This program requires file I/O operations with system calls that may not work in all online compilers. Create "start.txt" with sample content before running. Syntax off_t lseek(int fd, off_t offset, int whence); Parameters fd − ...
Read MoreInteger literal in C/C++ (Prefixes and Suffixes)
Integer literals in C are numeric values written directly in the source code to represent integer constants. They can be modified using prefixes to specify the base (decimal, octal, hexadecimal, binary) and suffixes to specify the data type (int, long, unsigned, etc.). Integer literals are of two types − Prefixes − Indicate the number base. For example, 0x10 represents hexadecimal value 16. Suffixes − Specify the data type. For example, 123LL represents a long long integer. Syntax // Prefixes decimal_literal (no prefix) 0octal_literal (prefix ...
Read MoreINT_MAX and INT_MIN in C/C++ and Applications
In C programming, INT_MAX and INT_MIN are predefined macros that represent the maximum and minimum values that can be stored in an int variable. These macros are defined in the header file and are essential for boundary checking and initialization in various algorithms. Syntax INT_MAX /* Maximum value for int */ INT_MIN /* Minimum value for int */ Basic Example Let's see how to use INT_MAX and INT_MIN in a simple program − #include #include int main() { ...
Read MoreCreating a C/C++ Code Formatting tool with help of Clang tools
In this tutorial, we will be discussing how to create a C/C++ code formatting tool using Python and clang-format. This tool automatically formats all C/C++ source files in a project directory according to specified coding standards. Installation Requirements: sudo apt install python3 sudo apt install clang-format How It Works The tool works by recursively scanning directories for C/C++ files and applying clang-format to each file. It uses Python's os.walk() to traverse directories and identifies source files by their extensions. Example: Python Code Formatter Script Create a Python file named format_code.py in your project ...
Read MoreCreate Directory or Folder with C/C++ Program
Creating a folder or directory on your computer is an important task in programming. A directory is like a container that helps store and organize files. In C, you often need to create directories to store data, logs, or configuration files. Creating directories makes file management easier. For example, if your program needs to store logs, it should check if a "logs" folder exists. If not, it can create the folder automatically, so you don't have to do it manually. In this article, we'll show you how to create a directory in C using the mkdir() function. ...
Read MoreCore Dump (Segmentation fault) in C/C++
Core dump (segmentation fault) is a runtime error that occurs when a program tries to access memory that it isn't allowed to access or tries to access memory in a way that isn't allowed. This results in the operating system terminating the program abnormally to prevent potential system damage. A segmentation fault typically happens when code tries to write to read-only memory, accesses corrupt memory locations, or violates memory access permissions. Syntax /* Common scenarios that cause segmentation faults */ char *ptr = NULL; *ptr = 'A'; ...
Read MoreConverting Strings to Numbers in C/C++
In C programming, converting strings to numbers is a common task that can be accomplished using several standard library functions. C provides multiple approaches to convert string representations of numbers into their corresponding numeric values. Syntax int atoi(const char *str); long atol(const char *str); double atof(const char *str); long strtol(const char *str, char **endptr, int base); double strtod(const char *str, char **endptr); Method 1: Using atoi() for Integer Conversion The atoi() function converts a string to an integer value − #include #include int main() { ...
Read MoreConvert a String to Integer Array in C/C++
In C, converting a comma-separated string to an integer array involves parsing the string character by character and extracting numeric values. This process requires traversing the string, identifying delimiters (commas), and converting individual number substrings to integers. Syntax // Function to convert string to integer array void convertStringToArray(char str[], int arr[], int *size); Example: Using Character-by-Character Parsing This approach traverses the string and builds integers by accumulating digits until a comma is encountered − #include #include void convertStringToArray(char str[], int arr[], int *size) { int i = 0, j = 0, num = 0; int len = strlen(str); for (i = 0; i = '0' && str[i]
Read More