问题描述
#include<stdio.h>
#include<string.h>
#include<math.h>
void main()
{
int i,p;
char y;
char x,a[10]={4,5,6,7,8};
p=strlen(a);
for(i=0;i<p;i++){
y=a[i];
x=(char)y;
printf("%c",x);
}
}
我的尝试:
i无法获得输出,当我这样做时,我得到许多不可读的输出
What I have tried:
i can't get output,when i do the same i get many unreadable output
推荐答案
char x,a[10]={'4','5','6','7','8'};
甚至
char x,a[10]="45678";
为什么我不能得到这个程序的输出?
Why can't I get the output in this program?
你的程序输出不可打印的字符。如果你告诉我们该怎么做这个程序,我们就能解释你的错误。
-----
你的代码没有表现出来你期望的方式,你不明白为什么!
有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。
调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。
调试器中没有魔法,它不知道你应该做什么,它没有发现错误,只是通过向你展示正在发生的事情来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。
要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。
]
[]
[]
[]
调试器仅显示您的代码正在执行的操作,并且您的任务是与应该执行的操作进行比较。
Your program outputs non printable chars. If you tells us what is supposed to do the program, we will be able to explain you what is wrong.
-----
Your code do not behave the way you expect, and you don't understand why !
There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
这篇关于为什么我不能在这个程序中获得输出?这种类型转换是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!