100% found this document useful (1 vote)
96 views

Important Differences in C Programming

The document compares and contrasts Linux and Windows operating systems, programming languages, data structures, and algorithms. It provides a table comparing key differences between Linux and Windows such as being open-source vs proprietary, number of applications supported, cost, security features, boot process, case sensitivity, reliability, and popularity. It also lists differences between compilers and interpreters, high-level and low-level programming languages, control structures like switch-case and if-else statements, and data access operators like dot and arrow. Flowcharts are compared to algorithms and pretest and posttest loops are explained with examples to calculate a sum from 1 to 10.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
96 views

Important Differences in C Programming

The document compares and contrasts Linux and Windows operating systems, programming languages, data structures, and algorithms. It provides a table comparing key differences between Linux and Windows such as being open-source vs proprietary, number of applications supported, cost, security features, boot process, case sensitivity, reliability, and popularity. It also lists differences between compilers and interpreters, high-level and low-level programming languages, control structures like switch-case and if-else statements, and data access operators like dot and arrow. Flowcharts are compared to algorithms and pretest and posttest loops are explained with examples to calculate a sum from 1 to 10.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Difference between Linux and Windows OS:

S. no. Point Linux Windows


1 Open-Source & Proprietary & Licensed
Type
FreeWare:
Linus Torvalds(1991), MS-Win3.1(1992)
Inventor(year)
2
3 Application Less More
4 Cost Freely available Costly
High Security:It never Low security:
5 Security
creates Registry Keys
boot from either primary Must boot from primary
6 Booting
or logical partition. partition.
File names-case File names- not case
7. Case sensitivity
sensitive sensitive
More Reliable: has Less Reliable
8. Reliability
better backup concept
Less Popular More Popular(Due to Its
9. Popularity
better GUI support)

Difference between Compiler and Interpreter:

Interpreter Compiler
Scans the entire program and translates it as a
Translates program one statement at a time.
whole into machine code.
It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time is source code but the overall execution time is
slower. comparatively faster.
Generates intermediate object code which
No intermediate object code is generated,
further requires linking, hence requires more
hence are memory efficient.
memory.
Continues translating the program until the first It generates the error message only after
error is met, in which case it stops. Hence scanning the whole program. Hence debugging
debugging is easy. is comparatively hard.
Ex-Programming language like Python, Ruby Ex-Programming language like C, C++ use
use interpreters. compilers.
Difference between High level language & Low level language
Points High level language Low level language
Learning High-level languages are easy to Low-level languages are difficult to
learn. learn.

Understanding High-level languages are near to Low-level languages are far from
human languages. human languages.
Execution Programs in high-level languages Programs in low-level languages are
are slow in execution. fast in execution.

Modification Programs in high-level languages Programs in low-level languages are


are easy to modify difficult to modify.
Facility at hardware level High-level languages do not provide Low-level languages provide facility
much facility at hardware level. to write programs at hardware level.
In Depth Knowledge of hardware Knowledge of hardware is not Deep knowledge of hardware is
required to write programs required to write programs.

Uses These languages are normally used These languages are normally used
to write application programs.
to write hardware programs.

Examples BASIC, COBOL, C, C++, Aassemblylanguage and machine


FORTRAN, Pascal, and Prolog
code. C also exists here
Difference between flowchart vs. algorithm
Flowchart Algorithm

Block by block information diagram Step by step instruction representing the

representing the data flow. process of any solution.

Easy to understand by any person. Bit difficult for the layman.

It uses symbols for processes and I/O. No symbols are used, completely in text.

Have some rule to create. No hard and fast rule.

Difficult to debug errors. Easy to debug errors.

It is difficult to write algorithm as

It is easy to make flowchart. compared to flowchart.


Comparison between switch case and else if ladder:
So, after going through the two control statements in brief, here are the main difference between switch case and else if
ladder:

1. In else if ladder, the control goes through the every else if statement until it finds true value of the statement
or it comes to the end of the else if ladder. In case of switch case, as per the value of the switch, the control
jumps to the corresponding case.
2. The switch case is more compact than lot of nested else if. So, switch is considered to be more readable.
3. The use of break statement in switch is essential but there is no need of use of break in else if ladder.
4. Another difference between switch case and else if ladder is that the switch statement is considered to be less
flexible than the else if ladder, because it allows only testing of a single expression against a list of discrete
values.
5. Since the compiler is capable of optimizing the switch statement, they are generally considered to be more
efficient. Each case in switch statement is independent of the previous one. In case of else if ladder, the code
needs to be processed in the order determined by the programmer.

Switch case statement works on the basis of equality operator whereas else if ladder works on the basis of true false(

zero/non-zero) basis.

Comparison of Dot and Arrow operator


1.Whenever we declare a structure or union variable then member can be accessed using the dot
operator. But when pointer to a structure or union is used then arrow operator is used.
2. Both dot and arrow operator serves same function to access member of structure or union. Lets
compare dot operator and arrow operator –

