अभी तक आपने सीखा कि C++ होता क्या है , C++ को install कैसे करते हैं , उसका syntax क्या होता है , कैसे program लिखते हैं आदि , इस topic में आप सीखेंगे कि लिखे गए program को कैसे run करें।


Turbo C++ compiler का use करके अपना पहला c++ program लिखना शुरू करने के लिए नीचे दिए गए steps का follow करें।

  1. पहला step desktop icon पर click करके Turbo C++ Open करना है या start menu में Turbo C++ icon पर click करना है।

  2. अगला step Turbo C++ start करें compiler पर click करके Turbo C++ compiler start करना है।

  3. अपना program लिखने से पहले, यह check कर लें कि directory compiler के लिए correctly configured की गई है। (Go to Options > Click Directories in the Menu Bar.)

  4. By default, program का नाम noname.cpp है, लेकिन हम C++ source file चाहते हैं। Go to File menu > Click Save as C++ source file का नाम type करें।

  5. अब, आप अपना C++ program code लिखना start कर सकते हैं। इस example के लिए हम 'Hello World' program लिखेंगे।

CopyFullscreenClose FullscreenRun
#include <iostream>
using namespace std;

int main() 
{ 
  cout << "Hello World!"; 
  return 0; 
}
Output :

Hello World!

Program को run करने पर , Output कुछ इस तरह से आएगा।

आइये , देखते हैं कि actually में एक simple "Hello World" program में हमें क्या क्या लिखा है।

  • #include <iostream> : सबसे पहले तो program में header file को include किया गया है , header file एक collection of function या class हो सकती है। C++ language में कई headers files defines है, जिसमें ऐसी information होती है जो या तो आपके program के लिए necessary होती है। इस program के लिए, header <iostream> की जरूरत है। #include keyword का use करके हम किसी header file को include करते हैं।

  • using namespace std; : यह compiler को std namespace का use करने के लिए कहता है। इसका मतलब है कि हम Standard library से objects और variables के लिए नामों का use कर सकते हैं।

  • main() : main() एक function कहा जाता है। इसके अंदर कोई भी code curly bracket {} में execute किया जाएगा। actually इसे आप C++ program का entry point भी का सकते हैं। इस function को use करने के लिए इसका return type int भी define किया गया है , जो बताता है कि main() function किस type की value return करने वाला है।

  • cout : cout एक object है जिसका use insertion operator के साथ मिलकर किया जाता है cout की full form characters output है । << text के साथ इसका use output print करने में किया जाता है।

  • semicolon (;) : C++ Statement semicolon के साथ end होता है , इसलिए आप देख रहे होंगे कि हर line के end में semicolon ; use हो रहा होगा।

  • return 0 : next line return 0; main() function को terminate करता है , हालाँकि , main() function को int के साथ define किया है इसलिए आप कोई भी integer value return कर सकते है।

Another Simple program

CopyFullscreenClose FullscreenRun
#include <iostream>
using namespace std;
int main() {    
  int number;

  cout << "Enter an integer: ";
  cin >> number;

  cout << "You entered " << number;    
  return 0;
}
Output :

Enter an integer: You entered 32766


यह program user को एक number enter करने के लिए कहता है। जब user एक integer में enter करता है, यह cin का use करके variable number में store किया जाता है। फिर इसे cout का use करके screen पर display किया जाता है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers