Posts: 266
Threads: 239
Joined: Apr 2011
what is differnce between itrator and pointer.so please explain this
what is difference between data structre and algorithm.
what is differnce between global variables and static variables and also understand it with the help of examples.
i am waitng your kind response.
Posts: 9,583
Threads: 8,089
Joined: Apr 2011
Iterator
In C++, an iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (at least, the increment (++) and dereference (*) operators). The most obvious form of iterator is a pointer: A pointer can point to elements in an array, and can iterate through them using the increment operator (++). But other forms of iterators exist. For example, each container type (such as a vector) has a specific iterator type designed to iterate through its elements in an efficient way. Notice that while a pointer is a form of iterator, not all iterators have the same functionality a pointer has; to distinguish between the requirements an iterator shall have for a specific algorithm.
Data structure is the technique to store data in memory in specified format (in the form of arrays, link lists, trees etc), while algorithms represent the logic that operates on these data structures, data structure represent the data perspective of the system while the algorithm normally present the middle layer e.g. business logic etc.
Static variables are local in scope to their module in which they are defined, but life is throughout the program. Say for a static variable inside a function cannot be called from outside the function (because it's not in scope) but is alive and exists in memory. On the other hand global variables have to be defined globally, persists (life is) throughout the program, scope is also throughout the program. This means such variables can be accessed from any function, any file of the program.
Example:
int x=50;// A global variable, accessible any where in the program. E.g. in display() function etc
int main() {
static int y=40; //Static variable, accessible only in main() function
system("pause");
}