struct student struct student


{ {
char name[20], char name[20],
int roll; int roll;
}std; }*ptr;

Difference between Break & Continue


difference between a pretest and a post-test Loop.

PreTest Loop(while or for loop) PostTest Loop(Do-while/Loop)

1 Test the loop condition each time through the Loop while we check the condition at the
loop & it keeps executing while the test bottom.
expression is a true value.

2.When the conditional expression is false then When the do- while is used ,the body of loop
the statements in body of Loop are skipped. is executed at least once, since the condition is
at the bottom of the loop.

3. General Syntax is : General Syntax is :


while <condition> Do{
{ <statements>
<statements> }while<condition>;
}

// Sum of no. 1 to 10 using while :- // Sum of no. 1 to 10 using do-while :-


void main() void main()
{ {
int num=1; int num=1;
int sum=0; int sum=0;
while (num<11) do
{ {
sum=sum+num; sum=sum+num;
num++; num++;
} }
printf(“sum is=%d”, sum); while (num<11);
printf(“sum is=%d”, sum);
}
}
Output: Sum Is 55 Output: Sum Is 55
Explanation: if num is 11, sum will be 0,since Explanation: if num is 11, sum will be 11,since
while condition fails. while condition fails after executing loop once.

Draw Flowchart of while or For loop Flowchart of do-while loop

Difference between Recursion and Iteration


RECURSION ITERATION

Recursive function – is a function that is Iterative Instructions –are loop based repetitions
partially defined by itself of a process

Recursion Uses selection structure Iteration uses repetition structure

Infinite recursion occurs if the recursion step An infinite loop occurs with iteration if the loop-
does not reduce the problem in a manner that condition test never becomes false
converges on some condition.(base case)

Recursion terminates when a base case is Iteration terminates when the loop-condition fails
recognized

Recursion is usually slower then iteration due Iteration does not use stack so it's faster than
to overhead of maintaining stack recursion
Recursion uses more memory than iteration Iteration consume less memory

Infinite recursion can crash the system infinite looping uses CPU
cycles repeatedly

Recursion makes code smaller Iteration makes code longer

Example: Find Factorial of a Number using Example: Find Factorial of a Number using
Recursion Iteration
int factorial(int n) int factorial (int n){
{
/* Base condition if n equals to 1 then return int i,fac = 1;
1 */
if(n==1) for ( i = 1; i <= n; i++){
return 1;
fac = fac * i;
else
/* Recursive call */ }
return (n * factorial(n-1) ); return fac;
} }
main() main()
{ {
printf("%d",factorial(5)); printf("%d",factorial(5));
} }
Output:120 Output:120

Difference between Non-tail Recursion and Tail- tail Recursion


//Non-tail recursive factorial //Tail recursive factorial Output window:
//function //function
#include<stdio.h> #include<stdio.h> Enter the number
int fact_norm(int); int fact_tail(int, int); 4
void main() void main() Resultant factorial
{ { is 24
int no, factorial; int no, factorial;
printf(“Enter the number\t”); printf(“Enter the number\t”); Remarks:
scanf(“%d”,&no); scanf(“%d”,&no); fact_norm
factorial=fact_norm(no); factorial=fact_tail(no,1); function in column 1
printf(“Resultant factorial is printf(“Resultant factorial is a non-tail
%d”,factorial); is %d”,factorial); recursive function.
} } The last operation
//Non-tail recursive fact //Tail recursive fact function is a multiplication
function int fact_tail(int no, int result) operation.
int fact_norm(int no) { fact_tail function
{ if(no==1) in column 2 is a tail
if(no==1) return result; recursive function.
return 1; else The last operation
else return fact_tail of this function is a
return no*fact_norm(no-1); (no-1,no*result) ; recursive function
} } call.

Difference between Call (pass) by Value and Call by Reference


Give example-programs of swapping values of 2 variables in above difference

difference between string and character array


A major difference is: string will have static storage duration, whereas as a character
array will not, unless it is explicitly specified by using the static keyword. Actually, a
string is a character array with following properties :
 The multi-byte character sequence, to which we generally call string, is used to
initialize an array of static storage duration. The size of this array is just sufficient to
contain these characters plus the terminating NUL character.

 It not specified what happens if this array, i.e., string, is modified. So the value of a
string is the sequence of the values of the contained characters, in order.
Difference between array and pointer
Pointer Array
1. A pointer is a place in 1. An array is a single, pre allocated chunk
memory that keeps address of of contiguous elements (all of the same
another place inside type), fixed in size and location.
2. Pointer can’t be initialized at 2. Array can be initialized at definition.
definition. Example: int num[] = { 2, 4, 5}
3. Pointer is dynamic in nature. 3. They are static in nature. Once memory
The memory allocation can be is allocated , it cannot be resized or freed
resized or freed later. dynamically.
4. The assembly code of Pointer 4. The assembly code of Array is different
is different than Array than Pointer.

