How can you quickly find the number of elements stored in a
a) static array b) dynamic array ?

Answer Posted / santhosh kumar sahukari

1.for static array we can find the no.of elements of its by using sizeof() operator and data type of that array.
2.we can find the no.of elements by its subscript in static array.
eg: int arr[10]
we can use sizeof(arr) to find the no.of elements it v l print 20,then we can divide it by 2 as size of int is 2.
2.subscript tells us it has 10 elements.

for dynamic array we cant use sizeof() operator.
we cant say dat how many elements it will have..it will be decided at runtime only.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain explicit container.

827


How is data hiding achieved in c++?

757


How the virtual functions maintain the call up?

801


What are the differences between new and malloc?

803


Explain "const" reference arguments in function?

786






In the derived class, which data member of the base class are visible?

846


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

2193


What is virtual base class?

749


What is difference between class and structure in c++?

840


What is an iterator?

898


Will the following program execute?

779


Do you know about C++ 11 standard?

838


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

847


Why do we use classes in c++?

788


What are structures and unions?

766