相关疑难解决方法(0)

使用printf打印出浮动值

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  int x, *ptr_x;
  float f , *ptr_f;

  ptr_f = &f;
  ptr_x = &x;
  *ptr_x = 5;
  *ptr_f = 1.5; //printf("%d %f\n", f,x);

  printf ("\n\nxd = %d \t xf = %f \n ff = %f \t fd = %d", x,x,f,f);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

ff =%f的输出不是预期的.

xd = 5 xf = 0.000000
ff = 0.000000 fd = 1073217536

此代码的要点是显示如果使用%d打印浮动值并且打印int值为%f将会发生什么.

为什么即使我使用%f,浮点值也不能正确打印?

c printf pointers

3
推荐指数
1
解决办法
4960
查看次数

printf()的异常行为?

可能重复:
使用%f打印整数变量

#include<stdio.h>

int main()
{
    printf("%f",9/5);
    return 0;   
}
Run Code Online (Sandbox Code Playgroud)

输出:0.000000

任何人都可以解释上述程序的输出吗?

不应该是程序的输出是1.000000?

c

3
推荐指数
2
解决办法
2150
查看次数

float variables in C

May be this is a simple question but I am not sure about how float variables are stored in memory and why it is behaving in this way, can someone please explain about the following behavior.

#include<stdio.h>

int main ()
{
    int a = 9/5;
    printf("%f\n", a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Output:

0.000000
Run Code Online (Sandbox Code Playgroud)

I have looked at some information on how float variables are stored in memory, it has stuff about mantissa, exponent and sign. But I am not getting how …

c format-specifiers

1
推荐指数
1
解决办法
522
查看次数

printf()函数异常

我在处理整数和浮点数时看到打印功能异常。

float y = 9/5;
printf("%f", y);

printf("%f", 9/5);
Run Code Online (Sandbox Code Playgroud)

第一个打印语句输出1.000000,可以接受,而其他输出0.000000。为什么两种情况下的输出都不同?

c floating-point printf

-2
推荐指数
1
解决办法
84
查看次数

标签 统计

c ×4

printf ×2

floating-point ×1

format-specifiers ×1

pointers ×1