Q:

Simple Modular Exponentiation in C++ without overflow? 

I have to create a simple modular exponentiation function that takes input three integers, a, b and c, and performs the task: a^b %c without overflow. 

A:

It is Modular exponentiation.  Assuming unsigned a, b, c and that a * (c - 1) does not overflow:
unsigned int r = 1;
for (unsigned int k = 0; k < b; k++)
    r = r * a % c;

(Note that there is no power operator in C, ^ is for XOR (exclosive OR.)