Found 205 Articles for Computer Programming

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

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

695 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

980 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

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

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

851 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

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

Advertisements