Read in Hindi
Read in English

Note: if you don't know how to run the program then click here to read my last post or Click on tab above "Run Program here" to run your program online.

Today we will understand the program we have seen in last post. I am writing that program again here below.
#include <stdio.h>
int main() {

printf("Namaskar");

scanf("%s");
return 0;
}

You have seen that running this program prints Namaskar on the screen. Today we will understand each line of this program and know some important things about the program.

See 3rd line carefully It have printf("Namaskar");. In C printf is a function, whatever we write inside this function inside " ", gets printed on the screen. You can try to change Namaskar to something else on that program then run it to see the difference.

We will understand other lines of program later. For now lets assume top 2 lines and bottom 3 lines is necessary in every program.

Some important points about this program.


1. Each C program starts running from then point where main() { is written. As program runs, it reads every line of program after main() { and executes it till it finds }. We will see later what happens on last 2 lines.
2. printf is a function or method (here we will use function), Each function can take some input which is written inside ().
3. semicolon(;) is necessary after function call. It tells program that statement is finished so that it can read and execute next statement.
#include <stdio.h>
int main() {

printf("Namaskar")

scanf("%s");
return 0;
}

If you compile program given above, it will give the following errors.
In function `int main()':
error: expected `;' before "scanf"
Execution terminated
It means before scanf ; should be there as said above. If you see program, ; have been omitted after printf function call. It will compile successfully after you correct it.

Remember that before running program, you have to compile it. If you have modified program, you have to compile it again then run.

In next topic we will read about variables and learn some program which can do some calculation as change Celsius to Fahrenheit, calculate interest, etc.
You can share this to Facebook, twitter etc using links given below.

नोट: अगर आपको C/C++ computer program चलाना नहीं आता हो तो मेरी पिछली पोस्ट पढ़े या फिर ऊपर "Run Program here" पर click करके सीधे अपना C/C++ program Run कर सकते हैं.

आज Hindi के इस C/C++ programming language tutorial को आगे बढ़ाते हुए पिछले वाले program को समझेंगे. एक बार फिर से नीचे वह program लिख रहा हूँ.
#include <stdio.h>
int main() {
   printf("Namaskar");
   scanf("%s");
   return 0;
}
आप देख ही चुके हैं की इस C/C++ program को चलाने से screen पर Namaskar लिखा हुआ आता है. आज हम इस program की एक line ही समझेंगे और कुछ महत्त्वपूर्ण बाते जानेंगे.

तीसरी line को ध्यान से देखिये इसमें printf("Namaskar"); लिखा हुआ है. C में printf एक function होता है इसके अन्दर हम जो भी " " के बीच में लिखते हैं वह screen पर लिखा हुआ आ जाता है. अब आप उस line में Namaskar की जगह कुछ और लिखकर program चलाने का प्रयास करें और output देखें.

इस program की अन्य lines को बाद में समझेंगे. अभी ये मान लीजिये की हर program ऊपर वाली 2 line और नीचे वाली 3 line लिखना है, कुछ दिनों तक हम सिर्फ printf वाली line में ही changes करके देखेंगे.

इस program के विषय में कुछ महत्त्वपूर्ण points


1.C का हर program वहां से run होना शुरू होता है जहाँ main() { लिखा होता है. program run होते ही main() { के बाद हर एक line को पढता है और उसे run (execute ) करता है और } का चिन्ह मिलते ही program समाप्त हो जाता है. यहाँ हम बाद में जानेंगे की बाद वाली 2 line execute होने पर क्या होता है.
2.printf एक function या method है (हम यहाँ function नाम use करेंगे), हर function कुछ न कुछ input लेता है जो की function के बाद छोटे कोष्ठक में लिखा जाता है.
3. function का कोष्ठक बंद होने के बाद semicolon का चिन्ह (;) लगाना आवश्यक है. semicolon का चिन्ह compiler को यह बताता है की यह function पूरा हो गया है ताकि वह अगली command पढ़ सके.
अब नीचे दिया गया program चलायें.
#include <stdio.h>
int main() {
   printf("Namaskar")
   scanf("%s");
   return 0;
}
जब आप इस program को compile करेंगे तो यह कुछ इस तरह की error देगा
In function `int main()':
error: expected `;' before "scanf"
Execution terminated
इसका मतलब यह है की scanf के पहले ; लगा होना चाहिए, जैसा की ऊपर बताया जा चुका है. परन्तु अगर आप ध्यान से देखें तो ऊपर दिए गए program में printf function के बाद ; नहीं लगाया गया. इसे सुधार कर compile करने पर यह compile हो जायेगा.

ध्यान रहे किसी program को रन करने से पहले compile करना आवश्यक होता है. अगर आपने program modify किया है तो उसे फिर से compile करना होगा.

अगले topic में हम variables के बारे में जानेंगे और कुछ program सीखेंगे जो कुछ calculation करे जैसे सेल्सियस को फारेनहाइट में बदलना, interest(ब्याज) निकलना इत्यादि.