Page not found.

# Kruskal’s algorithm : Reference

ImageDescription
AD and CE are the shortest arcs, with length 5, and AD has been arbitrarily chosen, so it is highlighted.
CE is now the shortest arc that does not form a cycle, with length 5, so it is highlighted as the second arc.
The next arc, DF with length 6, is highlighted using much the same method.
The next-shortest arcs are AB and BE, both with length 7. AB is chosen arbitrarily, and is highlighted. The arc BD has been highlighted in red, because there already exists a path (in green) between B and D, so it would form a cycle (ABD) if it were chosen.
The process continues to highlight the next-smallest arc, BE with length 7. Many more arcs are highlighted in red at this stage: BC because it would form the loop BCE, DE because it would form the loop DEBA, and FE because it would form FEBAD.
Finally, the process finishes with the arc EG of length 9, and the minimum spanning tree is found.

# Bitwise Left Shift (<<) Operator in C Programming

## Bitwise Left Shift Operator in C

1. It is denoted by <<
2. Bit Pattern of the data can be shifted by specified number of Positions to Left
3. When Data is Shifted Left , trailing zero’s are filled with zero.
4. Left shift Operator is Binary Operator [Bi - two]
5. Binary means , Operator that require two arguments

## Quick Overview of Left Shift Operator

 Original Number A 0000  0000  0011  1100 Left Shift 0000  0000  1111  0000 Trailing Zero’s Replaced by 0 (Shown in RED) Direction of Movement of Data <<<<<=======Left

## Syntax : Bitwise Left Shift Operator

`[variable]<<[number of places]`

## Live Example : Bitwise Operator [Left Shift Operator]

```#include<stdio.h>

int main()
{
int a = 60;

printf("\nNumber is Shifted By 1 Bit : %d",a << 1);
printf("\nNumber is Shifted By 2 Bits : %d",a << 2);
printf("\nNumber is Shifted By 3 Bits : %d",a << 3);

return(0);
}```

## Output :

```Number is Shifted By 1 Bit  : 120
Number is Shifted By 2 Bits : 240
Number is Shifted By 3 Bits : 480```

## Explanation of Left Shift Binary Operator :

We know the binary representation of the 60 is as below -

```0000 0000 0011 1100
```

Now after shifting all the bits to left towards MSB we will get following bit pattern -

```0000 0000 0011 1100   = 60
<< 1
-------------------
0000 0000 0111 1000   = 120
```

## Observations and Conclusion :

Shfting Binary 1 to Left By ‘X’ BitsDecimal ValueConverted Value
0 Bit2^01
1 Bit2^12
2 Bits2^24
3 Bits2^38
4 Bits2^416
5 Bits2^532
6 Bits2^664
7 Bits2^7128
8 Bits2^8256

# What is meaning of (++*ptr) in Pointer ?

In the previous topic we have studied Precedence of Value at and Address Operator of Pointer. In this chapter we will be looking more advance form of pointer. We are looking one step forward to learn how (++*ptr) works ?

## Meaning of (++*ptr) in C Programming :

Consider the Following Example :

```int num = 20 , *ptr ;
ptr = &num;
printf("%d",++*ptr);
```

## Explanation :

1. ‘++’ and ‘*’ both have Equal Precedence
2. Associativity is from Right to Left ( Expression evaluated from R->L)
3. Both are Unary (Operates on single operand )
4. So ‘ * ‘ is Performed First then ‘ ++ ‘

Re-Commanded Reference Article : Operator Precedence Table

## Calculation of Answer :

```  ++*ptr     =  ++ ( *ptr )
=  ++ ( *3058 )
=  ++ ( 20 )
=  21```
1. Suppose ptr variable stores address 3058.
2. * Operator will de-reference pointer to get value stored at that address. (i.e 20)
3. Pre-increment on 20 will perform increment first then assignment

## Live Example : Meaning of ++*ptr Pointer

```#include<stdio.h>

int main()
{
int n = 20 , *ptr ;
ptr = &n;
printf("%d",++*ptr);

return(0);
}```

Output :

`21`

In the next chapter we will be learning the meaning of (*++ptr) Pointer.

# What is the size of Pointer variable in C ?

In the previous chapter, we have learnt about the memory organization of the pointer variable. In this chapter we are learning to compute or find the size of pointer variable.

## What is the size of Pointer variable in C ?

Pointer is the variable that stores the address of another variable.

## How to calculate size of Pointer ?

Consider the following memory map before declaring the variable.In the memory comprise of blocks of 1 byte.

Whenever we declare any variable then random block of memory is chosen and value will be stored at that memory location.

Similarly whenever we declare any pointer variable then random block of memory will be used as pointer variable which can hold the address of another variable.

## Calculating Size of Pointer : Tips

1. Pointer stores the address of the Variable.
2. Size of Pointer Variable can be evaluated by using sizeof operator
3. Address of variable is considered as integer value.
4. For Borland C/C++ Compiler, for storing integer value 2 bytes are required.
5. Thus Pointer variable requires 2 bytes of memory.

## Size of Integer Pointer Variable in Different IDE :

