answersLogoWhite

0

How arrays used in vc plus plus?

Updated: 12/13/2022
User Avatar

Wiki User

9y ago

Best Answer

Arrays are used to store two or more variables of the same type in contiguous memory. Since all elements are of the same type, they are also of the same size (in bytes), thus every element can be accessed as an offset from the start of the array. In an array of n elements, index 0 is the first element and index n-1 is the last element. By multiplying the index by the type size, the compiler can determine the start address of each element, thus permitting constant time, random access to any element within the array, as well as bi-directional traversal of the array.

Arrays provide the most compact method of storing multiple values of the same type. So long as you know the start address of the array (which is obtained by the array name alone) and the number of elements in the array (which must be stored separately), you can access any element in constant time.

C++ supports fixed-length arrays (std::array) and variable-length arrays (std::vector) as well as C-style arrays (both static and dynamic). In most cases you will use std::vector and std::array as they both provide bounds-checking, can be easily passed to functions by value, reference or pointer, and you enlist the compiler to ensure type safety. Both std::vector and std::array encapsulate the array, its type and its size, while std::vector uses a built-in memory manager to minimise reallocation of the array.

With C-style arrays, the onus is entirely upon the programmer to ensure bounds-checking and type safety are adhered to. In particular, passing a C-style array to a function via a pointer should be avoided as the function has no way to determine how many elements are actually in the array, let alone what type of elements were originally placed in the array.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How arrays used in vc plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is vc plus plus plus plus?

7


Do I need syllabus for vc plus plus?

No.


Array in c plus plus must be defined at compil time?

No. Arrays can be defined at runtime, just as they can in C. It's just that it's generally more convenient to use vectors instead of dynamic arrays at runtime, thus arrays are generally used statically, at compile time.


What are the softwares created by using vc plus plus?

Virtually every major application by Microsoft is developed using VC++, including Windows itself.


What is difference between Bac arrays and DNA arrays?

BAC (Bacterial Artificial Chromosome) arrays are a type of DNA arrays. BAC arrays are usually used for a technique called array CGH (Comparative Genomic Hybridisation) which is used to identify gross deletions or amplifications in DNA (which for example is common in cancer). DNA arrays include BAC arrays but also oligo, cDNA, and promoter arrays. Oligo and cDNA arrays are typically used for gene expression analysis (looking to see how heavily expressed each gene is). Oligo arrays can also be used for SNP (single nucleotide polymorphism) analysis. Promoter arrays are used to identify transcription factor binding sites.


What is the Difference between arrays in c and c plus plus?

Nothing whatsoever. They are exactly the same.


Can arrays be used in for loops?

yes


Do you have pointer concept in c plus plus language?

Yes. All string variables are pointers as are other arrays.


How can arrays be used for inter function communication?

The size of a function can be determined from the size of the array. Arrays and functions are both used in computer programming.


Which people used guerrilla tactics in Vietnam?

VC.


Why are matrices used for representation while programming?

Let me correct you: two-dimensional arrays are used in programming to represent matrices. (Matrices are objects of mathematics, arrays are objects of programming.)


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