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 923 of 2109
Write a C Program to count the frequency of each character
In C programming, counting the frequency of each character in a string is a common task that involves scanning through the string and tracking how many times each character appears. Syntax int frequency[26]; // For lowercase letters a-z frequency[character - 'a']++; // Increment count for character Algorithm Step 1: Define maximum string size Step 2: Declare string and frequency array Step 3: Read input string Step 4: Initialize frequency array to 0 Step 5: Iterate through string and count characters: - For lowercase: frequency[string[i] - 'a']++ ...
Read MoreExplain the Character operations in C language
Character operations in C language involve handling individual characters, which can be alphabetic (A-Z or a-z), numeric (0-9), whitespace, or special symbols. C provides various functions for character input, output, and manipulation. Syntax char variable_name = 'character'; char variable_name; Character Declaration Characters in C are declared using the char data type and can be initialized with character constants − #include int main() { char a = 'A'; /* using character constant */ char b = ...
Read MoreExplain the pointers to unions in C language
A union in C is a memory location that is shared by several variables of different data types. A pointer to union is a variable that stores the address of a union, allowing us to access union members using the arrow operator (->) just like with structures. Syntax union uniontag { datatype member1; datatype member2; /* ... */ datatype membern; }; union uniontag *ptr; // Pointer to union Declaration of Union and Pointer There are different ...
Read MoreWhat is a structure at local scope in C language?
In C, a structure defined within a function or block has local scope, meaning it is only accessible within that specific function or block. This is different from global structures that can be accessed throughout the program. Syntax struct tagname { datatype member1; datatype member2; datatype member_n; }; When declared inside a function, the structure definition and its variables are local to that function. Example 1: Basic Local Structure Here's a simple example showing a structure declared within the main() function ...
Read MoreHow to pass an entire structure as an argument to function in C?
In C programming, structures can be passed to functions in three ways. Here we'll focus on passing an entire structure as an argument to a function, where the complete structure variable is passed by value. Syntax return_type function_name(struct structure_name variable_name); When passing an entire structure as an argument − The structure variable name is given as argument in the function call It is collected in another structure variable in the function header A complete copy of the structure is created, which uses additional memory Example 1: Basic Structure Passing This ...
Read MoreHow to pass the individual members as arguments to function using structure elements?
In C programming, there are three ways to pass structure data to functions. One of the most basic approaches is passing individual structure members as separate arguments to a function. This method treats each structure member as an independent variable in the function call. Syntax // Function declaration returnType functionName(dataType1 member1, dataType2 member2, ...); // Function call functionName(structVariable.member1, structVariable.member2, ...); How It Works Each member is passed as a separate argument in the function call Members are collected independently as ordinary variables in the function parameters Changes made to parameters inside the ...
Read MoreExplain the dynamic memory allocation of pointer to structure in C language
Dynamic memory allocation of pointer to structure in C allows us to allocate memory for structures at runtime using functions like malloc(), calloc(), or realloc(). This approach is essential when the number of structures needed is not known at compile time. Pointer to structure holds the address of the entire structure and is used to create complex data structures such as linked lists, trees, and graphs. The members of the structure can be accessed using the arrow operator (->). Syntax struct tagname *ptr; ptr = (struct tagname*) malloc(n * sizeof(struct tagname)); Declaration and Access ...
Read MoreExplain the concept of an array within a structure in C programming
An array within a structure in C programming is a powerful feature that allows you to group related data elements together. When you declare an array as a member of a structure, you can store multiple values of the same data type within a single structure variable. Syntax struct structure_name { datatype member1; datatype array_name[size]; datatype member2; }; General Structure Declaration The basic syntax for declaring a structure is − struct tagname { datatype member1; ...
Read MoreC program demonstrating the concepts of strings using Pointers
In C programming, strings can be effectively manipulated using pointers. A string is essentially an array of characters terminated by a null character ('\0'). When we use pointers with strings, we can access and manipulate individual characters efficiently. Syntax char *pointer_name = "string_literal"; char *array_of_pointers[] = {"string1", "string2", "string3"}; String Declaration and Initialization Strings can be declared and initialized in multiple ways − Using character array: char string[50]; Using character constants: char string[10] = {'H', 'e', 'l', 'l', 'o', '\0'}; Using string literals: char string[10] = "Hello"; Using pointer to string: char ...
Read MoreWhat is strncmp() Function in C language?
The C library function strncmp() compares at most the first n characters of two strings lexicographically. It returns an integer value indicating the relationship between the strings based on the first n characters. Syntax int strncmp(const char *str1, const char *str2, size_t n); Parameters str1 − First string to be compared str2 − Second string to be compared n − Maximum number of characters to compare Return Value 0 − If the first n characters of both strings are equal Positive value − If str1 is lexicographically greater than ...
Read More