Found 33676 Articles for Programming

C++ program to append content of one text file to another

Revathi Satya Kondra
Updated on 06-May-2025 18:53:08

1K+ Views

In C++, we can work with files to read, write, or even combine(append) their contents. Here, our task is to append the content of one text file to another. Imagine a scenario where we have two txt files which is named as 'source.txt' and 'destination.txt' files. So, with the help of these files we need to copy everything from the source file and append it at the end of the destination file. ExampleHere, we are giving an input as two text files as source.txt and destination.txt to append content in C++: source.txt file contains "Tutorials" destination.txt file contains "point" ... Read More

Print “Hello World” with empty or blank main in C++

Revathi Satya Kondra
Updated on 07-May-2025 14:13:04

541 Views

In this problem, we will see how to print "Hello World" into the console, but we cannot write anything into the main function. This problem can be solved in different ways. Initially, we will create a global variable, then we will store the returned value of the printf() function into that variable. When printf() is executed, then it will be printed. You can print "Hello World" without using the logic inside the main() function in different ways, such as using Global Constructors, Class Object and macros, or preprocessor, etc. Using Global Constructor A global constructor is the constructor of a global object ... Read More

C Program to find size of a File

Revathi Satya Kondra
Updated on 07-May-2025 14:18:00

2K+ Views

The size of a file refers to the number of bytes it occupies in memory. In C, size of a file can be found by moving the file pointer to the end of the file and checking its position. The position indicates the number of bytes the file contains. The most common way to do this is by using two functions: fseek() (to move to the end) and ftell() (to get the current position, which is the size of the file). Syntax Following is the syntax is as follows: FILE *fp = fopen("file.txt", "rb"); fseek(fp, 0, SEEK_END); long size = ... Read More

C++ Program to Find Size of the Largest Independent Set(LIS) in a Given a Binary Tree

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

174 Views

This is a C++ Program to Find Size of the Largest Independent Set (LIS) in a Given a Binary Tree.AlgorithmBegin.    Create a structure n to declare data d, a left child pointer l and a right child pointer r.    Call a function max() to return maximum between two integers. Create a function LIS() to return the    size of the largest independent set in a given binary tree.    Calculate size excluding the current node    int size_excl = LIS(root->l) + LIS(root->r)    Calculate size including the current node    int size_incl = 1;    if (root->l)   ... Read More

exit() vs _Exit() function in C and C++

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

459 Views

In this section we will see what are the differences between exit() and _Exit() in C and C++. In C the exit() terminates the calling process without executing the remaining code which is present after exit() function.In C++11, one new function is present called _Exit(). So what is the feature of this function? The exit() function performs some cleaning before terminating the program. It clears the connection termination, buffer flushes etc. This _Exit() function does not clean anything. If we test using atexit() method, it will not work.Let us see two examples where at first we are using exit() function, ... Read More

2D vector in C++ with user defined size

Aman Kumar
Updated on 24-Jul-2025 15:33:39

3K+ Views

In this article, we will see how we create and use 2D vectors with user-defined sizes. What is 2D Vector? In C++, a vector is a dynamic array used to store elements. The 2D vector is a vector of vectors and are used to create a dynamic two-dimensional array where the number of rows and the number of columns in each row can vary. Just like a 2D array, a 2D vector is used to store data in a tabular form such as matrices, grids, or tables. Structure of a 2D Vector A 2D vector is declared as: vector v; ... Read More

C++ Program to Find Lowest Common Ancestor in a Binary Search Tree

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

499 Views

A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to find the lowest common ancestor in a Binary Tree.AlgorithmBegin Create a structure n to declare data d, a left child pointer l and a right child pointer r.    Create a function to create newnode. Call a function LCA() to Find lowest common ancestor in a binary tree:    Assume node n1 and n2 present in the tree.    If root is null, then return.       If root is not null there are two cases.   ... Read More

C++ Program to Find Deepest Left Leaf in a Binary Tree

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

201 Views

A binary tree which has at most two children, specified as left child and right child. This is a C++ Program to Find Deepest Left Leaf in a Binary TreeAlgorithmBegin.    function deepestLLeafutil() find the deepest left leaf in a given    binary tree:         lvel is level of current node.       maxlvel is pointer to the deepest left leaf node found so far         isLeft Indicates that this node is left child of its parent         resPtr is Pointer to the result         If root is equal to Null ... Read More

C++ Program to Construct an Expression Tree for a Postfix Expression

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

2K+ Views

An expression tree is basically a binary tree which is used to represent expressions. In expression tree, nodes correspond to the operator and each leaf node corresponds to the operand. This is a C++ program to construct an expression tree for a postfix Expression in inorder, preorder and postorder traversals.AlgorithmBegin    Function r() has a character variable as parameter.       If the characters are + or - or * or / then          Return will be -1       If the characters are from A to Z then          Return will ... Read More

C++ Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree

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

247 Views

A binary tree is a tree data structure in which each node has at most two children, which are defined as left child and right child.AlgorithmBegin    function identical():        Take two nodes r1 and r2 as parameter.       If r1 and r2 is NULL then          Return true.       If r1 or r2 is NULL then          Return false.       Return (r1->d is equal to r2->d and          Call function Identical(r1->l, r2->l) and          Call functions Identical(r1->r, r2->r) ); ... Read More

Advertisements