शुरुआती C/C++ अभ्यास

स्वर गिनें

टेक्स्ट की एक लाइन में स्वर गिनें।

स्वर गिनें क्या है?

कैरेक्टर को वर्गीकृत करने में ट्रैवर्सल, नॉर्मलाइज़ेशन और सदस्यता की जाँच एक साथ आती है।

महत्वपूर्ण बातें

  • Compiler warnings चालू करके सभी ठीक करें।
  • हर value का type और lifetime समझें।
  • Input और array bounds validate करें।

C और C++ code examples

C
कोड चलाएँ →
main.c
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(void) {
    const char *text = "Code Utility"; int count = 0;
    // strchr performs a compact membership check.
    for (; *text; ++text) if (strchr("aeiou", tolower((unsigned char)*text))) ++count;
    printf("vowels=%d\n", count);
}
अपेक्षित output
vowels=5
C++
कोड चलाएँ →
main.cpp
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
int main() {
    std::string text = "Code Utility";
    // count_if counts characters accepted by the predicate.
    auto vowels = std::count_if(text.begin(), text.end(), [](unsigned char c) {
        return std::string("aeiou").find(std::tolower(c)) != std::string::npos;
    });
    std::cout << "vowels=" << vowels << '\n';
}
अपेक्षित output
vowels=5

C और C++ की तुलना

पाँच स्वरों से तुलना करने से पहले हर कैरेक्टर को छोटे अक्षर में बदलें।

C

C छोटे procedural APIs और representation details स्पष्ट करता है।

C++

C++ low-level model रखकर safer library types जोड़ता है।

अभ्यास

दोनों versions चलाकर बदलें और language guarantees की तुलना करें।

  • Invalid और boundary inputs जोड़ें।
  • -Wall -Wextra -Wpedantic से compile करें।
  • Declarations और implementation अलग करें।

चैलेंज से अभ्यास करें

इस पाठ में सीखी बात से एक असली समस्या हल करें। हर चैलेंज ब्राउज़र में चलता है, तुरंत टेस्ट और AI रिव्यू के साथ।

सभी चैलेंज