Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C++

C++ STL में array::at() फंक्शन


array::at()

निर्दिष्ट सूचकांक पर तत्व का संदर्भ लौटाता है। सीमा जांच करता है - अमान्य सूचकांक पर out_of_range अपवाद फेंकता है।

सिंटैक्स

array_name.at(index);

पैरामीटर

एक्सेस किए जाने वाले तत्व का सूचकांक।

रिटर्न

निर्दिष्ट सूचकांक पर तत्व।

उदाहरण 1: सामान्य उपयोग

#include <bits/stdc++.h>
using namespace std;

int main() {
    array arr = {12.1, 67.3, 45.0, 89.1};
    cout << "The element at index 1 is " << arr.at(1) << endl;
    return 0;
}

आउटपुट

The element at index 1 is 67.3

उदाहरण 2: सीमा से बाहर सूचकांक पर अपवाद

#include <bits/stdc++.h>
using namespace std;

int main() {
    array arr = {12.1, 67.3, 45.0, 89.1};
    cout << "The element at index 8 is " << arr.at(8) << endl;
    return 0;
}

आउटपुट

terminate called after throwing an instance of 'std::out_of_range'
what(): array::at: __n (which is 8) >= _Nm (which is 4)
  1. - C++ STL में atanh() फ़ंक्शन

    atanh() फ़ंक्शन atanh() फ़ंक्शन आर्क हाइपरबोलिक टैंजेंट (व्युत्क्रम हाइपरबोलिक टैंजेंट) लौटाता है। <cmath> हेडर में परिभाषित (C++11 से)। सिंटैक्स atanh(var) पैरामीटर: var - float, double, या long double। मान -1 और 1 के बीच होना चाहिए (अनन्य)। वापसी मान आर्क हाइपरबोलिक टैंजेंट मान (रेडियन मे

  1. - C++ STL में cosh() फ़ंक्शन

    cosh() फ़ंक्शन cosh() फ़ंक्शन दिए गए कोण (रेडियन में) का हाइपरबोलिक कोसाइन लौटाता है। <cmath> हेडर में परिभाषित। सिंटैक्स cosh(var) पैरामीटर: var - float, double, या long double। वापसी मान हाइपरबोलिक कोसाइन मान, सीमा: [1, ∞)। उदाहरण 1: रेडियन इनपुट #include <iostream> #include <cm

  1. - C++ STL में sinh() फ़ंक्शन

    sinh() फ़ंक्शन sinh() फ़ंक्शन दिए गए कोण (रेडियन में) का हाइपरबोलिक साइन लौटाता है। <cmath> हेडर में परिभाषित। सिंटैक्स sinh(var) पैरामीटर: var - float, double, या long double। वापसी मान हाइपरबोलिक साइन मान, सीमा: (-∞, ∞)। उदाहरण 1: रेडियन इनपुट #include <iostream> #include <cmath