In FORTRAN, Perl, Python, and Ruby (and possibly many others1), ** is the exponentiation operator. A Perl example follows, because it's my language of choice.

perl -e 'print "2^$_ = ", 2**$_, "\n" for (0..9)'

OUTPUT:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512

 

In C and C++, the * is used both to declare and dereference pointers. It is orthogonal, so ** declares or dereferences a pointer to a pointer. Exponentiation in C and C++ is accomplished with the pow() function in the C math library. For C, use #include <math.h> and for C++, use #include <cmath>.

#include <stdio.h>
int main() {
    int num  = 10;
    int *p1  = #
    int **p2 = &p1;
    printf("The number is %d\n", **p2);
    return 0;
}

OUTPUT:
The number is 10

Thanks to OldMiner and ariels for pointing out that ** as exponentiation didn't first appear in perl and recommending that I show how C and C++ do exponentiation.
Thanks to vruba for telling me ** is also used in Python and Ruby.

1 - If you know of another language that uses ** as exponentiation, /msg me, and I'll add it.

Log in or register to write something here or to contact authors.