Found 82 Articles for Miscellaneous

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

Difference Between Pointer and Reference

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

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

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

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

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

Tapas Kumar Ghosh
Updated on 05-May-2025 18:35:59

7K+ Views

In programming, int and long are the part of primitive data type. The int stores the integer value while long stores the larger range of values like a whole number. In this article, we will see the differences between int and long data types. int (Integer) Data Type The keyword int representing the integer value. It store the both positive and negative values such as -1, 45, -78, 85, etc., but not fractional and decimal values. The value ranges from –2, 147, 483, 648 to 2, 147, 483, 647. Behavior of int in Different Languages Following is the list of ... Read More

Difference between new and malloc( )

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

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

Difference Between malloc and calloc

AmitDiwan
Updated on 24-Mar-2021 12:31:57

898 Views

In this post, we will understand the difference between malloc and calloc.MallocThe method ‘malloc’ is used to assign a block of memory when it is requested.It doesn’t clear the memory.It only initializes the allocated memory when explicitly requested.It allocates memory of a specific ‘size’.This size is passed as parameter to it.This size is allocated from a heap.It performs its job quickly.Examplevoid *malloc(size_t size);CallocIt assigns the requested memory to multiple blocks.This memory allocated is initiated to zero.This initialization to 0 is done by ‘calloc’ method.It allocates memory to the required operation of a specific ‘size’, i.e num * size.The ‘num’ refers ... Read More

Advertisements