Found 213 Articles for Computer Programming

Difference Between while and do-while Loop

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

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

10K+ 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 Array and Pointer

Kiran Kumar Panigrahi
Updated on 20-Feb-2023 15:47:39

8K+ Views

Array and pointers have a very close relationship in programming, but there are several differences between them. Read this article to find out how Arrays are different from Pointers. But let us first discuss some basics of arrays and pointers. What is an Array? An array is one that stores the values of a homogeneous data type. It refers to a collection that consists of elements of homogenous/same data type. Arrays are considered as a primitive data type. They are declared using the '[ ]' and are stored in contiguous memory locations. Also, arrays use subscripts/ '[ ]' (square brackets) ... Read More

Difference Between Structure and Class

AmitDiwan
Updated on 24-Mar-2021 14:02:04

4K+ Views

In this post, we will understand the difference between structure and class.ClassIt is defined using ‘class’ keyword.When data is defined in a class, it is stored in memory as a reference.It gets memory allocated only when an object of that class is created.The reference type (before creating an object) is allocated on heap memory.They can have constructors and destructors.It can use inheritance to inherit properties from base class.The ‘protected’ access modifier can be used with the data members defined inside the class.StructureThe ‘struct’ keyword is used to define a structure.Every member in the structure is provided with a unique memory ... Read More

Difference Between Pointer and Reference

AmitDiwan
Updated on 24-Mar-2021 13:37:00

816 Views

In this post, we will understand the difference between pointer and reference.PointerIt can be initialized to any value.It can be initialized any time after its declaration.It can be assigned to point to a NULL value.It can be dereferenced using the ‘*’ operator.It can be changed to point to a different variable of the same type only.Exampleint val = 5; //code// int *p = &val;ReferenceIt has to be initialized when it is declared.It can’t be a NULL value.It can be used by a name.Once it has been initialized to a variable, it can’t be changed to refer to a variable object.Exampleint ... Read More

Difference Between if-else and switch

AmitDiwan
Updated on 24-Mar-2021 13:35:16

1K+ Views

In this post, we will understand the difference between if-else statement and ‘switch’ statement.If-elseDepending on the expression inside the statement, output would be generated.It uses multiple statements for multiple choices.This statement tests for equality.It can be used to test logical expressions.It can evaluate integer, character, pointer, floating-point type and boolean type.Just one of the ‘if’ or ‘else’ statement gets executed.If the condition inside the ‘if’ statement is false, then the ‘else’ statement is executed if it has been created.It is tough to edit if-else statement, especially if it is nested.SwitchThe statement that needs to be executed is decided by the ... Read More

Difference Between Array and Structure

Kiran Kumar Panigrahi
Updated on 20-Feb-2023 16:05:22

13K+ Views

Arrays and Structures are two different types of container datatype. The most basic difference between an array and a structure is that an Array can contain the elements of same datatype, while a Structure is a collection that can contain the elements of dissimilar datatypes. Read this article to learn more about Arrays and Structures and how they are different from each other. What is an Array? An array refers to a collection that consists of homogenous elements, i.e. of same data type. Arrays are declared using '[]'. It uses subscripts/ '[ ]' (square brackets) to access the elements. An ... Read More

Difference Between exit(0) and exit(1)

AmitDiwan
Updated on 24-Mar-2021 13:31:28

2K+ Views

In this post, we will understand the difference between exit(0) and exit(1).exit(0)It is portable.It tells about the successful termination or completion of the program.It tells about the termination when the program is executed without any errors.The ‘EXIT_SUCCESS’ macro is used to return code 0.The ‘EXIT_SUCCESS’ can be defined as standard as zero.Syntaxexit(0);exit(1)It is not portable.It tells about the abnormal termination of the program.It tells about the termination if the program exited with certain error when the program was being executed.The ‘EXIT_FAILURE’ macro is used to return code 1.It is not restrict by standard to be 1 only.It can be used ... Read More

Difference Between Character Array and String

AmitDiwan
Updated on 24-Mar-2021 13:31:06

8K+ Views

In this post, we will understand the difference between character array and string.StringsThey are immutable.Once they are defined, they can’t be changed.It refers to a sequence of characters, which is represented as a single data type.It contains built-in functions such as substring(), charAt().The ‘+’ operator can be used to append strings together, which would form a new string.The charAt() method helps access characters at a specific index within a ‘String’.These strings are stored in the ‘String Constant Pool’.It is not preferred to store passwords in strings in Java.A string can be converted to a character array using toCharArray() method of ... Read More

Difference Between Recursion and Iteration

Kiran Kumar Panigrahi
Updated on 01-Nov-2023 01:10:57

39K+ Views

Recursion and Iteration both repeatedly execute the set of instructions. Recursion occurs when a statement in a function calls itself repeatedly. The iteration occurs when a loop repeatedly executes until the controlling condition becomes false. The basic difference between recursion and iteration is that recursion is a process always applied to a function and iteration is applied to the set of instructions which we want to be executed repeatedly. Read through this article to find out more about Recursion and Iteration and how they are different from each other. What is Recursion? Recursion is defined as a process in which a function calls itself repeatedly. Recursion uses selection structure. If the recursion step does ... Read More

Advertisements