以下代码编译并运行但我在编译时会发出警告:
#include <stdio.h>
#include <stdlib.h>
int main(void){
int x = 10;
printf("%p\n",&x);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
-Wall -std=gnu99 -O2 -o a.out source_file.c -pedantic -Wextra
Run Code Online (Sandbox Code Playgroud)
编译时发出以下警告
source_file.c: In function ‘main’:
source_file.c:7:3: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%p\n",&x);
Run Code Online (Sandbox Code Playgroud)
因为我之前没有添加一个(void*)强制转换,因为我在
编译时需要一个类型&x为%p.But的参数void*
gcc SO.c -o so -Wall -Wextra -pedantic -std=c11
Run Code Online (Sandbox Code Playgroud)
要么
gcc SO.c -o so -Wall -Wextra -pedantic -std=c99
Run Code Online (Sandbox Code Playgroud)
要么
gcc SO.c -o …Run Code Online (Sandbox Code Playgroud) #include<stdio.h>
void main()
{
int i = 5;
printf("%p",i);
}
Run Code Online (Sandbox Code Playgroud)
我试图在Linux上使用GCC编译器编译这个程序,在编译程序时会发出警告说
%p expects a void* pointer
Run Code Online (Sandbox Code Playgroud)
当运行时输出为46600x3.
但是当我使用网站codingground.tutorialspoint.com在线编译时,我得到一个输出等于0x5 即十六进制输出,有人可以解释原因吗?
我是C的新手.我尝试为Vector编写函数,但肯定有问题.
这是代码:
/* Defines maths for particles. */
#include <math.h>
#include <stdio.h>
/* The vector struct. */
typedef struct {
long double x, y, z;
} Vector;
Vector Vector_InitDoubleXYZ(double x, double y, double z) {
Vector v;
v.x = (long double) x;
v.y = (long double) y;
v.z = (long double) z;
return v;
}
Vector Vector_InitDoubleAll(double all) {
Vector v;
v.x = v.y = v.z = (long double) all;
return v;
}
Vector Vector_InitLongDXYZ(long double x, long double y, …Run Code Online (Sandbox Code Playgroud)