answersLogoWhite

0

Can array be initialized if they are static?

Updated: 8/18/2019
User Avatar

Wiki User

13y ago

Best Answer

Yes.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can array be initialized if they are static?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can a PHP static be initialized?

PHP static can only be initialized using a literal or constant. You can not use an expression. You can initialize it to an integer but you may not to another variable.


What happen when static data field is initialised in a non static constructor?

It got initialized as you instructed.


Which variable is initialized once when program is compiled?

global and static


How the array has to be declared and initialized?

An example might help int myarray [] = {2,0,1,3,1,1,2,9};


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


Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


Static method can use only static variable why?

A static method is a method that is a class method and is not attached to the object of that class. So if we use a non static variable of the class, it would most probably not have been initialized because no object could have been created for the class. Hence it would throw a null pointer exception. To avoid such an ambiguity, there is a restriction that static methods can use only static variables. This is to ensure that class methods can access only class variables both of which would get initialized simultaneously.


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


Can static variables be changed?

No, a static variable means that there is only one copy of that variable, and it is shared by all members of the class, or by all callers of a function.A variable that is read-only would be marked as const or final (depending on language).


What is the difference between queues and circular queues?

A queue can use a dynamic array, or a linked list, but if using static memory, the queue becomes a circular queue because the underlaying data structure is a static circular array. This means the ends of the array are attached.


What is static array and dynamic array in visual basic?

Generally speaking, a static array is a fixed-length array while a dynamic array is a variable-length array. However, we prefer the terms fixed-length and variable-length because static objects are objects that are allocated in static memory at compile time, which means they have a fixed offset address (the offset remains the same for each execution and will not change at runtime). Dynamic objects, on the other hand, are allocated and destroyed at runtime, which means they have dynamic addresses; each time the object is instantiated we cannot guarantee it resides at the same address. To put it another way, all static arrays must be fixed-length arrays, but not all fixed-length arrays must be static arrays. We can allocate a fixed-length array in static memory (in which case it is also a static array), but we can also allocate a fixed-length array on the call stack or on the heap, in which case we can potentially create more than one instance of that array, each with its own unique address. Consider a recursive function that instantiates a local (non-static) fixed-length array: each instance of that function would instantiate a new instance of that array, each with its own unique address. Similarly with multi-threaded applications: each thread has its own call stack, thus we could potentially have multiple threads invoking the same function and thus instantiating multiple instances of the same array in different call stacks, each with its own unique address. And if we allocate a fixed-length array on the heap, we have no guarantee where that array will be allocated. So whenever we speak of static or dynamic allocations, remember that we are specifically referring to the address (or at least the offset address). Dynamic addresses can change at runtime, static addresses cannot. Although the physical address of a static object can change between executions, its offset address (relative to the start of the static data segment) can never change -- not without recompiling the executable.


What static array and dynamic array in visual basic?

Generally speaking, a static array is a fixed-length array while a dynamic array is a variable-length array. However, we prefer the terms fixed-length and variable-length because static objects are objects that are allocated in static memory at compile time, which means they have a fixed offset address (the offset remains the same for each execution and will not change at runtime). Dynamic objects, on the other hand, are allocated and destroyed at runtime, which means they have dynamic addresses; each time the object is instantiated we cannot guarantee it resides at the same address. To put it another way, all static arrays must be fixed-length arrays, but not all fixed-length arrays must be static arrays. We can allocate a fixed-length array in static memory (in which case it is also a static array), but we can also allocate a fixed-length array on the call stack or on the heap, in which case we can potentially create more than one instance of that array, each with its own unique address. Consider a recursive function that instantiates a local (non-static) fixed-length array: each instance of that function would instantiate a new instance of that array, each with its own unique address. Similarly with multi-threaded applications: each thread has its own call stack, thus we could potentially have multiple threads invoking the same function and thus instantiating multiple instances of the same array in different call stacks, each with its own unique address. And if we allocate a fixed-length array on the heap, we have no guarantee where that array will be allocated. So whenever we speak of static or dynamic allocations, remember that we are specifically referring to the address (or at least the offset address). Dynamic addresses can change at runtime, static addresses cannot. Although the physical address of a static object can change between executions, its offset address (relative to the start of the static data segment) can never change -- not without recompiling the executable.