Found 7346 Articles for C++

wcspbrk() function in C/C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

103 Views

The wcspbrk() function is a built in function of C or C++. It searches for a set of wide characters present in a wide string in another wide string. This function is present into cwhar header file.This function takes two arguments. The first argument is destination, and the second argument is the source. As destination we have to pass null terminated wide strings to be searched. As source, we have to pass null terminated wide string, that is containing the characters that will be searched.This function returns two values. If one or more than one wide character is present, this ... Read More

Convert C/C++ code to assembly language

Smita Kapse
Updated on 30-Jul-2019 22:30:25

6K+ Views

Here we will see how to generate assembly language output from C or C++ source code using gcc.The gcc provides a great feature to get all intermediate outputs from a source code while executing. To get the assembler output we can use the option ‘-S’ for the gcc. This option shows the output after compiling, but before sending to the assembler. The syntax of this command is like below.gcc –S program.cppNow, let us see how to output will be look like. Here we are using a simple program. In this program two numbers are stored into the variables x and ... Read More

Difference between C structures and C++ structures

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

3K+ Views

Here we will see what are the differences between structures in C and structures in C++. The C++ structures are mostly like classes in C++. In C structure, all members are public, but in C++, they are private in default. Some other differences are listed below.C StructureC++ StructureStructures in C, cannot have member functions inside structures.Structures in C++ can hold member functions with member variables.We cannot initialize the structure data directly in C.We can directly initialize structure data in C++.In C, we have to write ‘struct’ keyword to declare structure type variables.In C++, we do not need to use ‘struct’ ... Read More

Structure Sorting in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

1K+ Views

Here we will see how to sort using some condition on some member variables of the structure in C++. In this example we will take a structure called book. The book will hold name, number of pages, and price. We will sort them based in the price.For comparing two structures, we have to define a function. This function will compare them with these parameters. This comparison function is used inside the sort function to sort the values.Example#include  #include using namespace std; struct book {    string title;    int pages;    float price; }; bool compareBook(book b1,  book b2) {    if(b1.price Read More

Macros and Preprocessors in C

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

3K+ Views

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −Sr.NoDirectives & Descriptions1#defineSubstitutes a preprocessor macro.2#includeInserts a particular header from another ... Read More

enum vs. const vs. #define in C/C++

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

458 Views

Here we will see what are the differences between enum, const and the #define in C or C++ programs. These three creates some confusion while we have to take the decision for choosing them. Now let us see what are these three things.const or static constThe const is constant type data, or static const is constant but storage specifier is static. So it will remain active until the program is terminated, and constant type data cannot be updated.Example#include using namespace std; main() {    int x;    x = 65700;    cout

How to write a short literal in C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

629 Views

Here we will see how will be the short literal in C++. In C or C++, different types of data have different literals. These are listed below.Sr.NoDatatypes & Literals1int52unsigned int5U3Long5L4long long5LL5float5.0f6double5.07char‘\5’Now, there are int, long float, double etc, but no short is present. So we cannot use any literals for short type data. But we can solve this problem by explicit typecasting.If we use the line like below, then it will be converted into short.int x; x = (short) 5; //converted into short type data.Example#include using namespace std; main() {    int x;    x = 65700;    cout ... Read More

C++ Program to Perform Edge Coloring on Complete Graph

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

186 Views

A complete graph is a graph which has a connecting edge between any pair of vertices. This is a C++ Program to Perform Edge Coloring on Complete Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’.    Construct a complete graph using e=n*(n-1)/2 edges, in ed[][].    Function EdgeColor() is used to Color the graph edges.    A) Assign color to current edge as c i.e. 1 initially.    B) If the same color is occupied by any of the adjacent edges, then       discard this color and go to flag again and try next color. ... Read More

C++ Program to Perform Edge Coloring of a Graph

Paul Richard
Updated on 30-Jul-2019 22:30:25

514 Views

In this program, we will perform Edge Coloring of a Graph in which we have to color the edges of the graph that no two adjacent edges have the same color. Steps in Example.AlgorithmBegin    Take the input of the number of vertices, n, and then number of edges, e, in the graph.    The graph is stored as adjacency list.    BFS is implemented using queue and colors are assigned to each edge. EndExample#include using namespace std; int n, e, i, j; vector g; vector color; bool v[111001]; void col(int n) {    queue q;    int c = ... Read More

C++ Program to Implement a Heuristic to Find the Vertex Cover of a Graph

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

556 Views

Vertex Cover of a Graph is to find a set of vertices V, such that for every edge connecting M to N in graph, either M or N (or both) are present in V. In this program, we Implement a Heuristic to Find the Vertex Cover of a Graph.AlgorithmBegin    1) Initialize a set S as empty.    2) Take an edge E of the connecting graph Say M and N.    3) Add both vertex to the set S.    4) Discard all edges in the graph with endpoints at M or N.    5) If some edge is ... Read More

Advertisements