Click this link to see Difference Between C and C++

         

Difference between Local Variable and Global Variable

Slno. Local Variable Global Variable
1. A variable which is declared inside a function or block of code is known as a local variable. A variable which is declared outside function or block is known as a global variable.
 2. It is comparatively a simple variable. It is comparatively a complex variable.
3. The scope of this variable is available within/inside a function in which they are declared. The scope of this variable is available throughout the program.We can access this variable from any where from the program.
 4. Local variables are normally declared inside a main/other function body. Global variables are normally declared at the top of the program usually after header files.
5. Variables can be accessed only by those statements inside a main/other function in which they are declared. Any related statement in the entire program can access this variable.
 6. The Initial value of local variables are Garbage.
The initial value of global variables are for int=0,float=0.000000,char-”Blank space(Non-printable char).”
7. Life of a this variable is started when it is created/starts executed and lost when the functions terminate. Life of this variable exists until the program is executing i.e. it is created before the program’s global execution starts and lost when the program terminates.
8. Variable’s values are stored in a stack unless specified. The compiler decides the storage location of variable’s values.It is stored on a fixed location decided by the compiler.
9. It is suggested to use this variable in the program mostly. It is suggested to avoid/if not necessary, the use of global variables in regular practice.
10. Local variable’s values are unique for each block/function variable. Global variable’s values are common for each block/function variable.
11.  Data sharing is not possible as data of the local variable can be accessed by only one function. Here, values are shared by all the related variables of the program.Hence, data sharing is possible as multiple functions can access the same global variable.
12.  Parameters passing is required for local variables to access/share the value in other function. Parameters passing is not necessary for a global variable as it is visible throughout the program.
 13. When the value of the local variable is modified in one function, the changes are not visible/reflected in another function. When the value of the global variable is modified in one function changes are visible/available for rest of the program.

                

Difference between Array and String

Slno. Array String
1. Array can hold any data types data. It can hold only char data type.
2. Array size must be a constant value. hence, array size can’t be changed once declared. Normally string size also can,t be changed but can be modified using char pointer.
3. Array is not ended with null character by default. string is ended with null (‘\0’) character by default.
4. The length of an array is fixed. The size of string is not fixed.
5. Arrays are mutable i.e. the fields can be modified. Strings are immutable i.e. value can not be changed in memory once created.
6. The elements of arrays are stored contiguously in increasing memory locations. Strings can be stored in any manner in memory locations.

            

Difference between Call by Value and Call by Reference

Slno. Call by Value Call by Reference
1. A copy of actual parameters value is passed into respective formal parameters i.e. A copy of the variable is passed. The location/Reference (address) of actual arguments is passed into respected formal parameters which is accepted by the pointer  i.e. A variable itself is passed.
2. Separate memory location is created/allocated for actual and formal parameters. Same memory location is allocated/created for both actual and formal parameters.
3. Changes in formal parameters will not reflect changes in actual parameters. Changes in formal parameters will reflect changes in actual parameters.
4. Primitive datatype are passed using ‘call by value’. Objects are implicitly passed using ‘call by reference’.
5.
Syntax of Calling Function is –  FunctionName(variablename1, variable_name2, . . . );
Syntax of Calling Funtion is – FunctionName (&variablename1, &variable_name2, . .. .);    NB : In case of object,  object.functionname( object);
6.
Syntax of Receiving Function is – DataType FunctionName (datatype variablename1, datatype variablename2, . .  .)
          {   . . . codes        }
Syntax of Receiving Function is – DataType FunctionName ( datatype *variablename1, datatype *variablename2, . . .)
{ . . . codes}
NB : In the case of object,
datatype functionname (classtype objectname)
{ . . . codes }
7.
It works locally.
It works globally.
8.
The original value is not modified i.e. It does not allow to make any changes in the actual variables.
The original value is modified i.e. it allows to make changes in the values of original variables by using function calls.
9. 
Supports by most of the programming languages, to pass values as parameters, such as C, C++,C#, php, VB .Net etc.
Supports by least no. of the programming languages, to pass values as parameters, such as C++, Java  etc.
10.
It is supported by C.
Actually, there is no call by reference in C rather we can create the illusion of call by reference in C through pointers. In this case, we are sending the memory location of the argument through a pointer.

         

