answersLogoWhite

0


Best Answer

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];

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

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;

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

by using malloc functoin

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you define variable size array in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};


Define pointer in C?

Pointer is a variable, A variable that stores the address of another variable. Size of a pointer is 2 bytes.


Is an array is a collection of characters that can be fixed or variable?

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.


Is the array size is fixed after it is created?

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).


How do you find the minimum value of an array in c language?

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 }


How do you convert char array into unsigned char array in c?

You can't convert the data type of any variable.


C program to copy one matrix to another matrix?

#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; }


Can you give an example of array using character variable in c program?

the example of array over charcter variables is char ["string"]


What is the base address of an array in c program?

the address of variable (pointer) that contains array


How do you swap two adjecent no in array in c?

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];


What is the maximum size of array in c?

Platform-dependent.


What is the difference between subscript and subscripted variable in c plus plus?

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=&amp;i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).