|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我在写作业时遇到一个问题(偶然发现的)
在DEV C++中如果源代码后缀为.cpp在未包含math.h头文件时是不可以调用pow函数的
但是把后缀改成.c就不会存在这个问题,会有警告[Warning] incompatible implicit declaration of built-in function 'pow'
百度上我搜索过,搜到答案如下:
https://zhidao.baidu.com/question/310052611.html
(截图放不上来抱歉)
但是为什么不写#include <math.h>能不能调用会与文件后缀有关呢?
- #include <stdio.h>
- int main()
- {
- unsigned long long sum=0,temp=1,weight,i;
- for(i=0;i<64;i++)
- {
- temp=pow(2,i);
- sum=sum+temp;
- }
- weight=sum/25000;
- printf("舍罕王应该给予达依尔%llu粒麦子\n如果每25000粒麦子为1kg,那么应该给%llu公斤麦子\n",sum,weight);
- }
复制代码
希望能获得各位老师的解答,万分感谢!
因为gcc 与g++是两个程序,对应.c和.cpp,处理上可能略微不同,math.h是C库中的,cpp中应该是 #include <cmath> 这个和你写代码影响不大的
|
|