以下程序的输出是什么?为什么?
#include <stdio.h>
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的编译器打印0和1095237632.为什么?
我有3个不同的进程,所有进程都打印出单个字符使用printf.但我在终端看不到它们.当我添加换行符时,printf("\n H")每个字符都在一个新行上,我可以看到它们.如果没有换行符,为什么它不起作用?
请看下面的代码
#include <stdio.h>
#include <stddef.h>
typedef struct _node
{
int a;
char *s;
}Node, *nodePtr;
int main(int argc, char *argv[])
{
char *str = "string"; /*str points to satic storage area*/
Node nd;
nodePtr pNode = NULL;
size_t offset_of_s = offsetof(Node,s);
nd.a = 1;
nd.s = str;
pNode = &nd;
/*Get addr of s, cast it to a different data types pointer, then de-reference it*/
/*this works, print "string"*/
printf("%s\n", *(int*)((char*)pNode + offset_of_s));
/*this sucks, print (null)*/
printf("%s\n", *(float*)((char*)pNode + …Run Code Online (Sandbox Code Playgroud) 在下面的C程序中,演示了十六进制浮点常量的用法
double d;
d = 2;
printf("Ex 1: 2 in hex: %a\n\n",d);
d = 256;
printf("Ex 2: 2^8 in hex: %a\n\n",d);
d = 0.015625; //= 2^-6
printf("Ex 3: 2^-6 in hex: %a\n\n",d);
d = 0.857421875;
printf("Ex 4: 0.857421875 in hex: %a\n\n",d);
Run Code Online (Sandbox Code Playgroud)
结果是:
Ex 1: 2 in hex: 0x1p+1
Ex 2: 2^8 in hex: 0x1p+8
Ex 3: 2^-6 in hex: 0x1p-6
Ex 4: 0.857421875 in hex: 0x1.b7p-1
Run Code Online (Sandbox Code Playgroud)
我不明白如何得到前4的结果?
我如何更改此代码,使用cout保留格式化为C++?
printf(" %5lu %3d %+1.2f ", nodes, depth, best_score / 100.0);
Run Code Online (Sandbox Code Playgroud) 我执行了以下代码
#include <stdio.h>
int main()
{
printf("%f\n", 9/5);
}
Run Code Online (Sandbox Code Playgroud)
输出: 0.000000
为什么不1呢?
如果我写 printf("%f %f %d %d\n", (float)9/5, 4, sizeof(float), sizeof(int));
那么输出就是 1.800000 0.000000 4 59
为什么不 1.800000 4 4 4
在我的机器上sizeof (float)是4
提前致谢
我正在尝试使用Kernighan和Ritchie的书(The C Bible)来学习C. 尝试使用tcc和MinGW(使用Windows)编译第一个问题.它给了我一个错误信息.最详细的一个来自Min GW:helloworld.c:3:8:错误:预期')'之前'('令牌
这是我的计划:
main()
(
printf("hello, world\n");
)
Run Code Online (Sandbox Code Playgroud)
据我所知,按照这本书来说.这已经过时了吗?我已经找到了这个但仍然找不到我做错了什么.请帮忙.
提前致谢!
我正在尝试编写一个Python脚本来测试我在汇编中针对预期输出编写的各种代码的输出.但是我很难将输出重定向到文件中.我写了以下内容:
extern printf
LINUX equ 80H ; interupt number for entering Linux kernel
EXIT equ 1 ; Linux system call 1 i.e. exit ()
section .data
intfmt: db "%ld", 10, 0
segment .text
global main
main:
push rax
push rsi
push rdi
mov rsi, 10
mov rdi, intfmt
xor rax, rax
call printf
pop rdi
pop rsi
pop rax
call os_return ; return to operating system
os_return:
mov rax, EXIT ; Linux system call 1 i.e. exit ()
mov rbx, …Run Code Online (Sandbox Code Playgroud) 我正在浏览MinGW附带的stdio.h头文件,并注意到该printf函数声明如下:
int printf (const char *__format, ...)
{
//body omitted
}
Run Code Online (Sandbox Code Playgroud)
我之前从未见过函数参数列表中的省略号,所以我试了一下.它编译并运行没有错误.那么,"......"的目的是什么?
请帮助我,它从文件中读取数据..并使用FIFO替换算法..我不知道为什么字符串(比较时)包含笑脸字符,当我确定我放置一个空终止符时有什么问题.
示例文件内容:
load AAAAAAAA
load AAAAAAAA
load BBBBBBBB
load BBBBBBBB
load BBBBBBBB
load BBBBBBBB
load AAAAAAAA
load CCCCCCCC
load CCCCCCCC
load DDDDDDDD
load EEEEEEEE
load EEEEEEEE
load FFFFFFFF
Run Code Online (Sandbox Code Playgroud)
试着运行它......
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
FILE *fpointer;
typedef struct cache Cache;
struct cache{
char DATA[8];
int COUNT;
int LOAD;
Cache *NEXT;
};
int scan(char *addr, Cache *front){
while(front != NULL){
printf("compare: %s & %s\n", addr, front->DATA);
if(strcmp(addr, front->DATA) == 0){
front->COUNT++;
return 0;
}
front->LOAD++;
front = front->NEXT;
}
return 1;
}
void …Run Code Online (Sandbox Code Playgroud)