Learn how to use the puts() function to display strings in C programming.
To write a C/C++ program that demonstrates the use of the puts() function to display strings on the screen.
In C programming, puts() is a built-in function used to display a string on the screen. It stands for "put string". The puts() function is part of the stdio.h library. It automatically adds a newline character (\n) at the end of the string, so you don't need to include it yourself.
The puts() function is simpler than printf() because it only displays strings. It takes a single argument:
puts() automatically adds a newline after the string. This is different from printf() where you need to add \n manually.
name.puts() statement automatically adds a newline after the string.Run the program:
Expected Output:
| Feature | printf() |
puts() |
|---|---|---|
| Purpose | Display formatted output | Display only strings |
| Format Specifiers | Supports %d, %f, %s, etc. |
Does NOT support format specifiers |
| Newline | Requires \n manually |
Adds \n automatically |
| Arguments | Multiple arguments possible | Only one argument (string) |
| Header File | stdio.h |
stdio.h |
| Example | printf("Age: %d", age); |
puts("Hello"); |
puts() function is used to display strings on the screen.puts() is simpler than printf() for displaying strings.puts() does not support format specifiers like %d or %f.puts() with string literals or string variables.
You have successfully written a C program that demonstrates the use of the puts() function. You have learned how puts() differs from printf() and when to use each function.
puts() automatically adds a newline, while printf() does not. Use printf() when you need formatted output, and puts() when you only need to display a simple string.
fputs() to write strings to files, but puts() is specifically for displaying output on the screen.
ایک C/C++ پروگرام لکھنا جو اسکرین پر سٹرنگز ظاہر کرنے کے لیے puts() فنکشن کا استعمال دکھاتا ہے۔
C پروگرامنگ میں، puts() ایک بلٹ ان فنکشن ہے جو اسکرین پر سٹرنگ ظاہر کرنے کے لیے استعمال ہوتا ہے۔ یہ "put string" کا مخفف ہے۔ puts() فنکشن stdio.h لائبریری کا حصہ ہے۔ یہ خود بخود سٹرنگ کے آخر میں ایک نئی لائن (\n) شامل کرتا ہے، لہذا آپ کو اسے خود شامل کرنے کی ضرورت نہیں ہے۔
puts() فنکشن printf() سے آسان ہے کیونکہ یہ صرف سٹرنگز ظاہر کرتا ہے۔ یہ ایک ہی دلیل لیتا ہے:
puts() خود بخود سٹرنگ کے بعد نئی لائن شامل کرتا ہے۔ یہ printf() سے مختلف ہے جہاں آپ کو \n دستی طور پر شامل کرنا پڑتا ہے۔
name کی ویلیو ظاہر کرتا ہے۔puts() بیان خود بخود سٹرنگ کے بعد نئی لائن شامل کرتا ہے۔پروگرام چلائیں:
متوقع آؤٹ پٹ:
| خصوصیت | printf() |
puts() |
|---|---|---|
| مقصد | فارمیٹ شدہ آؤٹ پٹ ظاہر کرنا | صرف سٹرنگز ظاہر کرنا |
| فارمیٹ اسپیسیفائر | %d، %f، %s وغیرہ کو سپورٹ کرتا ہے |
فارمیٹ اسپیسیفائر کو سپورٹ نہیں کرتا |
| نئی لائن | \n دستی طور پر درکار ہے |
خود بخود \n شامل کرتا ہے |
| دلائل | متعدد دلائل ممکن ہیں | صرف ایک دلیل (سٹرنگ) |
| ہیڈر فائل | stdio.h |
stdio.h |
| مثال | printf("Age: %d", age); |
puts("Hello"); |
puts() فنکشن اسکرین پر سٹرنگز ظاہر کرنے کے لیے استعمال ہوتا ہے۔puts() سٹرنگز ظاہر کرنے کے لیے printf() سے آسان ہے۔puts() %d یا %f جیسے فارمیٹ اسپیسیفائر کو سپورٹ نہیں کرتا۔puts() کو سٹرنگ لٹرلز یا سٹرنگ متغیرات کے ساتھ استعمال کر سکتے ہیں۔
آپ نے کامیابی سے ایک C پروگرام لکھا ہے جو puts() فنکشن کا استعمال دکھاتا ہے۔ آپ نے سیکھ لیا ہے کہ puts() printf() سے کیسے مختلف ہے اور ہر فنکشن کو کب استعمال کرنا چاہیے۔
puts() خود بخود نئی لائن شامل کرتا ہے، جبکہ printf() نہیں کرتا۔ جب آپ کو فارمیٹ شدہ آؤٹ پٹ کی ضرورت ہو تو printf() استعمال کریں، اور جب آپ کو صرف ایک سادہ سٹرنگ ظاہر کرنی ہو تو puts() استعمال کریں۔
fputs() استعمال کر سکتے ہیں، لیکن puts() خاص طور پر اسکرین پر آؤٹ پٹ ظاہر کرنے کے لیے ہے۔