Server Side Programming Articles - Page 2302 of 2651

Read/Write structure to a file using C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

12K+ Views

fwrite() and fread() is used to write to a file in C.fwrite() syntaxfwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)whereptr - A pointer to array of elements to be writtensize - Size in bytes of each element to be writtennmemb - Number of elements, each one with a size of bytesstream – A pointer to a FILE object that specifies an output streamfread() syntaxfread(void *ptr, size_t size, size_t nmemb, FILE *stream)whereptr - A pointer to a block of memory with a minimum size of size*nmemb bytes.size - Size in bytes of each element to be read.nmemb - Number of ... Read More

How to listdown all the symbols in a .so file in C++

Samual Sam
Updated on 30-Jul-2019 22:30:25

826 Views

To read a .so file in elf format, use readelfreadelf -Ws libName.soIt helps to extract symbol from binary.The standard tool used for listing all symbol is, nmnm -g libName.so

How can I get the list of files in a directory using C or C++?

Revathi Satya Kondra
Updated on 13-Jun-2025 12:59:07

16K+ Views

Listing files in a directory is used to write a program that opens a specified folder (e.g: "/myfiles"), reads its contents, and displays the names of each file and subfolder one by one. In C/C++, to see all the files in a directory, you can use special system functions that let you read the directory's contents. In real life, we open folder to see the contents inside the files. Similarly, in C or C++, we can write a program to display all the files and folders in a directory. Algorithm Following is the algorithm to get the list of files ... Read More

Why is address zero used for the null pointer in C/C++?

Revathi Satya Kondra
Updated on 17-Jun-2025 14:27:30

671 Views

In C/C++, a null pointer is a special pointer that does not point to any valid memory location. Address 0 is used for Null Pointers because address 0 is reserved by the system, and it is guaranteed not to be used for valid data. So, when a pointer is assigned the value 0 (or nullptr), it means the pointer points to nothing. Some uses of null pointers are: To initialize a pointer variable when that pointer variable isn't assigned any valid memory address yet. To pass a null pointer to a function ... Read More

C++ Program for Inorder Tree Traversal without Recursion

Anvi Jain
Updated on 30-Jul-2019 22:30:25

676 Views

If a binary tree is traversed in-order, the left subtree is visited first, then the root and later the right sub-tree. The output the key in ascending order in in_order traversal. This is a C++ Program for Inorder Tree Traversal without Recursion.AlgorithmBegin      Function inOrder():       Declare a stack s.       Declare the current node as root.       While current node is not null and stack is not empty do          While current node is not null do             Push the current node on the ... Read More

C++ Program to Implement Array in STL

Revathi Satya Kondra
Updated on 27-May-2025 17:06:54

565 Views

An array is a collection of elements of the same type such as integers, string, etc. Array in STL In C++ Standard Template Library (STL) , we use std::array container to create arrays with a fixed size. the size cannot be changed once created. It works like a normal array but with extra features like knowing its own size and working with STL functions. Syntax Following is the syntax to create an array in C++ STL: array(data_type, size) array_name = {va1, val2, ...valn}; Here, data_type: It specifies the type of data array will accept. it can be any ... Read More

vector::begin() and vector::end() in C++ STL

Revathi Satya Kondra
Updated on 12-Jun-2025 14:07:46

5K+ Views

In C++, a vector is a dynamic array provided by the Standard Template Library (STL) that can grow or shrink in size and can store multiple elements of the same type (like int, string, etc.). Instead of accessing elements one by one using indexes like vec[0], vec[1], etc., The C++ provides helper functions like begin() and end() that return iterators. These iterators make it easy to loop through the vector from start to end, especially for loops. The vector::begin() Function The vector::begin() function returns an iterator pointing to the first element of the vector. Syntax vectorname.begin() Parameters This function does ... Read More

vector insert() function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

799 Views

vector insert() function in C++ STL helps to increase the size of a container by inserting the new elements before the elements at the specified position.It is a predefined function in C++ STL.We can insert values with three types of syntaxes1. Insert values by mentioning only the position and value:vector_name.insert(pos, value);2. Insert values by mentioning the position, value and the size:vector_name.insert(pos, size, value);3. Insert values in another empty vector form a filled vector by mentioning the position, where the values are to be inserted and iterators of filled vector:empty_eector_name.insert(pos, iterator1, iterator2);AlgorithmBegin    Declare a vector v with values.    Declare ... Read More

unordered_multimap swap() function in C++ STL

Anvi Jain
Updated on 30-Jul-2019 22:30:25

140 Views

unordered_multimap swap() function in C++ STL is used to swap the elements of one multimap to another of same size and type.AlgorithmBegin    Declaring two empty map container m, m1.    Insert some values in both m, m1 map containers.    Perform swap() function to swap the values of m, m1 map containers.    Printing the swapped values of m map container.    Printing the swapped values of m1 map container. End.Example Code Live Demo#include #include using namespace std; int main() {    unordered_map m, m1; // declaring m, m1 as empty map container    m.insert (pair('b', 10)); ... Read More

unordered_multimap size() function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

108 Views

unordered_multimap size() function in C++ STL returns the number of elements in the unordered map.AlgorithmBegin    Declare an empty map container m.    Performing reserve function to restrict the most appropriate    bucket_count of the map container.    Insert values in the map container.    Print the size of the unorderd multimap container by using the size() function. EndExample Code Live Demo#include #include using namespace std; int main() {    unordered_map m; // declaring m as empty map container    m.reserve(6); //restricting the most appropriate bucket_count of map container    m.insert (pair('b', 10)); // inserting some values    m.insert (pair('a', 20));    cout

Advertisements