Found 83 Articles for Miscellaneous

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 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

817 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 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

Difference Between Float and Double

AmitDiwan
Updated on 24-Mar-2021 12:58:50

1K+ Views

In this post, we will understand the difference between float and double data types.floatIt has a single precision.It takes 4 bytes of memory.According to IEEE, it has 32-bit precision.It is used with graphic based libraries.It improves the processing power of programs.It is simple to manage by compilers.Its value can be between 1.2E-38 to 3.4E+38.It can have a precision of up to 6 decimal places.doubleIt has a double precision.It takes 8 bytes of memory.According to IEEE, it has 64-bit precision.Its value can be between 2.3E-308 to 1.7E+308.It can have a precision of up to 15 decimal places.It is considered as the ... Read More

Difference Between int and long

AmitDiwan
Updated on 24-Mar-2021 12:50:50

3K+ Views

In this post, we will understand the difference between ‘int’ and ‘long’ types.intIt is a datatype.It has 32-bits.In terms of bytes, it takes up 4 bytes.In Java, it is between the range –2, 147, 483, 648 to 2, 147, 483, 647.It is also used as a keyword to declare variable of type integer.In comparison to memory required to store ‘long’ variables, it takes up less memory space.longIt is a data type.It takes 64-bits.In terms of bytes, it takes 8 bytes.In Java, its range is between –9, 223, 372, 036, 854, 775, 808 to 9, 223, 372, 036, 854, 775, 807.It ... Read More

Difference between new and malloc( )

AmitDiwan
Updated on 24-Mar-2021 12:48:23

720 Views

In this post, we will understand the difference between ‘new’ and ‘malloc’.newIt is present in C++, Java, and C#.It is an operator that can be used to call the constructor of the object.It can be overloaded.If it fails, an exception is thrown.It doesn’t need the ‘sizeof’ operator.It doesn’t reallocate memory.It can initialize an object when allocating memory for it.The memory allocated by ‘new’ operator can be de-allocated using ‘delete’ operator.It reduces the execution time of the application.Example#include using namespace std; int main(){ int *val = new int(10); cout Read More

Advertisements