answersLogoWhite

0

When a significant number of values must be tested to perform an operation, an array is more efficient then "if else" or "switch case" statements. Juge by the following example in C: const char* ConverteIntegerToCStr( unsigned int number, char cstr[] )

{

// predefined array with the first 10000 number string representation

// Note: the ellipsis is not part of the code

static const Array[10000] = { "0", "1", "2", ..., "9998", "9999" };

if (number < 10000)

memcpy( cstr, Array[number], strlen( Array[number] ) ); // very fast

else

itoa( number, cstr ); // standard C function that is much slower

return cstr;

}

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

Why do you use antenna arrays?

To improve the signal :)


How can you do the same thing as the program below but using strings and arrays in C language?

Program below?!


Write a program to read your name and reverse it using arrays?

abdulrahman


How do you create a program in visual basic?

arrays programms in visual basic


Write a program to find intersection between two arrays?

#include&lt;stdio.h&gt;


Dynamically allocated array waste storage and time?

It's actually not true. In order to make a good program which can work with big arrays you have to use dynamic arrays because you can cleam memory used by dymanic arrays any time. For static arrays is not true, memery which was reserved for static arrays will be available for other applications only when you finish working with your application (which is working with static arrays).


Explain the design and application of arrays and how an array simplifies program development?

I need an example of a real-world array


What are the types of array?

There are several different types of arrays, which describe the characteristics of the array. Arrays may be static or dynamic. Static arrays have a predetermined size that will not change over the course of the program's life cycle, while dynamic arrays may be made larger or smaller as necessary while the program runs. Arrays may be one-dimensional or multi-dimensional. An array of just one dimension stores values in a straight line, while a multi-dimensional array represents data that might be rectangular, such as the dots in an image, or even 3 dimensional, such as a multi-layer image, an animation, etc.


Why memory is divided into initialized and uninitialized areas?

The program's data segment. This area of memory is allocated by the linker and is used to store the program's global variables, static variables, static arrays and constants. Constants are always initialised, as are static variables, but global variables and static arrays need not be initialised.


Are arrays in C created on the stack or the heap?

That depends on where you define them. Arrays defined inside functions are declared on the stack (like other variables defined in functions). Arrays defined outside of any function, or using the static keyword inside a function are allocated in the static data area of the program. Other arrays may be allocated using malloc() (or "new" in C++); these are allocated on the heap.


What is multidimentional array?

Arrays having more than one dimension is known as multi-dimensional arrays. Multi-dimensional arrays is also known as arrays-of-arrays.


What is a multidimentional array?

Arrays having more than one dimension is known as multi-dimensional arrays. Multi-dimensional arrays is also known as arrays-of-arrays.