टिपा – सी आणि सी++

सी आणि सी++ या भाषा दोन स्वतंत्र भाषा आहेत. कित्येकदा सी++ शिकणा-यांना आधी सी शिका आणि नंतर सी++ शिका असा चुकीचा सल्ला दिल्या जातो. त्याऐवजी, थेट सी++ शिकणे अधिक श्रेयस्कर आहे. उदाहरणार्थ खालील सी++ आज्ञावलीच्या सारखा कृका (code) सी मध्ये देखभालीच्या दृष्टीने सुगम पद्धतीने लिहीणे जवळ-जवळ अशक्यच आहे -


// factotmpl.cpp -- simple template demo
// Copyright (c) Shailesh S. Khandekar, 2009. Released with GPLv3.
// Compile with:
// g++ -o factotmpl factotmpl.cpp
// Sample output
// $./factotmpl
// 25! = 2076180480

#include <iostream>

using namespace std;

template<unsigned int N>
struct factorial {
static const unsigned long value = N*factorial<N-1>::value;
};

template<> struct factorial<0> {
static const unsigned long value = 1;
};

int main(int, char**)
{
cout << "25! = " << factorial<25>::value << endl;

return 0;
}