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
Should the this pointer can be used in the constructor?
Is c or c++ more useful?
What is name hiding in c++?
Define stacks. Provide an example where they are useful.
Can c++ do everything c can?
What are the four partitions in which c++ compiler divides the ram?
Can you pass a vector to a function?
Do you need a main function in c++?
What is difference between c++ and c ++ 14?
What is dev c++ used for?
What are the new features that iso/ansi c++ has added to original c++ specifications?
Explain how to initialize a const data member.
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
What is the benefit of c++?
What are containers in c++?