Difference between Arrays and Structures


Both the arrays and structures are classified as structured data types as they provide a
mechanism that enable us to access and manipulate data in a relatively easy manner.
But they differ in a number of ways listed in table below:

Arrays Structures
1. An array is a collection of related 1. Structure can have elements of
data elements of same type. different types
2. An array is a derived data type 2. A structure is a programmer-defined
data type
3. Any array behaves like a built-in 3. But in the case of structure, first we
data types. All we have to do is to have to design and declare a data
declare an array variable and use it. structure before the variable of that type
are declared and used.
Insert the complete example program in above difference

Difference Between Static Memory and Dynamic memory allocation

STATIC MEMORY ALLOCATION DYNAMIC MEMORY ALLOCATION

Memory is allocated before the execution of Memory is allocated during the execution of the
the program begins. program.
(During Compilation)

No memory allocation or deallocation actions Memory Bindings are established and destroyed
are performed during Execution. during the Execution.

Variables remain permanently allocated. Allocated only when program unit is active.

Implemented using stacks and heaps. Implemented using data segments.

Pointer is needed to accessing variables. No need of Dynamically allocated pointers.

Faster execution than Dynamic. Slower execution than static.

More memory Space required. Less Memory space required.


No specified functions are required. Malloc(),calloc(),realloc(),free() are used.
comparison between calloc and malloc functions

Calloc Malloc

Function allocates a region of memory large enough to allocates "size" bytes of memory.
hold "n elements" of "size" bytes each. Also
initializes contents of memory to zeroes.
Number of 2 1
arguments

Syntax void *calloc (number_of_blocks, void *malloc (size_in_bytes);


size_of_each_block_in_bytes);
Contents of allocated The allocated region is initialized to zero. The contents of allocated memory
memory
are not changed. i.e., the memory
contains unpredictable or garbage
values. This presents a risk.
Return value void pointer (void *). If the allocation succeeds, a void pointer (void *). If the
pointer to the block of memory is returned. If the allocation succeeds, a pointer to the
allocation of memory fails, a NULL pointer is block of memory is returned. If the
returned. allocation of memory fails, a NULL
pointer is returned.
Speed of execution Slower because of the extra step of initializing the Faster comparative to calloc
allocated memory by zero. However, in practice the
difference in speed is very tiny and not recognizable.

Differences between macro(function like) and functions are as:


Difference between android and windows OS/Phone

What are the differences between syntax error, run time error and logic errors.?
1) Syntax Errors are errors in the syntax of your code. This kind of error is the easiest to figure
out. They are revealed when you attempt to compile your program. An example would be as
mentioned - forgetting the semi colon at the end of a statement in a language like C.
2) Run time errors are unhandled errors that are raised during runtime. For example, your code
fails to get access to a remote machine. There is no way to be sure at compile time (when you
compile your program) whether this error is SURELY going to happen or not. You can suspect
that it happens though.
3) Logic Errors are the sneakiest. Your syntax is correct. No runtime error is being raised,
however your program logic is not correct (for example an incorrect formula).

Difference between implicit & explicit type conversion (type casting)


Implicit Conversion Explicit Conversion

Implicit Conversion is Explicit Conversion is


done automatically. done programatically.
In Implicit conversion, no data loss take In explicit conversion, data
place during the data conversion. loss may or may not be take
place during data
conversion. Hence there is
a risk of information loss.
No possibility of It might throw error if tried
throwing exception during the conversion to do without type casting.
and therefore is called type safe.
Implicit conversion do not require Explicit conversion do
any special syntax. require cast operator to
perform conversion.
Example : Example :
Conversion of smaller number to larger Conversion of larger
number is implicit conversion. number to smaller number
Conversion of integer type data to is explicit conversion.float
float.float i=0; k=123.456
int j=10; int i= (int) k
i=j; // This is Explicit
// This is implicit conversion since float is conversion and
larger than integer,hence no loss of data & (int) is type cast
no exception. operator. Here we may be
able to escape an exception
but there is noticeable data
loss.i.e. i=123
// .456 is lost during
conversion

Differences Between Linker and Loader

1. The key difference between linker and loader is that the linker
generates the executable file of a program whereas, the loader loads
the executable file obtained from the linker into main memory for
execution.
2. The linker intakes the object module of a program generated by the
assembler. However, the loader intakes the executable
module generated by the linker.
3. The linker combines all object module of a program to
generate executable modules it also links the library function in the
object module to built-in libraries of the high-level programming
language. On the other hands, loader allocates space to an
executable module in main memory.
4. The linker can be classified as linkage editor, and dynamic
linker whereas loader can be classified as absolute loader,
relocatable loader and dynamic run-time loader.

You might also like