In below program, what would you put in place of “?” to print “TATA”.…
2025
In below program, what would you put in place of “?” to print “TATA”. Obviously, something other than “TATA”.
int main()
{
char arr[] = "TATA and TATA";
printf("%s", ?);
getchar();
return 0;
}
- A.
It is not possible to print TATA without mentioning "TATA" in place of "?"
- B.
The program contains error
- C.
arr+9
- D.
&arr + 8
Attempted by 464 students.
Show answer & explanation
Correct answer: C
The array arr contains the string "TATA and TATA", which is stored in memory as a sequence of characters. The first "TATA" occupies indices 0 to 3, followed by " and ", and then the second "TATA" starts at index 9. To print the second "TATA" without using the string literal, we can use pointer arithmetic. The expression arr+9 gives the address of the character at index 9, which is the start of the second "TATA". When printf is called with arr+9, it prints all characters from that position until it encounters the null terminator (\0). This is a valid and correct way to print "TATA" without writing the string literal.
हिन्दी उत्तर: एरे arr में "TATA and TATA" स्ट्रिंग स्टोर होती है, जिसका पहला "TATA" इंडेक्स 0 से 3 तक होता है, फिर " and " और दूसरा "TATA" इंडेक्स 9 से शुरू होता है। दूसरे "TATA" को स्ट्रिंग लिटरल का उपयोग किए बिना प्रिंट करने के लिए, हम पॉइंटर अरिथमैटिक का उपयोग कर सकते हैं। arr+9 वह एड्रेस देता है जहाँ इंडेक्स 9 पर चर है, जो दूसरे "TATA" की शुरुआत है। जब printf को arr+9 के साथ कॉल किया जाता है, तो यह उस स्थान से शुरू होकर नल टर्मिनेटर (\0) तक सभी वर्ण प्रिंट करता है। यह स्ट्रिंग लिटरल का उपयोग किए बिना "TATA" प्रिंट करने का एक मान्य और सही तरीका है।