JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

STATIC EXAMPLE in c++ language , STATIC program source code with explanation in hindi

STATIC program source code with explanation in hindi , STATIC EXAMPLE in c++ language :-
इससे पहले के article मे , c++ language के  कुछ advance उदाहरणों को discuss किया है जो की static data type और static variable और static object के उदाहरन को discuss करेगे |
उदाहरन – 1
इस उदाहरन class को static function और static class  को use किया गया है  |
Explanation
सबसे पहले  static class Example को define किया जाता है |
इसमें  static variable a को define किया  जाता है | इसके बाद function () को declare किया जाता है |
function() मे
class मे define static variable को call किया जाता है |
इसके बाद static variable की value को display किया जाता है |
इसके बाद main() function को डेफिन किया जाता है | जिसमे एक template class example मे से variable a को define किया जाता है  |
उसके बाद  class example के लिए object को define किया जाता है |
इसके बाद object से class function को call किया जाता है | जिसमे ‘8’ को pass किया जाता है |
#include<stdio.h>
#include<conio.h>
class Example {
public :
static int a;
static int function(int c) {
cout << “call of Static member function “;
cout << “\nThe value of c is: ” << c ;
}
};
int Example::a=28;
void main() {
Example obj;
Example::func(8);
cout << “\nThe value of the static data member a is: ” << obj.a;
getch();
}
इसका आउटपुट होगा :
call of Static member function
The value of c  : 28
The value of the static data member a is: 8
उदाहरन -2
इस उदहारण मे , static object को declare किया जाता है |
Explantion
सबसे पहले  class pool को define किया जाता है |
इसमें  normal variable a को define किया  जाता है | इसके बाद function () को declare किया जाता है | जबकि पहले वाले उदाहरन मे static variable को define किया जाता है | अतः इसकी value को कभी भी change किया जा सकता है |
function() मे
class मे define normal variable को call किया जाता है |
इसके बाद normal variable की value को display किया जाता है |
इसके बाद main()function को डेफिन किया जाता है | जिसमे   class pool के लिए  static object को define किया जाता है |
इसके बाद object से class function को call किया जाता है | जिसमे कोई भी function मे pass नहीं  किया जाता है |
source code
#include <iostream>
using namespace std;
class pool {
public :
int function () {
int c = 20;
cout << “The value of c  : ” << c ;
}
};
void main() {
static pool b;
b.function ();
getch();
}
इसका आउटपुट होगा :
The value of c  : 20
उदाहरन -3
इस function मे static variable को define किया जाता है |
Explantion
सबसे पहले  class display को define किया जाता है |
इसमें  दो static variable a और b को define किया  जाता है जिसमे मे से a की value को initail किया जाता है | और b की value को 12 से initial किया जाता है |
function() मे
class मे  दो  normal variable को define किया जाता है |
इसके बाद  दो static variables की value को display किया जाता है |
इसके बाद main()function को डेफिन किया जाता है | जिसमे   class display के लिए  object ‘d’ को define किया जाता है |
इसके बाद object ‘d’ से  function को call किया जाता है | जिसमे कोई भी function मे pass नहीं  किया जाता है | जब इस function को call किया जाता है तब function के variable ‘a’ की value मे यूजर द्वारा value को input किया जाता है | को print किया जाता है |
और इसके बाद static variable जिसे value को initial किया गया है को print किया जाता है |
source code
#include <iostream>
using namespace std;
class display  {
public :
int function () {
static int a;
static int b = 12;
cout<<“enter value : “<<endl;
cin>>a;
cout << ” Static variable a is: ” << a;
cout << “\n Static variable b is: ” << b;
}
};
void main() {
display d;
d.function ();
getch();
}
Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now