sizeof operator in C
sizeof operator in C is an unary operator which can be used to find the size of the data-type or expression or a variable.
It returns the size of the memory allocated (in Bytes) by the compiler. Lets say, we want to find the size of the memory allocated to the data-type int
. We can find it by using sizeof
operator as shown in the below code:
#include<stdio.h> #include<conio.h> void main() { clrscr(); int sizeOfInt; sizeOfInt = sizeof(int); printf("%d Bytes", sizeOfInt); getch(); }
Output:
2 Bytes
As you can see, the above code calculated the size of int data type and displayed the result.
Find Max from Array Data
Find Min from Array Data
Sort the elements of Array
Data insert in an array specific position
Data delete in an array specific position
I didnt understand the codes
To find max and min, you can sort array in either ascending order to descending order and read the first and last element.
Refer the below code for sorting:
https://www.learnconline.com/2010/04/program-in-c-to-sort-array-in-descending-order.html
For the 4th and 5th request, I will update the website soon and revert with the solution.
Thanks,
LearnCOnline Team
while sorting in array why do we need this??
for(i=0;i<no;i++)
{
for(j=i;j??? why do we need this??
{
if(arr[i] > arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
Hello Zerin,
In the above program, the sorting logic is as follows:
Read the first element of an array, compare it with remaining elements which are present after the first element and swap the elements based on the if condition.
The above program consist of two for loops,
1) for(i=0;i<no;i++)
2) for(j=i;j<no;j++)
Consider a[2] = {2, 1};
Lets consider program to sort an array in ascending order.
First for loop with run for 2 iterations
Iteration 1 on 1st for loop:
i = 0
j = 0
if(arr[0] > arr[0]) => False, so No Swap
j = 1
if(arr[0] > arr[1]) => True, so swap
After swap, a[2] = {1, 2}
Iteration 2 on 1st for loop:
i = 1
j = 1
if(arr[1] > arr[1]) => False, so no swap
Final result: a[2] = {1, 2}
Just to summarize, second for loop is used so that we can compare the previous array elements with all of the array elements following the previous one and swap accordingly in order to sort it.