函数没有声明编译通过了
A. 定义的函数必须要声明吗为什么我没声明也成功了
你的主函数也没有函数返回类型 又没有声明函数 绝对不会成功 主函数改为void main 然后su(int x) 函数也没有返回类型 不可能正确 比如你写成void su(int x) 在主函数之前 在写上void su(int x);这句表示声明一下 才行
B. c语言,为什么我写的的这个函数没有声明,我也能调用呢
这个未声明只是警告,是一种提醒,有些时候不会影响编译,应该尽量可能避免。
以上代码把第11行的内容复制在第1行、第2行之间,末尾再加个分号(;),就可以了,这就是函数的声明。
C. C语言 函数调用 如果没进行声明会怎么样
1、由于程序是顺序执行,如果没有提前声明,程序会找不到函数,于是报错。
2、声明的主要作用是告诉程序我下面要用到这个函数,程序会去找这个函数的定义,然后调用。
3、也可以把nt max(int x,int y)放到main函数之前,就不用写声明了。
D. 编译已通过,为什么无法找到函数定义
你把大括号的位置放错了,sushu函数被定义在了main函数里面,但是按照C语言的规定,函数不允许嵌套定义,所以你的sushu相当于没有定义(不知为何你的编译器没有报错说不允许在函数内定义函数)。解决方法是把你最后面多出来的大括号移到main函数最后面。
E. 请问C语言中我的主调函数之前没有写函数声明 为什么还能跑通
在C语言中,函数声明只是推荐,而不是强制。
当没有函数声明的时候,编译器没办法对函数的参数个数和类型做检查,于是带来风险,但并不是找不到。
你看下你编译的时候,针对没有声明的函数,应该会有一个warning的。代表编译器检查到了这个问题,但是并不是致命的。所以只是warning, 而不是error。
F. 没有声明函数也可以通过编译
如果该函数声明的修饰符为public类型的,在main中当然可以直接调用了。public不受调用限制
G. c语言这段代码为什么fun函数没有声明,却还是可以正常运行
我真的可想知道就这代码你原封不动地搬到编译器里能通过运行?让人家回答你得先给个整的代码啊.
H. c 里的函数可否不声明 直接在main()后面使用
函数未先声明,直接在main中使用,在Turbo C 2.0,Borland C++编译是可以通过的,不过这样不是良好的编程习惯,建议:1. 将函数移到main之前;2. 在main之前声明,在main之后再为函数代码。对于较大的代码,函数多,相互之间存在各种引用,为了便于阅读、管理,减少错误,强烈建议采用第2种方式,这是一种良好的编程习惯。而且现在很多编译器对于函数未先声明,直接使用会给出警告或错误。
I. c语言规定函数使用前必须先声明或定义,那为什么我的max()函数在使用前不定义和声明都能编译成功
我用的code::blocks是必须先声明再调用的,但是高级语言编译器会做优化,它会先将声明和定义的东西执行,再执行代码,所以写Java和C#的时候是不需要声明在调用之前的
J. 函数已经声明过了,但是编译的时候还是说没有声明
#include <iostream>
#include <iomanip>
#include "io.h"
void Calcluate(int month_index, double interest_ratio, double monthly_pay, double bal);
int main()
{
double monthly_payment, interest_rate, years;
int ration_in_month;
//Get the monthly payment.
string prompt = "Please enter the monthly payment: ";
monthly_payment = GetParam(prompt, 1.0, 100000.0);
//Get the interest rate.
prompt = "Please enter the interest rate: ";
interest_rate = GetParam(prompt, 0, 1);
//Get the ration of the loan.
prompt = "Please enter the ration of the loan, in years: ";
do {
years = GetParam(prompt, 1, 100);
}while (10 * years - 10 * (int)years > 0);
ration_in_month = 12 * years;
//Print the header of the output table.
PrintHeader ();
//Calculate the loans.
Calcluate(ration_in_month, interest_rate, monthly_payment, 0);//单词拼写错误改过后就没有了
return 0;
}
void Calcluate(int month_index, double interest_ratio, double monthly_pay, double bal)
{
double interests, prin;
do{
bal = (monthly_pay + bal) / (1 + interest_ratio / 12);
interests = bal * interest_ratio / 12;
prin = monthly_pay - interests;
//Print the table.
PrintMonthlyData (month_index, prin, interests, bal);
}while (month_index-- > 1);
}