Difference between Structure and Union

Slno Similarities
1. Both are user-defined data types.
2. They allow the user to combine different data types under a single name.
3. They are declared similarly.
4. Both are used to store multiple data items. 
Slno Structure Union
1. ‘Struct’ keyword is used to define a structure. ‘Union’ keyword is used to define a union.
2. All members of a structure can be initialized at once. Only the first member can be initialized at a time.
3. Size of memory occupied by the structure is equal to the sum of size of the each member. Size of memory occupied by the union is equal to the size of the largest member present in it.
4. A structure uses separate memory space for all its members i.e. all the members of structure have unique memory location.Members of a structure do not share common memory space. all the members use same storage one by one i.e.Members of union  share common memory space.
5. Members of structure can be accessed individually at any time. At a time, only one member of union can be accessed.

6.

In Structure, change in the value of one member can not affect the other in structure.
In Union, change in the value of one member can affect the value of other member.

       

Difference between Macro and Function

Slno Similarities
1.
2.
3.
4.
Slno Macro Function
1. Macro is a Pre-processed Process. Function is a compiled process.
2. Here, Datatype checking is not done. Here, Datatype checking is  done.
3. Code length increases during macro expansion process. Code length remains same during processing.
4. Speed of execution of program is faster. Speed of execution of program is comparatively slower.
5. Macro does not check Compile Errors during processing. Function checks Compile Errors during compilation of the program.
6. Before Compilation, macro name is replaced by macro value i.e. macro expansion. During function call, mainly transfer of control takes place.
7. Generally Macros do not extend beyond one line of code. Function’s code can be of any number of lines.
8. They are useful where small code appears multiple times in the program. They are useful where large code appears multiple times in the program.
9. Use of macro in our program can lead to side effect. It is believed that there is no side effect of function using in the program.
10. We cannot do recursion in macro. We can do recursion in macro.
11. We cannot debug a macro code. We can debug a macro code.
12. We cannot return a parameter value. We can return a parameter value.

              

Difference between Iteration and Recursion

Slno Similarities
1. Both involve repetition.
2. Both involve a termination test.
3. Both can occur infinitely.
Slno Iteration Recursion
1. Iteration explicitly uses a repetition structure. Recursion achieves repetition through repeated function calls.
2. Iteration terminates when the loop continuation. Recursion terminates when a base case is recognized.
3. Iteration keeps modifying the counter until the loop continuation condition fails. Recursion keeps producing simple versions of the original problem until the base case is reached.
4. Iteration normally occurs within a loop so the extra memory assigned is omitted. Recursion causes another copy of the function and hence a considerable memory space’s occupied.
5. It reduces the processor’s operating time. It increases the processor’s operating time.

         

Difference between Procedure and Function

Slno Similarities
1.
2.
3.
Procedure Function
1. Procedure is a sub program which is included within main program/function. Functions is also a sub program
which is intended for specific task. eg. sqrt(), area(), avg() etc.
2. Procedure do not return a value. Functions may or may not return a value.
3. Procedure cannot be called again and again i.e. one time used. A Function can be called any  number of times as per need of the program.
4. Global variables cannot be used in procedure. A function can use both local as well as global variables as per need of the program.
5. Procedures can be used only in procedural programming concept such as Dbase, Foxpro etc. Functions can be used in modular programming concept such as C, C++ etc.

                   

Difference between Break and Continue

Slno Similarities
1.
2.
3.
Break Continue
1. Break is used to terminate the loop code or exit from the block of code where ever it encountered. The control then jumps to next statement after the loop or block. Continue is used for continuing the next iteration in the loop, leaving certain given condition iteration only.
2.
Break statement can be used with looping statement and switch statement. When break  statement is used in nested loops, then only the innermost loop is terminated.
This statement skips only the given condition in loop and continue the rest of the statements as it is. This continue statement used with looping statement.
3.
Syntax:
{
    statement1;
    statement2;
    statement3;
    break;
}
Syntax:
{
    statement1;
    continue;
    statement2;
    statement3;
    break;
}

       

           

Click this link to see Difference Between Structure and Class

 555 total views,  2 views today

Categories: C

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.