हिंदी माध्यम नोट्स
C++ : Sizeof और Increment Operator and Decrement operators in hindi in c++ language
जब किसी loop को discuss किया है update statement , increament operator को use किया जाता है | अतः increament operator को किसी control variable को आटोमेटिक increament किया जाता है | इसका syntax होता है :-
variable ++ ;
यहा पर
variable : ये variable का नाम होता है जिसकी value को increment किया जाता है |
++ : ये increament operator का keyword होता है |
increament operator को दो तरह से use किया जाता है :-
Postfix increament operator
जब किसी variable की value को एक बार use करने के बाद increament किया जाता है | इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Data :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<“Array Element”<<endl;
for(i=0;i<5;i++)
{
cout<<a[i];
}
getch();
}
इस उदाहरण मे array के element को read और display किया जाता है | इसका आउटपुट होता है :-
Enter Array Data : 12 23 43 23 12
Array Element
12 23 43 23 12
Prefix increament operator
जब किसी variable की value को एक बार use करने के पहले increament किया जाता है | इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Data :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<“Array Element”<<endl;
for(i=0;i<=5;++i)
{
cout<<a[i];
}
getch();
}
इस उदाहरण मे array के element को read और display किया जाता है | सबसे i की value 1 होगी तब array की first element को display किया जाता है | और बाद मे i की value 2 हो जाती है तब array के दूसरी element display किया जाता है | इसका आउटपुट होता है :-
Enter Array Data : 23 21 45 78 6
Array Element
23 21 45 78 6
Decrement operator
जब किसी loop को discuss किया है update statement , Decrement operator को use किया जाता है | अतः Decrement operator को किसी control variable को आटोमेटिक Decrement किया जाता है | इसका syntax होता है :-
variable –;
यहा पर
variable : ये variable का नाम होता है जिसकी value को increament किया जाता है |
— : ये Decrement operatorका keyword होता है |
Decrement operator को दो तरह से use किया जाता है :-
Postfix Decrement operator
जब किसी variable की value को एक बार use करने के बाद Decrement किया जाता है | इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Data :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<“Array Element”<<endl;
for(i=5;i>0;i–)
{
cout<<a[i];
}
getch();
}
इस उदाहरण मे array के element को read किया जाता है और reverse order मे array के element को display किया जाता है | इसके लिए i की value 5 होती है जिससे array fifth element को display किया जाता है | उसके बाद i की value को Decrement कर दिया जाता है | और array की fourth element को display किया जाता है | ये तब चलता है जब तक i की value ‘0’ से बड़ी होती है | इसका आउटपुट होता है :-
Enter Array Data : 12 23 43 23 12
Array Element
12 23 43 23 12
Prefix Decrement operator
जब किसी variable की value को एक बार use करने के पहले Decrement किया जाता है | इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Data :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<“Array Element”<<endl;
for(i=5;i=>0;–i)
{
cout<<a[i];
}
getch();
}
इस उदाहरण मे array के element को read किया जाता है और reverse order मे array के element को display किया जाता है | इसके लिए i की value 4 होती है जिससे array fifth element को display किया जाता है | उसके बाद i की value को Decrement कर दिया जाता है | और array की fourth element को display किया जाता है | ये तब चलता है जब तक i की value ‘0’ से बड़ी या सामान होती है | इसका आउटपुट होता है :-
Enter Array Data : 23 21 45 78 6
Array Element
6 78 45 21 23
size of operator
size of operator का use किसी variable के size को calculate करने के लिए किया जाता है | इसका syntax होता है :
sizeof(variable name );
यहा पर ;
sizeof() : ये sizeof() operator का keyword होता है | जिसका use sizeof() को use करने के लिए किया जाता है |
variable name : इसमें variable का नाम होता है जिसकी size को calculate करना होता है |
उदाहरण के लिए :
sizeof(int); इस statement से integer variable के size को calculate किया जाता है |
sizeof(float); इस statement से float variable के size को calculate किया जाता है |
sizeof(double); इस statement से double variable के size को calculate किया जाता है |
sizeof(char); इस statement से character variable के size को calculate किया जाता है |
इसका उदाहरण होता है :-
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
char c;
double b;
float f;
cout<<“Enter Integer Value :”<<endl;
cin>>a;
cout<<“Enter Character Value :”<<endl;
cin>>c;
cout<<“Enter Flaot Value :”<<endl;
cin>>f;
cout<<“Enter Double Value :”<<endl;
cin>>d;
cout<<“Value of a: “<<a<<“And Size of a :”<<sizeof(a)<<endl;
cout<<“Value of b: “<<b<<“And Size of b :”<<sizeof(b)<<endl;
cout<<“Value of c: “<<c<<“And Size of c :”<<sizeof(c)<<endl;
cout<<“Value of f: “<<d<<“And Size of f :”<<sizeof(f)<<endl;
getch();
}
इसका आउटपुट होगा :
Enter Integer Value : 12
Enter Character Value : w
Enter Float Value : 12.23
Enter Double Value : 12.342456
Value of a: 12 And Size of a : 8
Value of b: 12.342456 And size of b : 32
Value of c: w And Size of c : 2
Value of f: 12.23 And Size of f : 12.23
इस article मे increment और decrement और sizeof() operator को discuss किया है | जिससे प्रोग्रामर को programming skill को बढाया जा सकता है |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…