Found 33676 Articles for Programming

Line Splicing in C/C++

Revathi Satya Kondra
Updated on 30-May-2025 17:16:26

626 Views

In C/C++, Line splicing is a small feature that lets you split one long line of code into two lines by using a special symbol that is the backslash (\).Line splicing is a preprocessor feature, not a function or method. It does not have any parameters. But it simply affects how lines of code are interpreted by the preprocessor before compilation.How to Use Line Splicing? If a line of code is too long, and you want to break it into multiple lines to make it easier to read. You can use a backslash at the end ... Read More

C++ Program to Implement Hash Tables Chaining with Doubly Linked Lists

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

651 Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ program to Implement Hash Tables chaining with doubly linked lists.AlgorithmFor insert:Begin    Declare Function insert(int k, int v)       int hash_v= HashFunc(k)       HashTableEntry *en = ht[hash_v]       if (en == NULL)          en = new HashTableEntry          en->d = v          en->k = k ... Read More

C++ Program to Implement Hash Tables

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

21K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ program to Implement Hash Tables.AlgorithmBegin    Initialize the table size T_S to some integer value.    Create a structure hashTableEntry to declare key k and value v.    Create a class hashMapTable:    Create a constructor hashMapTable to create the table.    Create a hashFunc() function which return key mod T_S.    Create a function Insert() to insert element at ... Read More

Writing a binary file in C++

Revathi Satya Kondra
Updated on 17-Jun-2025 14:05:43

7K+ Views

The binary file stores data in binary format, and data can be written using the write() or fwrite() method in C++. Writing to a Binary File To write a binary file in C++, use write method like fwrite()/write() method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is current at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data. If any error ... Read More

What is the best way to read an entire file into a std::string in C++?

Revathi Satya Kondra
Updated on 10-Jun-2025 15:02:33

2K+ Views

To read an entire file into a std::string in C++, you can open the file using std::ifstream, read its contents using a std::stringstream or by moving the file pointer at the specified position, and then store the result in a std::string. Algorithm Here is a simple algorithm to read an entire file into a std::string in C++: Begin. Open the file using an ifstream object. Check if the file is successfully opened. Create an ostringstream object. Read the file content using rdbuf() and write it into the ostringstream. ... Read More

Reading and writing binary file in C/C++

Tapas Kumar Ghosh
Updated on 03-Jun-2025 12:53:36

76K+ Views

Writing a Binary File To write a binary file in C/C++ use fwrite()/write() method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is currently at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data. If any error has occurred during writing in the file, the stream is placed in an error state. Syntax of write() method Following is the basic syntax of ... Read More

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

821 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

15K+ 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

662 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

Advertisements