GCC कंपाइलर में कुछ बिल्ट-इन फ़ंक्शन्स होते हैं। ये फ़ंक्शन्स नीचे दिए गए हैं।
फ़ंक्शन __builtin_popcount(x)
यह बिल्ट-इन फ़ंक्शन पूर्णांक प्रकार के डेटा में 1s की संख्या गिनने के लिए उपयोग किया जाता है। आइए __builtin_popcount() फ़ंक्शन का एक उदाहरण देखें।
उदाहरण
#include<iostream> using namespace std; int main() { int n = 13; //बाइनरी 1101 है cout << "Count of 1s in binary of "<< n <<" is " << __builtin_popcount(n); return 0; }
आउटपुट
Count of 1s in binary of 13 is 3
फ़ंक्शन __builtin_parity(x)
यह बिल्ट-इन फ़ंक्शन किसी संख्या की समता जांचने के लिए उपयोग किया जाता है। यदि संख्या में विषम समता है, तो यह true लौटाएगा, अन्यथा false लौटाएगा। आइए __builtin_parity() फ़ंक्शन का एक उदाहरण देखें।
उदाहरण
#include<iostream> using namespace std; int main() { int n = 13; //बाइनरी 1101 है cout << "Parity of "<< n <<" is " << __builtin_parity(n); return 0; }
आउटपुट
Parity of 13 is 1
फ़ंक्शन __builtin_clz(x)
यह बिल्ट-इन फ़ंक्शन पूर्णांक के अग्रणी शून्यों को गिनने के लिए उपयोग किया जाता है। clz का अर्थ है Count Leading Zeros। आइए __builtin_clz() फ़ंक्शन का एक उदाहरण देखें।
उदाहरण
#include<iostream> using namespace std; int main() { int n = 13; //बाइनरी 1101 है //0000 0000 0000 0000 0000 0000 0000 1101 (32बिट पूर्णांक ) cout << "Leading zero count of "<< n <<" is " << __builtin_clz(n); return 0; }
आउटपुट
Leading zero count of 13 is 28
फ़ंक्शन __builtin_ctz(x)
यह बिल्ट-इन फ़ंक्शन पूर्णांक के अनुगामी शून्यों को गिनने के लिए उपयोग किया जाता है। ctz का अर्थ है Count Trailing Zeros। आइए __builtin_ctz() फ़ंक्शन का एक उदाहरण देखें।
उदाहरण
#include<iostream> using namespace std; int main() { int n = 12; //बाइनरी 1100 है //0000 0000 0000 0000 0000 0000 0000 1100 (32बिट पूर्णांक ) cout << "Trailing zero count of "<< n <<" is " << __builtin_ctz(n); return 0; }
आउटपुट
Trailing zero count of 12 is 2