-5
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int i;
    i = 2;
    printf("%d %d %d\n", i,pow(i,2),pow(i,3));
    return 0;
}

/* I expect the output to be 2,4,8.But the output shown is 2 0 1074790400.Can anyone explain me the reason please..? */

Bathsheba
  • 231,907
  • 34
  • 361
  • 483

1 Answers1

5

The return type of the overload of pow that you're using is double, so the behaviour of your code is undefined due to the invalid printf format specifiers.

Reference: http://en.cppreference.com/w/cpp/numeric/math/pow

Bathsheba
  • 231,907
  • 34
  • 361
  • 483