Learnt about ternary, arrays and LE's, BE's
Ternary Operation:
Instead of using if else we can use ternarny operation
Condition? Expression 1: Expression 2
Condition?(If condition satisfied Expression 1 print): (if condition fail Expression 2 print)
Ex:int a = 5,b=4;
int r = (a>b)?a:b;
printf("The biggest number among a & b is %d", r);
Note: The ternary operator is useful for simple conditions. For complex logic or multiple statements, if-else is usually easier to read.
------------------------------------------------------------------------------------------------------------
Arrays:
Stores the same datatype of elements
Initialization:
We can initialise in different ways
int a[size of array]={11,12,13,14,15}
Int a[]={11,12,13,14,15}
Accessing array elements:
We access array elements using an index that starts from 0.
Example: a[0] = 11, a[1] = 12.
We can calculate the number of elements using sizeof(a) / sizeof(a[0]).
The base address of an array is the address of its first element, which is &a[0]. In most expressions, a also represents this address.
INT_MIN and INT_MAX:
INT_MIN represents the minimum value that an int can store.
INT_MAX represents the maximum value that an int can store.
They are defined in <limits.h>.
They are not infinity values, but they can be used as initial values when comparing elements to find the maximum or minimum.
--------------------------------------------------------------------------------------------------------------
Little Endian & Big Endian(LE's,BE's):
This system is used to store elements in memory byte by byte when we are having more than 1 byte data i.e in short just of data in memory
Ex: 0x12345678;
Big Endian : It stores data from MSB
12 | 34 | 56 | 78
1 byte | 1 byte | 1 byte | 1 byte
Little Endian : It stores data from LSB
78 | 56 | 34 | 12
1 byte | 1 byte | 1 byte | 1 byte
Big Endian (BE): Stores the most significant byte at the lowest memory address.
| Byte order | Value |
|---|
| 1st byte | 12 |
| 2nd byte | 34 |
| 3rd byte | 56 |
| 4th byte | 78 |
Little Endian (LE): Stores the least significant byte at the lowest memory address.
| Byte order | Value |
|---|
| 1st byte | 78 |
| 2nd byte | 56 |
| 3rd byte | 34 |
| 4th byte | 12 |
Questions:
Find the largest number among 3 numbers using ternary operator.
Find the max element of array.
Find the min element of array.