Found 7346 Articles for C++

Builtin functions of GCC compiler in C++

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

444 Views

In the GCC compiler there are some builtin functions. These functions are like below.Function _builtin_popcount(x)This builtin function is used to count the number of 1s in an integer type data. Let us see an example of _builtin_popcount() function.Example Live Demo#include using namespace std; int main() {    int n = 13; //The binary is 1101    cout

Wide char and library functions in C++

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

3K+ Views

In this section we will see what is the wide character in C++. We will also see some functions that are used to handle wide characters.Wide characters are similar to character datatype. The main difference is that char takes 1-byte space, but wide character takes 2-bytes (sometimes 4-byte depending on compiler) of space in memory. For 2-byte space wide character can hold 64K (65536) different characters. So the wide char can hold UNICODE characters. The UNICODE values are international standard which allows for encoding for characters virtually for any character of any language.Example Live Demo#include using namespace std; int main() { ... Read More

Conversion constructor in C++?

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

702 Views

In this section we will see what is the conversion constructor in C++ class. A constructor is a special type of function of class. It has some unique property like, its name will be same as class name, it will not return any value etc. The constructors are used to construct objects of a class. Sometimes constructors may take some arguments, or sometimes it does not take arguments.When a constructor takes only one argument then this type of constructors becomes conversion constructor. This type of constructor allows automatic conversion to the class being constructed.Example Live Demo#include using namespace std; class my_class{ ... Read More

Type difference of character literals in C and C++

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

548 Views

In C++ the size of the character constants is char. In C the type of character constant is integer (int). So in C the sizeof(‘a’) is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.Example Live Demo#include main() {    printf("%d", sizeof('a')); }Output4Example Live Demo#include using namespace std; main() {    cout

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

215 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

378 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

481 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

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

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

Advertisements