हिंदी माध्यम नोट्स
Categories: c++ language in hindi
C++ : Program Header , Function Header , Manipulator , Newline character , C++ Source code Formatting
Newline character , C++ Source code Formatting , C++ : Program Header , Function Header , Manipulator :-
इससे पहले के article मे , comment , function definition और preprocessor को discuss किया था |अब इस article मे c++ प्रोग्राम के बाकि elements को discuss करेगे |
Function Header
जब किसी c++ प्रोग्राम function को run किया जाता है या दुसरे function द्वारा call किया जाता है तब function header इन दोनों functions के बीच interface को define करता है |इसमें function name को define करता है जिसमे function के type और function के नाम को define करता है |इसमें function के flow को भी define करता है |function definition मे () मे function के parameter को pass करते है |argument और parameter लिस्ट call function से calling function मे data के फ्लो को define करता है |
function definition मे main() function मे अलग होता है | main() function किसी प्रोग्राम का start code होता है |जो की complier को प्रोग्राम को start होने का निर्देश देता है |
उदाहरण के लिए :
main() के लिए , int जो की main() function के start मे होता है | वो ये define करता है की function से integer type return होती है |अगर main() function से कोई data return नहीं होता तब इसका type void कहते है |
function का नाम main() क्यों होता है |
जब हम निन्म उदहारण को consider करे तो
#include<iostream>
void main()
{
using namespace std;
using namespace std;
cout<< “Good Morning”;
getch();
}
इस उदाहरण मे , जब code को compile करते है तब प्रोग्राम मे main() function का होना आवश्कता है |लेकिन MAIN () और Main () function तब compiler error message देगा |किसी प्रोग्राम मे , केवल एक main() function की जरुरत होती है |
जब किसी प्रोग्राम को compile किया जाता है , complication main() से start होता है |अगर प्रोग्राम मे , main() function नहीं होता तो प्रोग्राम अधुरा होता है |और compile नहीं होता है |
windows मे dynamic link library को use किया जाता है जिसमे main() function को use नहीं करना होता है |इसका उदाहराण मे किसी रोबोट्स , controller चिप के लिए प्रोग्राम |
Manipulator
cout<< end1;
इस statement को Manipulator कहते है |जो की किसी नए statement के start होने के लिए define कियाजाता है |जब किसी आउटपुट statement मे , end1 को introduce करते है तब couser console screen पर नए line पर shift हो जाता है |endl , cout की तरह iostream header file का पार्ट होती है | इसलिए इसके लिए namespace को use किया जाता है |
cout function से next line मे automatic नहीं जा सकता है |इसे केवल string को print करने के लिए किया जाता है|
उदहारण के लिए :
#include<iostream>
void main()
{
using namespace std;
using namespace std;
cout<< “Good Morning !”;
cout<< “Parth”;
cout << endl;
cout << “It is my First Program.”;
getch();
}
आउटपुट होता है :
Good Morning ! Parth
It is my First Program.
इस उदाहरण मे , Good Morning ! और Parth को एक ही line मे print होता है |और endl से cusor next line मे shift हो जाता है | उसके बाद It is my First Program. को print होता है |
Newline character
c++ मे endl के अलावा एक option होता है नए line मे shift करने के लिए | इसे new line operator (\n) कहते है |ये दो single character से मिलकर बना होता है |जिसे new line operator कहते है |
c++ मे endl के अलावा एक option होता है नए line मे shift करने के लिए | इसे new line operator (\n) कहते है |ये दो single character से मिलकर बना होता है |जिसे new line operator कहते है |
अगर किसी string को display करना होता है तब new line option से कम character को type करना होता है |इसका उदहारण है :-
#include<iostream>
void main()
{
using namespace std;
using namespace std;
cout<< “Good Morning !”;
cout<< “Parth”;
cout << endl;
cout << “It is my First Program.”;
getch();
}
इस उदाहरन मे , endl को use किया गया है |जबकि निन्म उदहारण मे ,
#include<iostream>
void main()
{
using namespace std;
using namespace std;
cout<< “Good Morning !”;
cout<< “Parth \n”;
cout << “It is my First Program.”;
getch();
}
दोनों प्रोग्राम से सामान आउटपुट मिलता है लेकिन कम character को type करना होता है |
C++ Source code Formatting
कुछ language जैसे prascal , fortan ,c language मे एक statement को एक line मे लिखा जाता है | इस सभी language मे , return statement को अलग से लिखना होता है |लेकिन c++ मे , return statement को अलग से लिखना complusy नहीं होता है |return statement को प्रोग्राम के free space मे कही पर भी लिख सकते है |उदाहरण के लिए :-
int main()
{
using
namespace std;
cout<<“good mornging “<<
endl; cout<<
“I am Parth”<<endl; return;
}
उपर लिखा गया code compile सही होगा कोई भी error नहीं आएगी लेकिन इससे समजने मे काफी difficulty होगी |अतः c++ मे ,कुछ rules को फॉलो करना होता है |जिससे code का display अच्छा लगे |और standard पर follow हो |
1.किसी भी syntax मे space नहीं हो सकता है |जैसे
main() ; // right syntax
ma in (); // invalid syntax
2.return statement को code के बीच कम कम लिखना चाहिए |
3.इसके अलावा कई सारे rules होते जो बाद मे discuss करेगे |
Token और whitespace
टोकन एसे element होते है जिसे divide नहीं किया जा सकता है |किसी एक टोकन को दुसरे टोकन से अपके से अलग कर सकते है |इस format को white space कहते है |उदहारण के लिए () , (,) , “” आदि tokens है जिसे white space के साथ use नहीं कर सकते है |
उदाहरण के लिए :
return0; // invalid statement
return (0) ; // valid statement , 0 will be return
return(0); // valid statement , 0 will be return
intmain() ; //invalid statement
int main() ; //valid statement , program start
int main( ) ; //valid statement , program start
int main()
{
using
namespace std;
cout<<“good mornging “<<
endl; cout<<
“I am Parth”<<endl; return;
}
उपर लिखा गया code compile सही होगा कोई भी error नहीं आएगी लेकिन इससे समजने मे काफी difficulty होगी |अतः c++ मे ,कुछ rules को फॉलो करना होता है |जिससे code का display अच्छा लगे |और standard पर follow हो |
1.किसी भी syntax मे space नहीं हो सकता है |जैसे
main() ; // right syntax
ma in (); // invalid syntax
2.return statement को code के बीच कम कम लिखना चाहिए |
3.इसके अलावा कई सारे rules होते जो बाद मे discuss करेगे |
Token और whitespace
टोकन एसे element होते है जिसे divide नहीं किया जा सकता है |किसी एक टोकन को दुसरे टोकन से अपके से अलग कर सकते है |इस format को white space कहते है |उदहारण के लिए () , (,) , “” आदि tokens है जिसे white space के साथ use नहीं कर सकते है |
उदाहरण के लिए :
return0; // invalid statement
return (0) ; // valid statement , 0 will be return
return(0); // valid statement , 0 will be return
intmain() ; //invalid statement
int main() ; //valid statement , program start
int main( ) ; //valid statement , program start
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