हिंदी माध्यम नोट्स
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();
}
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
2 weeks ago
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
2 weeks ago
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
2 weeks ago
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
2 weeks ago
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
2 weeks ago
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…
2 weeks ago