answersLogoWhite

0


Best Answer

An example might help

int myarray [] = {2,0,1,3,1,1,2,9};

User Avatar

Wiki User

βˆ™ 10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How the array has to be declared and initialized?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you initialise a two dimentional array?

C provides rectangular multidimensional arrays. In C, a two-dimensional array is really a one-dimensional array, each of whose elements is an array. An array is initialized by a list of initializations in braces; each row of a two-dimensional array is initialized by a corresponding sub-list. Example of two dimensional array initialization: char array_example[2][4] = { {11, 12, 13, 14}, {21, 22, 23, 24} };


Variables declared using the string data type usually are initialized to the empty string?

Yes.


How do you get the middle number for the turbo c using array?

it depends how you have coded your program as: if you initialized your array (a) by loop from 0 then int lb=0,ub=n-1; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]); if you initialized your array (a) by loop from 1 then int lb=1,ub=n; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]);


Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

int *ptr = (int *) calloc(10,sizeof(int));


When is memory allocated when declaring an array in C plus plus?

It depends how the array is declared (fixed size or variable size) and where it is declared (global scope or local scope). If the array is declared in global scope (outside a function) and is fixed size, it will be allocated in static memory. If it is variable size, the pointer is stored in static memory while the array itself is allocated on the heap. The pointer in static memory points to the start address of the array in heap memory. If the array is declared in local scope (inside a function) and is fixed size, it will be allocated on the stack in whichever thread the function was called. If it is variable size, the local pointer is stored on the stack while the array is allocated on the heap. The pointer will fall from scope when the function returns so the array must not be allowed to outlive the function in which the pointer is declared. If the array must outlive the function that allocates the array, the pointer must be declared at a higher scope in the call stack and must be passed by reference to or returned by value from the function that allocates the array. If you provide your own memory manager, however, an array may be allocated wherever the memory manager's memory pool is allocated, be it in static memory, the stack or the heap. A memory manager essentially allocates an array of bytes which you can then utilise as you see fit (the array of bytes will be allocated as per the previous description for arrays in general).

Related questions

Can array be initialized if they are static?

Yes.


How do you initialise a two dimentional array?

C provides rectangular multidimensional arrays. In C, a two-dimensional array is really a one-dimensional array, each of whose elements is an array. An array is initialized by a list of initializations in braces; each row of a two-dimensional array is initialized by a corresponding sub-list. Example of two dimensional array initialization: char array_example[2][4] = { {11, 12, 13, 14}, {21, 22, 23, 24} };


Variables declared using the string data type usually are initialized to the empty string?

Yes.


How do you get the middle number for the turbo c using array?

it depends how you have coded your program as: if you initialized your array (a) by loop from 0 then int lb=0,ub=n-1; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]); if you initialized your array (a) by loop from 1 then int lb=1,ub=n; //n is number of elements in array int mid=(lb+ub)/2; printf("middle number is :%d",a[mid]);


How do you make source codes of of declaring an array of type double values?

It declares an array of type double, it has size of 10, and all elements are initialized to 0;...int myArraySize = 10;double myArray[myArraySize] = {0.0}...


What variable is one that has been declared but has not been initialized or assigned a value?

Uninitialized Page 59 Programming Logic and Design by Tony Gladdis


What variable is one that has been declared but has not been initialized or assigned value?

Uninitialized Page 59 Programming Logic and Design by Tony Gladdis


How is a10-element char array declared?

char myCharArray[10];


Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?

int *ptr = (int *) calloc(10,sizeof(int));


How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.


Write an expression that computes the sum of two variables in java?

int sum = a + b; PS: a and b are int variables that must have been already declared and initialized.


How a variable is declared and initialized during declaration in c?

During declaration, the declaration goes like this: extern <type> <variable-name> or <type> <function-name> (<parameter list>);