CompilerSize of IntegerSize of Integer Pointer
Borland C/C++2 Bytes2 Bytes
Turbo C/C++2 Bytes2 Bytes
Visual C++4 Bytes4 bytes

## Size of the Pointer :

```#include<stdio.h>

int main()
{
int num = 15;
int *ptr = NULL;

ptr = &num;

printf("Size of Pointer : %d Bytes",sizeof(ptr));
return 0;
}```

## Output :

`Size of Pointer : 2 Bytes`

# Application of Array in C Programming

## Application Of Array :

Array is used for different verities of applications. Array is used to store the data or values of same data type. Below are the some of the applications of array -

## A. Stores Elements of Same Data Type

Array is used to store the number of elements belonging to same data type.

`int arr[30];`

Above array is used to store the integer numbers in an array.

```arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;```

Similarly if we declare the character array then it can hold only character. So in short character array can store character variables while floating array stores only floating numbers.

## B. Array Used for Maintaining multiple variable names using single name

Suppose we need to store 5 roll numbers of students then without declaration of array we need to declare following -

`int roll1,roll2,roll3,roll4,roll5;`
1. Now in order to get roll number of first student we need to access roll1.
2. Guess if we need to store roll numbers of 100 students then what will be the procedure.
3. Maintaining all the variables and remembering all these things is very difficult.

### Consider the Array :

`int roll[5];`

So we are using array which can store multiple values and we have to remember just single variable name.

## C. Array Can be Used for Sorting Elements

We can store elements to be sorted in an array and then by using different sorting technique we can sort the elements.

### Different Sorting Techniques are :

1. Bubble Sort
2. Insertion Sort
3. Selection Sort
4. Bucket Sort

## D. Array Can Perform Matrix Operation

Matrix operations can be performed using the array.We can use 2-D array to store the matrix.

Matrix can be multi-dimensional

## E. Array Can be Used in CPU Scheduling

CPU Scheduling is generally managed by Queue. Queue can be managed and implemented using the array. Array may be allocated dynamically i.e at run time. [Animation will Explain more about Round Robin Scheduling Algorithm | Video Animation]

## F. Array Can be Used in Recursive Function

When the function calls another function or the same function again then the current values are stores onto the stack and those values will be retrieve when control comes back. This is similar operation like stack.

# if-else-if Statement OR else if Ladder : Tutorial on If

## if-else-if Statement OR else if Ladder :

Suppose we need to specify multiple conditions then we need to use multiple if statements like this -

```void main ( )
{
int num = 10 ;

if ( num  >  0 )
printf ("\n Number is Positive");

if ( num  <  0 )
printf ("\n Number is Negative");

if ( num  ==  0 )
printf ("\n Number is Zero");
}
```

which is not a right or feasible way to write program. Instead of this above syntax we use if-else-if statement.

### Consider the Following Program –

```void main ( )
{
int num = 10 ;
if ( num  >  0 )
printf ("\n Number is Positive");
else if ( num  <  0 )
printf ("\n Number is Negative");
else
printf ("\n Number is Zero");
}
```

## Explanation :

In the above program firstly condition is tested i.e number is checked with zero. If it is greater than zero then only first if statement will be executed and after the execution of if statement control will be outside the complete if-else statement.

```else if ( num  <  0 )
printf ("\n Number is Negative");
```

Suppose in first if condition is false then the second condition will be tested i.e if number is not positive then and then only it is tested for the negative.

```else
printf ("\n Number is Zero");
```

and if number is neither positive nor negative then it will be considered as zero.

## Which is faster and feasible way for Writing If ?

PointExample 1Example 2
No of If Statements32
No of times Condition Tested (Positive No.)31
No of times Condition Tested (Negative No.)32
No of times Condition Tested (Zero No.)32

# Difference between Declaration and Definition in C Programming

## Some Examples of Declaration :

### Declaration of Function :

Whenever we write function after the main function, compiler will through the error since it does not have any idea about the function at the time of calling function. If we provide prototype declaration of function then we compiler will not look for the definition.

```int sum(int,int);

main()
{
int res = sum(10,20);
}

int sum(int n1,int n2)
{
return(n1+n2);
}```

In the above example , first line is called as function declaration.

`int sum(int,int);`

### Declaring Variable

Whenever we write declaration statement then memory will not be allocated for the variable. Variable declaration will randomly specify the memory location.

```int ivar;
float fvar;```

## A. Space Reservation :

1. Whenever we declare a variable then space will not be reserved for the variable.
2. Whenever we declare a variable then compiler will not look for other details such as definition of the variable.
3. Declaration is handy way to write code in which actual memory is not allocated.
```struct book  {
int pages;
float price;
char *bname;
};```

In the above declaration memory is not allocated. Whenever we define a variable then memory will be allocated for the variable.

```struct book b1;
```

## B. What it does ?

1. Declaration will identify the data type of the identifier.
2. Definition of the variable will assign some value to it.

## C. Re-Declaration Vs Re-Definition

In Both the cases we will get compile error. Re-declaration and Re-definition is illegal in C programming language.

