Block , block statement, compound statement in c++

Block (ब्लॉक):-  
A block is a compound statement (a group of zero or more statements) that is assumed as a single statement by the compiler. A block is begin with{ and end with}.
एक ब्लॉक एक कंपाउंड स्टेटमेंट(शून्य या अधिक स्टेटमेंट्स का समूह) होता है जिसे कम्पाइलर द्वारा एक सिंगल स्टेटमेंट माना जाता है। किसी ब्लॉक का प्रारंभ { एवं अंत } से होता है।    

Example:-
#include<iostream.h>
#include<conio.h>
int count=0;
class list{
int i;
}
public:
list(){
i=0;
count++;
cout<<"Object Created"<<endl;
}
~list(){
cout<<count<<"Object Destroyed"<<endl;
count--;
}
};
void main(){
list l1;
getch();
//Block1
{
list l2,l3,l4;
}
cout<<"Three Objects of Block1 Destroyed"<<endl<<"Back To main function's block"<<endl;
getch();
cout<<"Object of Main Block will be Destroyed"<<endl;
}

No comments:

Post a Comment