How can you quickly find the number of elements stored in a
a) static array b) dynamic array ?
Answer Posted / jaroosh
a) sizeof(array)/sizeof(element)
b) you cant (well, you can, eg. by using realloc, counting
from 0 up, and checking the result etc. but this is absurd),
its best to keep track somehow how many elements are there
in the array, but the BEST solution is...do NOT use dynamic
arrays at all, use std containers instead like vector.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How are Structure passing and returning implemented by the compiler?
Differentiate between late binding and early binding. What are the advantages of early binding?
What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random
How would you differentiate between a pre and post increment operators while overloading?
What is a null object in c++?
What are c++ variables?
What is the arrow operator in c++?
What is helper in c++?
What is type of 'this' pointer? Explain when it is get created?
How does a copy constructor differs from an overloaded assignment operator?
Difference between a copy constructor and an assignment operator.
Can you explicitly call a destructor on a local variable?
Difference between overloaded functions and overridden functions
What is data types c++?
What is a constructor and how is it called?