Difference Between ref and out in C#

AmitDiwan
Updated on 24-Mar-2021 13:09:58

902 Views

In this post, we will understand the difference between ‘ref’ and ‘out’ in C#.Ref keywordBefore passing the parameters to ‘ref’, they need to be initialized.It is not necessary to initialize the value of the parameter before it returns to the calling method.The data can pass in two directions when the ‘ref’ keyword is used.It is useful when the called method needs to change the value of the parameter that is passed.Out keywordIt is not required to initialize parameters before it is passed to ‘out’.It is required to initialize the value of a parameter before it is returned to the calling ... Read More

Difference Between Delegates and Events in C#

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

2K+ Views

In this post, we will understand the difference between delegates and events in C#.DelegateIt can be declared using the ‘delegate’ keyword.It is a function pointer.It holds the reference to one or more methods during runtime.It is an independent keyword.It doesn’t depend on events.It contains the Combine() and Remove() methods that help add methods to the list of invocation.It can be passed as a parameter to a method.The ‘=’ operator can be used to assign a single method.The ‘+=’ operator can be used to assign multiple methods to a delegate.EventIt can be declared using the ‘event’ keyword.It can be defined as ... Read More

Difference Between Packages and Interfaces in Java

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

5K+ Views

In this post, we will understand the difference between packages and interfaces in Java.PackagesIt is a group of classes and/or interfaces that are together.It can be created using the "Package" keyword.It can be imported.It can be done using the "import" keyword.Examplepackage package_name; public class class_name {    .    (body of class)    . }InterfacesIt is a group of abstract methods and constants.It can be created using the "Interface" keyword.It can be extended by another interface.It can also be implemented by a class.It can be implemented using the ‘implement’ keyword.Exampleinterface interface_name { variable declaration; ... Read More

Find Palindrome Number Using While Loop in C

Bhanu Priya
Updated on 24-Mar-2021 13:05:23

16K+ Views

Palindrome number is a number which remains same when it reverses. In C language, the user is allowed to enter any positive integer and to check, whether the given number is palindrome number or not by using the while loop.Example1Following is the C Program to find Palindrome number by using the while loop − Live Demo#include int main(){    int num, temp, rem, rev = 0;    printf("enter a number:");    scanf("%d", &num);    temp = num;    while ( temp > 0){       rem = temp %10;       rev = rev *10+ rem;     ... Read More

Convert Centimeter to Meter and Kilometer in C

Bhanu Priya
Updated on 24-Mar-2021 13:03:38

6K+ Views

Here, the user has to enter the length in centimeters (cm), and then, convert the length into meters (m), and kilometer (km).1 Meter = 100 Centimeters 1 Kilometer = 100000 CentimetersAlgorithmRefer an algorithm given below to convert centimeter into meter and kilometer respectively.Step 1: Declare variables. Step 2: Enter length in cm at runtime. Step 3: Compute meter by using the formula given below.    meter = centim / 100.0; Step 4: Compute kilometer by using the formula given below.    kilometer = centim / 100000.0 Step 5: Print meter. Step 6: Print kilometeExample1Following is the C program to convert ... 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

Find the Sum of Arithmetic Progression Series in C

Bhanu Priya
Updated on 24-Mar-2021 12:55:26

2K+ Views

ProblemFind the sum of an arithmetic progression series, where the user has to enter first number, total number of elements and the common difference.SolutionArithmetic Progression (A.P.) is a series of numbers in which the difference of any two consecutive numbers is always the same. Here, total number of elements is mentioned as Tn.Sum of A.P. Series: Sn = n/2(2a + (n – 1) d) Tn term of A.P. Series: Tn = a + (n – 1) dAlgorithmRefer an algorithm given below to find the arithmetic progression.Step 1: Declare variables. Step 2: Initialize sum=0 Step 3: Enter first number of series ... Read More

C Program to Generate an Electricity Bill

Bhanu Priya
Updated on 24-Mar-2021 12:54:05

10K+ Views

Based on the units consumed by the user, the electricity bill is generated. If number of units consumed are more then, the rate of a unit charge will also increase.The logic applied if minimum units are consumed by the user is as follows −if (units < 50){    amt = units * 3.50;    unitcharg = 25; }The logic applied if units are in between 50 to 100 is given below −else if (units

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 Dispose and Finalize in C#

AmitDiwan
Updated on 24-Mar-2021 12:47:38

1K+ Views

In this post, we will understand the difference between the methods ‘dispose’, and ‘finalize’ in C#.DisposeThis method is defined in the IDisposable interface.It has to be invoked by the user.Whenever it is invoked, it helps free the unmanaged resources.It can be implemented whenever a close() method is present.It is declared as public method.It is quick, and instantly disposes an object.Since it performs instantaneously, it doesn’t affect performance.FinalizeIt is a method that is defined in the java.lang.object class.It is invoked by the garbage collector.It helps free the unmanaged resources just before the object is destroyed.It is implemented to manage the unmanaged ... Read More

Advertisements