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

How a new operator differs from the operator new?

620


What is math h in c++?

602


What are guid? Why does com need guids?

566


What is the fastest c++ compiler?

580


Which compiler does turbo c++ use?

599






How did c++ get its name?

564


What is the error in the code below and how should it be corrected?

300


Why c++ is not a pure oop language?

551


Describe Trees using C++ with an example.

602


What are the storage qualifiers?

659


Is it possible for the objects to read and write themselves?

637


What is #include cstdlib in c++?

652


Explain about Virtual Function in C++?

605


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

588


Can create new c++ operators?

565