## Re-Declaring the Variable in Same Scope :

```main()
{
int num1;
int num1;
}
```

&

```struct book  {
int pages;
float price;
char *bname;
};

struct book  {
int pages;
float price;
char *bname;
};
```

above statement will cause error.

## Re-Defining the Variable :

```int sum(int n1,int n2)
{
return(n1+n2);
}

int sum(int n1,int n2)
{
return(n1+n2);
}
```

above definition will cause compile error.

## Difference between Declaration and Definition

NoDeclarationDefinition
1Space is Not ReservedIn Definition Space is Reserved
2Identifies Data TypeSome Initial Value is Assigned
3Re-Declaration is ErrorRe-Definition is Error
Some Re-commanded Reading List : Link 1 | Link 2 | Link 3

# What is Data Type in C Programming ?

## What is Data Type in C Programming ?

1. A Data Type is a Type of Data.
2. Data Type is a Data Storage Format that can contain a Specific Type or Range of Values.
3. When computer programs store data in variables, each variable must be assigned a specific data type.

## Some of the Data Types Supported by C :

Data TypekeywordDescription
Integer Data TypeintStores the Integer Value
Float Data TypefloatStores the Floating Point Value
Character Data TypecharStores the Single Character Value
Long Data TypelongStores the Long range Integer Value
Double Data TypedoubleStores the long range Floating Value

## Explanation :

1. Whenever we declare variable in Computer’s memory, Computer must know the type of the data to be stored inside the memory.
2. If we need to store the single character then the size of memory occupied will be different than storing the single integer number.
3. The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C.
4. A byte can store a relatively small amount of data one single character or a small integer (generally an integer between 0 and 255).

Re-commanded Readings : Data Type

## Size Required to Store Variable of Different Data Types

Data TypeBorland C/C++ CompilerVisual C++
Integer2 Bytes4 bytes
Float4 Bytes4 Bytes
Character1 Byte1 Byte
Long4 Byte8 Byte

# 1-D Array – Compile Time Initializing in C Programming

## Different Methods of 1-D Array – Compile Time Initializing

Whenever we declare an array we can initialize array directly at compile time. Initialization of an array is called as compiler time initialization if and only if we assign certain set of values to array element before executing program. i.e at Compilation Time.

## Different Ways Of Array Initialization :

1. Size is Specified Directly
2. Size is Specified Indirectly

## A. Method 1 : Array Size Specified Directly

In this method , we try to specify the Array Size directly.

```int num[5] = {2,8,7,6,0};
```

In the above example we have specified the size of array as 5 directly in the initialization statement.Compiler will assign the set of values to particular element of the array.

```num[0] = 2
num[1] = 8
num[2] = 7
num[3] = 6
num[4] = 0
```

As at the time of compilation all the elements are at Specified Position So This Initialization Scheme is Called as “Compile Time Initialization“.

## B. Method 2 : Size Specified Indirectly

In this scheme of compile time Initialization, We does not provide size to an array but instead we provide set of values to the array.

```int num[] = {2,8,7,6,0};
```

## Explanation :

• Compiler Counts the Number Of Elements Written Inside Pair of Braces and Determines the Size of An Array.
• After counting the number of elements inside the braces, The size of array is considered as 5 during complete execution.
• This type of Initialization Scheme is also Called as “Compile Time Initialization

## Live Example :

```#include <stdio.h>

int main()
{
int num[] = {2,8,7,6,0};
int i;

for(i=0;i<5;i++) {
printf("\nArray Element num[%d] : %d",i+1,num[i]);
}

return 0;
}
```

## Output :

```Array Element num[1] : 2
Array Element num[2] : 8
Array Element num[3] : 7
Array Element num[4] : 6
Array Element num[5] : 0
```

# Basic Stack Operation : Data Structure

## Primitive Basic Stack Operation in C

We know that Stack can be represented using an array. Stack is open at one end and operations can be performed on single end. We can have different primitive operations on Stack Data Structure.

## Creating Stack Data Structure :

```typedef struct stack {
int data[MAX];
int top;
}stack;```

1. Create
2. Push
3. Pop
4. Empty

## A. Creating Stack :

1. Stack can be created by declaring the structure with two members.
2. One Member can store the actual data in the form of array.
3. Another Member can store the position of the topmost element.
```typedef struct stack {
int data[MAX];
int top;
}stack;
```

## B. Push Operation on Stack :

We have declared data array in the above declaration. Whenever we add any element in the ‘data’ array then it will be called as “Pushing Data on the Stack”.

Suppose “top” is a pointer to the top element in a stack. After every push operation, the value of “top” is incremented by one.

## C. Pop Operation on Stack :

Whenever we try to remove element from the stack then the operation is called as POP Operation on Stack.

## Some basic Terms :

ConceptDefinition
Stack PushThe procedure of inserting a new element to the top of the stack is known as Push Operation
Stack OverflowAny attempt to insert a new element in already full stack is results into Stack Overflow.
Stack PopThe procedure of removing element from the top of the stack is called Pop Operation.
Stack UnderflowAny attempt to delete an element from already empty stack results into Stack Underflow.