C语言问题
一个小程序,大家帮忙看一下,本程序是完成极坐标到直角坐标的转换,而且输入
为极径和以度数为单位的极角,程序如下:
#include<stdio.h>
#include<math.h>
#define pi 3.1415926
void convert(float,float,float *,float *);
int main(void)
{
float A,r,*X,*Y;
printf("Enter the A and r:");
while(scanf("%f %f",&A,&r)==2)
{
convert(A,r,X,Y);
printf("%f\t%f\n",*X,*Y);
printf("Enter the A and r:");
}
return 0;
}
void convert(float A,float r,float * x,float * y)
{
*x=r*cos(A/180*pi);
*y=r*sin(A/180*pi);
}
本程序在TC下调试,出错为:
Warnning:possible use of "X" before definition in function main;
Warnning:possible use of "Y" before definition in function main;
Warnning:possible use of "X" before definition in function main;
Warnning:possible use of "Y" before definition in function main;
将两个指针改为普通的float 变量,函数传递用convert(A,r,&X,&Y),则不出错.
我想是不是定义指针的时候,只为指针变量赋初值,而对指针所指的量则不管,
那么为什么程序可以运行,并且结果正确。那么这样做有没有坏处,有什么坏处
呢?
谢谢!
为极径和以度数为单位的极角,程序如下:
#include<stdio.h>
#include<math.h>
#define pi 3.1415926
void convert(float,float,float *,float *);
int main(void)
{
float A,r,*X,*Y;
printf("Enter the A and r:");
while(scanf("%f %f",&A,&r)==2)
{
convert(A,r,X,Y);
printf("%f\t%f\n",*X,*Y);
printf("Enter the A and r:");
}
return 0;
}
void convert(float A,float r,float * x,float * y)
{
*x=r*cos(A/180*pi);
*y=r*sin(A/180*pi);
}
本程序在TC下调试,出错为:
Warnning:possible use of "X" before definition in function main;
Warnning:possible use of "Y" before definition in function main;
Warnning:possible use of "X" before definition in function main;
Warnning:possible use of "Y" before definition in function main;
将两个指针改为普通的float 变量,函数传递用convert(A,r,&X,&Y),则不出错.
我想是不是定义指针的时候,只为指针变量赋初值,而对指针所指的量则不管,
那么为什么程序可以运行,并且结果正确。那么这样做有没有坏处,有什么坏处
呢?
谢谢!
...全文
相关推荐
《你必须知道的495个C语言问题》
"《你必须知道的495个C语言问题》是针对C语言学习者和使用者的一本问答式参考书,涵盖了C语言中声明、初始化、数组、指针、字符串、内存分配、库函数、C预处理器等多个方面的问题。书中通过495个经典问
【C语言】迷宫问题
建立两个栈,使得打印的顺序是正确的怎么找路径,标记已经走过的坐标栈的应用递归回溯算法!
C语言常见面试问题及答案总结
"C语言常见面试问题及答案总结"在C语言面试中,了解基础概念、语法特性和数据结构是至关重要的。以下是对标题和描述中提及的一些知识点的详细解释:1. 关键字`static`的作用: - 函
旅行商问题 C语言解法
源代码.txt"可能包含了解决旅行商问题的C语言源代码,供用户学习和分析。
C语言图的着色问题回溯法
**C语言**:C语言是一种强大的、低级的编程语言,适合编写系统软件和高性能的应用程序。在这里,C语言被用来实现图的着色问题的算法。


