Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program. C++ uses 5 storage classes, namely: auto register extern static mutable 1. auto: ========= The auto keyword provides type inference capabilities, using which automatic deduction of the data type of an expression in a programming language can be done. It is the default storage class for all local variables. The auto keyword is applied to all local variables automatically. { auto int y; float y = 3.45; } The above example defines two variables with a same storage class, auto can only be used within functions. 2.regist...
Lists are sequence containers that allow non-contiguous memory allocation. As compared to vector, list has slow traversal, but once a position has been found, insertion and deletion are quick. Normally, when we say a List, we talk about doubly linked list. For implementing a singly linked list, we use forward list. ----------------- #include <iostream> #include <list> #include <iterator> using namespace std; //function for printing the elements in a list void showlist(list <int> g) { list <int> :: iterator it; for(it = g.begin(); it != g.end(); ++it) cout << '\t' << *it; cout << '\n'; } int main() { list <int> gqlist1, gqlist2; for (int i = 0; i < 10; ++i) { gqlist1.push_back(i * 2); gqlist2.push_front(i * 3); } cout << "\nList 1 (gqlist1) is : "; showlist(...
Comments
Post a Comment