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


Please Help Members By Posting Answers For Below Questions

What is atoi in c++?

805


What do you mean by funtion prototype?

798


What are function prototypes?

964


What are the operators in c++?

850


How does c++ structure differ from c++ class?

820


What is setw manipulator in c++?

799


Can I learn c++ without knowing c?

794


what are the iterator and generic algorithms.

1891


What do you mean by vtable and vptr in c++?

808


Why do you use the namespace feature?

859


What are separators in c++?

819


Define friend function.

774


How we can differentiate between a pre and post increment operators during overloading?

832


How is data hiding achieved in c++?

777


What is a class template in c++?

770