What is the Difference between "vector" and "array"?
Answers were Sorted based on User's Feedback
Answer / vivek
in vector space is not fixed,but in array space is fixed
second vector has memory allocation is dynamic which is
unsuitable at execution time but in array memory allocation
is continuously
array contain same datatype it is not in vector
array has compatibility to use 2d,3d arrayalso
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / sumit arora
In C++,vectors are used for dynamically allocating space
(run time)as per your need,you do not need to hard code for
eg: consider a <vector> v;
for(int i=0;i<=v.size();i++)
cout<<v[i];
and that size can be increased with v.pushback(element)for
eg.
so there is no need to hard code whatever element you
pushed back only that memory is used.
but in array you do only have a fixed size
for(i=0;i<=100;i++)
cin<<a[i];
and if you want to access a[101] positions also it will
show you a garbage value ,bcoz in array there is no bound
checking and memorywize its a compile time allocation not a
dynamic one.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / ...........
difference of vector and array in data structure
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / maninder kaur
what is difference between vector class and array?
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / musaddique
arrat is derived type But vector is user-defined type or
class type
Is This Answer Correct ? | 8 Yes | 13 No |
1)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea += sizeof(int); } return 0; } 2)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea ++; } return 0; } The output of this two programs will be different why?
What is difference between class and function?
What is c++ and its features?
Write about a nested class and mention its use?
What is the difference between an array and a list?
How to demonstrate the use of a variable?
What is c++ iterator?
How do you sort a sort function in c++ to sort in descending order?
What is array give example?
What do you mean by inheritance in c++? Explain its types.
Which software is used to run c++ program?
Where must the declaration of a friend function appear?