Found 33676 Articles for Programming

Difference Between break and continue

AmitDiwan
Updated on 24-Mar-2021 14:15:39

2K+ Views

In this post, we will understand the difference between break and continue statements.breakIt is used to terminate the enclosing loop like while, do-while, for, or switch statement where it is declared.It resumes control over the program until the end of the loop.It also helps with the flow of control outside the loop.It is used with ‘switch’ and ‘label’ since it is compatible.Following is the flowchart of break statement −continueIt helps skip the remaining part of the loop.It continues to execute the next iteration.It causes early execution of the next iteration of the enclosing loop.It can’t be used with ‘switch’ and ... Read More

Difference Between One-Dimensional (1D) and Two-Dimensional (2D) Array

AmitDiwan
Updated on 24-Mar-2021 14:15:09

939 Views

In this post, we will understand the difference between one dimensional array and two dimensional array.One dimensional arrayIt helps store a single list of elements that are similar data type.The total bytes is calculates as the product of the datatype of variable array and the size of the array.C++ declarationtype variable_name[ size ];Java declarationtype variable_name [ ]; variable_name = new type[size];int [ ] a = new int [10];Two-Dimensional arrayIt helps store 'list of lists' or 'array of arrays' or 'array of one dimensional arrays', i.e nested arrays.The total bytes is equivalent to product of datatype of variable array and size ... Read More

Difference Between Virtual and Pure Virtual Function

AmitDiwan
Updated on 24-Mar-2021 14:11:51

1K+ Views

In this post, we will understand the difference between virtual and pure virtual functions.Virtual FunctionIt has its own definition inside the class.The base class can override a virtual function.It doesn’t have a derived class.Declarationvirtual funct_name(parameter_list) {. . . . .};Pure Virtual FunctionIt doesn’t have a definition.If a class has at least one virtual function, it can be declared abstract.The derived class has to override the pure virtual function to use it.A pure virtual function is specified by placing "= 0" in its declarationDeclarationvirtual funct_name(parameter_list)=0;Following is an example −Exampleclass Box {    public:    // pure virtual function    virtual double ... Read More

Difference Between while and do-while Loop

AmitDiwan
Updated on 24-Mar-2021 14:11:20

6K+ Views

In this post, we will understand the difference between the ‘while’ loop and the ‘do-while’ loop.while conditionThe controlling condition here appears at the beginning of the loop.The iterations do not occur if the condition at the first iteration results in False.It is also known as an entry-controlled loopThere is no condition at the end of the loop.It doesn’t need to execute at least one.Examplewhile ( condition){ statements; //body of loop }Following is the flowchart of while loop −do-while conditionThe controlling condition is present at the end of the loop.The condition is executed at least ... Read More

Difference Between for and while loop

AmitDiwan
Updated on 24-Mar-2021 14:07:55

12K+ Views

In this post, we will understand the difference between the ‘for’ and the ‘while’ loop.For loopThe initialization, condition checking, and the iteration statements are written at the beginning of the loop.It is used only when the number of iterations is known beforehand.If the condition is not mentioned in the 'for' loop, then the loop iterates infinite number of times.The initialization is done only once, and it is never repeated.The iteration statement is written at the beginning.Hence, it executes once all statements in loop have been executed.Examplefor(initialization; condition; iteration){ //body of the 'for' loop }Following is the flowchart ... Read More

Difference Between Structure and Class

Ravi Ranjan
Updated on 15-May-2025 16:13:38

6K+ Views

In C++, both structures (struct) and classes (class) are user-defined data types, where they both give access to group different data elements (variables) and functions together. However, they still possess a few differences between them. In this article, we will see and go through its differences. Structure (struct) The struct is a user-defined data type, which allows the grouping of variables of different data types, with the members being public by default. This is commonly used to represent simple data structures, where encapsulation is not necessary. A struct can contain data members and member functions, but its primary use is ... Read More

Explain insertion of elements in linked list using C language

Sindhura Repala
Updated on 27-Jan-2025 15:37:10

3K+ Views

Linked List Representation Linked lists use dynamic memory allocation, allowing them to grow and shrink as needed. They are defined as a collection of nodes, each containing two parts: data and a link. A linked list is a linear data structure where each element is known as a node, is connected to the next one using pointers. Unlike arrays, elements of a linked list are stored in random memory locations. The representation of data, links, and linked lists is shown below − Representation of node - Representation of Linked List -      Insertion Insertion operations in a linked list ... Read More

Explain the evaluation of expressions of stacks in C language

Bhanu Priya
Updated on 06-Dec-2024 15:49:44

21K+ Views

Stack is a linear data structure, that allows elements to be added and removed in a last-in, first-out(LIFO). The main operations are − Push Pop Display The Push Operation A stack adds a new item on top. A stack overflow occurs when the stack is full and cannot specify more items. Given below is an algorithm for Push() − Check for stack overflow. if (top = = n-1) printf("stack over flow"); Otherwise, insert an element into the stack. top ++ a[top] = item The ... Read More

Explain the conversions of expressions of stacks in C language

Bhanu Priya
Updated on 21-Jun-2024 21:50:10

2K+ Views

Stack is a linear data structure, where data is inserted and removed only at one end.AlgorithmsGiven below is an algorithm for Push ( ) −Check for stack overflow.if (top = = n-1) printf("stack over flow");Otherwise, insert an element into the stack.top ++ a[top] = itemGiven below is an algorithm for Pop ( ) −Check for stack underflow.if (top = = -1) printf("stack under flow");Otherwise, delete an element from the stack.item = a[top] top --Given below is an algorithm for Display ( ) −if (top == -1) printf ("stack is empty");Otherwise, follow the below mentioned algorithm.for (i=0; i

Explain linear data structure queue in C language

Bhanu Priya
Updated on 24-Mar-2021 13:59:45

752 Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below −Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists.Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables.QueueIt is a linear data structure, where the insertion is done at rear end and the deletion is done at the front end.The order of queue is FIFO – First In First OutOperationsInsert – Inserting an element into a queue.Delete – Deleting an element from the ... Read More

Advertisements