Array is the set of multiple values while variable is used to store a single value at a time.
Arrays have subscript while variable doesn't have a subscript.
Syntax of declaring array and variable is different.
For variable:
data_type list of variables;
For array:
Data_type variable1[size], variablen[size];
Not possible, use pointers instead, eg:
typedef struct MyIntArr {
. int *ptr;
. size_t size;
} MyIntArr;
#define EmptyMyIntArr {NULL, 0}
int *AccessMyIntArr (MyIntArr *arr, size_t index)
{
. if (index>=arr.size) {
. . size_t newsize= index+1;
. . int *newptr= NULL;
. . if (newsize < arr->size * 2) newsize= arr->size * 2;
. . newptr= realloc (arr->ptr, newsize);
. . if (newptr==NULL) exit (33);
. . arr->ptr= newptr;
. . arr->size= newsize;
. }
. return arr->ptr + index;
}
MyIntArr a = EmptyMyIntArr;
*AccessMyIntArr (&a, 72) = 100;
*AccessMyIntArr (&a, 100) = *AccessMyIntArr (&a, 72) + 1;
by using malloc functoin
Generally, a array is fixed in size. With some libraries, however, they are extensible, either by reallocation/copying strategies (C/C++/STL), or by linking/referencing strategies (JAVA).
Your best bet would probably be to iterate through the array using a for loop and compare each value to the current low and high values (which you would store in a local variable) for example: for each element in array { if current is less than lowest_value lowest_value = current else if current is greater than highest_value highest_value = current }
You can't convert the data type of any variable.
#include main() { int array[100], minimum, size, c, location = 1; printf("Enter the number of elements in array\n"); scanf("%d",&size); printf("Enter %d integers\n", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is present at location number %d and it's value is %d.\n", location, minimum); return 0; }
the example of array over charcter variables is char ["string"]
type variable {[optional array size]} {= optional initializer};
Pointer is a variable, A variable that stores the address of another variable. Size of a pointer is 2 bytes.
No. An array is a collection of objects of any type, such as doubles, not just characters. You can even have arrays of arrays, or arrays of structs. In C, the size of an array is fixed, but it is possible to write code that will allow you to manually make it variable in size.
Generally, a array is fixed in size. With some libraries, however, they are extensible, either by reallocation/copying strategies (C/C++/STL), or by linking/referencing strategies (JAVA).
Your best bet would probably be to iterate through the array using a for loop and compare each value to the current low and high values (which you would store in a local variable) for example: for each element in array { if current is less than lowest_value lowest_value = current else if current is greater than highest_value highest_value = current }
You can't convert the data type of any variable.
#include main() { int array[100], minimum, size, c, location = 1; printf("Enter the number of elements in array\n"); scanf("%d",&size); printf("Enter %d integers\n", size); for ( c = 0 ; c < size ; c++ ) scanf("%d", &array[c]); minimum = array[0]; for ( c = 1 ; c < size ; c++ ) { if ( array[c] < minimum ) { minimum = array[c]; location = c+1; } } printf("Minimum element is present at location number %d and it's value is %d.\n", location, minimum); return 0; }
the example of array over charcter variables is char ["string"]
the address of variable (pointer) that contains array
Option 1) Use a temporary variable: int x = array[i]; array[i] = array[i+1]; array[i+1] = x; Option 2) Use bit operators: array[i] ^= array[i+1] ^= array[i];
Platform-dependent.
Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays. The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants. A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars. Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).