answersLogoWhite

0


Best Answer

For any type T, the type T[n] instantiates an array of n elements of type T, where n is a constant expression.

int a[100]; // a fixed-length array of 100 integers (allocated in static memory)

void f (const int n) {

int b[n]; // a fixed-length array of n integers (allocated on the stack)

// ...

}

If the number of Ts in an array could change at runtime, we can allocate memory on the heap instead:

void g (int n) {

int* ptr = malloc (n * sizeof(int)); // allocate n integers on the heap

ptr[0] = 42; // access memory using suffix notation

// ...

n *= 2; // double the size of the array

ptr = realloc (ptr, n * sizeof (int)); // reallocate (allocation may move to new memory)

assert (nptr[0]==42); // assert that existing values are retained even after a reallocation

// ...

free (ptr); // don't forget to release memory when it is no longer required!

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What construct can you use to define an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Define social construct?

define social constuction define social constuction


What object in c plus plus?

An object is an instance of a class. A class is a user-defined data type from which we can instantiate objects of that class. We often use the terms object and variable interchangeably, however the term variable specifically refers to a named object (objects instantiated at compile time), as opposed to anonymous objects (instantiated at runtime). Built-in data types such as int, double and pointer types are not classes, thus instances of these types are simply known as variables. Built-in types are also part of the language (hence they are built-in) thus we don't need to include a header or a type definition in order to use them; they are immediately available. But to use an object we must first define its class or include the appropriate header that defines the class.


You can use a variable to declare an array's size true or false?

True and false in the same time, because even so you can declare array size using notation for variables you have use constwhich makes your variable basically a constant:const int arraySize = 10;In Java, you can use any expression to define the array size, when you create the array. Once you create an Array object, however, you can't redimension it - but you can create a new Array object and destroy the old one.


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


Define the declare statement for multi-dimension array?

<storage_class> <type> <identifer> '[ '<number1> ']' '[ '<number2> ']' ... ';'

Related questions

Are construct and array equivalent in c?

No.


Define social construct?

define social constuction define social constuction


What advantage does the Java ArrayList class have over the Arrays class?

The biggest advantage of an ArrayList is that it can expand in size to fit more data. So, if you don't know how many data values you are going to have, you can construct an ArrayList. Whenever you use the add() method, the object will be added to the ArrayList, regardless of the current size. An Array does not have this advantage. When you construct an Array of size n, the array will always be that size.


What object in c plus plus?

An object is an instance of a class. A class is a user-defined data type from which we can instantiate objects of that class. We often use the terms object and variable interchangeably, however the term variable specifically refers to a named object (objects instantiated at compile time), as opposed to anonymous objects (instantiated at runtime). Built-in data types such as int, double and pointer types are not classes, thus instances of these types are simply known as variables. Built-in types are also part of the language (hence they are built-in) thus we don't need to include a header or a type definition in order to use them; they are immediately available. But to use an object we must first define its class or include the appropriate header that defines the class.


You can use a variable to declare an array's size true or false?

True and false in the same time, because even so you can declare array size using notation for variables you have use constwhich makes your variable basically a constant:const int arraySize = 10;In Java, you can use any expression to define the array size, when you create the array. Once you create an Array object, however, you can't redimension it - but you can create a new Array object and destroy the old one.


Define the word fabricate?

(v.) - to make or construct; to lie or deceive


What are the demensions of an array?

The numbers that define its size:int x[12][24];


Define an array and describe its purpose?

An array refers to storing data on multiple devices. An example of this would be to be able to type in six things, call them an array, and not need an identifier for each one.


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


How does an array differ from a array?

'a array' is substandard, if you use it, you might be frowned upon.


An instrument use to construct a straight line?

an instrument use to construct straight line?


Define the declare statement for multi-dimension array?

<storage_class> <type> <identifer> '[ '<number1> ']' '[ '<number2> ']' ... ';'