请解释以下给定代码的输出。对于这两种情况,我都得到了不同的 c 值,即
情况 1:n 的值取自标准输入。情况2:n的值直接写在代码中。链接:http ://www.ideone.com/UjYFQd
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;
int main()
{
int c;
int n;
scanf("%d", &n); //n = 64
c = (log(n) / log(2));
cout << c << endl; //OUTPUT = 5
n = 64;
c = (log(n) / log(2));
cout << c << endl; //OUTPUT = 6
return 0;
}