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
Server Side Programming Articles
Page 937 of 2109
How arrays are passed to functions in C/C++
In this tutorial, we will be discussing how arrays are passed to functions in C. Understanding this concept is crucial for proper array handling in C programming. In C, arrays are never passed by value to functions. Instead, when you pass an array to a function, what actually gets passed is a pointer to the first element of the array. This is called "array decay" − the array name decays into a pointer. Syntax // Method 1: Array notation void function_name(data_type array_name[]); // Method 2: Pointer notation void function_name(data_type *array_name); // Method ...
Read MorePredefined Identifier __func__ in C
The __func__ is a predefined identifier in C that provides the name of the current function. It was introduced in C99 standard and is automatically available in every function without any declaration. Syntax __func__ The __func__ identifier is implicitly declared as if the following declaration appears at the beginning of each function − static const char __func__[] = "function-name"; Example 1: Basic Usage Here's a simple example showing how __func__ returns the current function name − #include void function1(void) { printf("Current function: ...
Read MorePrint * in place of characters for reading passwords in C
In C programming, when handling passwords, it's important to hide the actual characters from being displayed on screen for security reasons. This involves replacing each character of the password with an asterisk (*) symbol. Let's take an example to understand the problem − Input: password Output: ******** Syntax for(int i = 0; i < strlen(password); i++){ printf("*"); } Example 1: Using Predefined Password String The below program demonstrates how to replace each character of a password string with asterisks ? #include #include ...
Read MorePrint 1 2 3 infinitely using threads in C
In C programming, we can print the sequence "1 2 3" infinitely using multiple threads with proper synchronization. This demonstrates thread coordination using mutexes and condition variables to ensure orderly execution. Syntax pthread_create(&thread_id, NULL, thread_function, argument); pthread_mutex_lock(&mutex); pthread_cond_wait(&condition, &mutex); pthread_cond_signal(&condition); pthread_mutex_unlock(&mutex); Installation: On Linux systems, compile with: gcc filename.c -lpthread Example This program creates three threads that print numbers 1, 2, and 3 in sequence infinitely. Each thread waits for its turn using condition variables − #include #include pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER; pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER; ...
Read MorePrint 2D matrix in different lines and without curly braces in C/C++
Here, we will see how to print a 2D matrix in C programming language without using curly braces. This technique uses a clever approach to eliminate the need for braces in nested loops. Curly braces are separators in C that define separate code blocks in the program. Without curly braces, defining scopes is difficult, but we can use a shorthand technique to achieve the same result for simple operations. Syntax for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) ...
Read MoreInteger to Roman in C
Given a decimal number n, we have to convert this into Roman numeral. The value n lies in the range 1 to 4000. Roman numerals use specific symbols and follow subtraction rules for certain combinations. Number Numeral 1 I 4 IV 5 V 9 IX 10 X 40 XL 50 L 90 XC 100 C 400 CD 500 D 900 CM 1000 M 4000 MMMM ...
Read MoreC program for file Transfer using UDP?
File transfer using UDP in C enables transferring files between client and server using User Datagram Protocol. This implementation includes XOR encryption for basic security and handles file existence checking. Syntax int socket(int domain, int type, int protocol); int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); Algorithm The server starts and waits for a filename from the client. The client sends a filename to the server. The server receives the filename ...
Read MoreBinary Number System - Overflow in Arithmetic Addition in C/C++?
The 2's complement number system is widely implemented in computer architecture for representing signed integers. In an N-bit 2's complement system, numbers can be represented from -2n-1 to 2n-1 - 1. For example − 4-bit system represents numbers from -8 to 7 5-bit system represents numbers from -16 to 15 Overflow occurs when adding two N-bit 2's complement numbers and the result is too large to fit into the N-bit representation. Syntax // Overflow detection formula overflow = carry_in_msb ^ carry_out_msb Understanding Overflow A computer uses N-bit fixed registers. ...
Read MoreBarabasi Albert Graph (for Scale Free Models) in C/C++?
The Barabási-Albert model is one of the most important models for generating scale-free networks. It combines two fundamental concepts: growth and preferential attachment. Growth means that the number of nodes in the network increases over time, while preferential attachment means that highly connected nodes are more likely to receive new connections. This model simulates real-world networks where popular nodes (like well-known websites or influential people) attract more connections than less popular ones, following the "rich get richer" principle. Syntax // Basic structure for BA model implementation typedef struct { int **adjacencyMatrix; ...
Read MoreArrange a binary string to get maximum value within a range of indices C/C++?
In this problem, we have a binary string consisting of only 0's and 1's, along with M non-intersecting ranges [A1, B1], [A2, B2], ..., [AM, BM]. We need to rearrange the string to maximize the sum within the given ranges while ensuring the result is lexicographically maximum. Syntax char* arrangeString(char* binaryStr, int ranges[][2], int m); Algorithm The approach involves two main steps − First, fill all the given ranges with 1's to maximize the sum Then, place remaining 1's from left to right to achieve lexicographical maximum Example 1: Basic ...
Read More