Found 7401 Articles for C++

Precedence of postfix ++ and prefix ++ in C/C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

1K+ Views

Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)Example Live Demo#include using namespace std; int main() {    char arr[] = "Hello World";    char *ptr = arr;    ++*ptr;    cout

C++ Scope of Variables

George John
Updated on 30-Jul-2019 22:30:25

193 Views

A scope is a region of the program and broadly speaking there are three places, where variables can be declared −Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters.Outside of all functions which is called global variables.We will learn what is a function and it's parameter in subsequent chapters. Here let us explain what are local and global variables.Local VariablesVariables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. ... Read More

Line Splicing in C/C++

Chandu yadav
Updated on 30-Jul-2019 22:30:25

326 Views

In this section we will see what is the line spacing in C or C++. Sometimes we put some single line comment using double slash “//”. The one-line comment is basically ends when we move to the next line. But if we put back slash at the end of some single line comment, then what will be the effect?When back slash is used it continues to the next lie. So after the comment line, if there are some line after comment, it will also be ignored. Let us see an example.Example Live Demo#include using namespace std; int main () { ... Read More

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

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

423 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

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

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

5K+ Views

To write a binary file in C++ use 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 has occurred during writing in the file, the stream is placed in an error state.Syntax of write methodostream& write(const char*, int);AlgorithmBegin    Create a structure Student to declare variables.   ... Read More

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

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

1K+ Views

This is an simple way to read an entire file into std::string in C++AlgorithmBegin    Take the filename as inputstream.    Declare a string variable str.    Read the file till the end by using rdbuf().    Put the data into st.    Print the data. End.Example Code#include #include #include #include using namespace std; int main() {    ifstream f("a.txt");    string str;    if(f) {       ostringstream ss;       ss

Reading and writing binary file in C/C++

Samual Sam
Updated on 02-Sep-2023 12:49:38

54K+ Views

WritingTo write a binary file in C++ use 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 methodostream& write(const char*, int);ReadingTo read a binary file in C++ use read() method. ... Read More

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

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

603 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++?

karthikeya Boyini
Updated on 30-Jun-2020 10:47:33

11K+ Views

Let us consider the following C++ sample code to get the list of files in a directory.AlgorithmBegin    Declare a poniter dr to the DIR type.    Declare another pointer en of the dirent structure.    Call opendir() function to open all file in present directory.    Initialize dr pointer as dr = opendir(".").    If(dr)       while ((en = readdir(dr)) != NULL)          print all the file name using en->d_name.       call closedir() function to close the directory. End.Example#include #include #include using namespace std; int main(void) {    DIR ... Read More

Advertisements