我试图运行下面的代码来演示转换是如何工作的。
#include <stdio.h>
int main()
{
int x=5;
int y=2;
float z;
printf("x=%d\n", x);
printf("y=%d\n", y);
//Doing division as it is
z= x/y;
printf("With no preliminar assignment: (z=x/y)\n");
printf("\"z\
我注意到println()这样做,但我无法让它在printf()中工作。
在下面的片段中,前两个println发出红色和蓝色,然后printf崩溃。
class Jim {
public enum Colours {BLUE, RED}
static Colours xx = Colours.RED;
public static void main(String[] args) {
Colours fred = Colours.BLUE;
System.out.println(xx);
System.out.println(fred);
System.out
我有以下代码:
#include<stdio.h>
int main()
{
printf("The 'int' datatype is \t\t %lu bytes\n", sizeof(int));
printf("The 'unsigned int' data type is\t %lu bytes\n", sizeof(unsigned int));
printf("The 'short int' data type is\t %lu bytes\n",
根据惯例,int (*o)5=&s;是指针o指向包含5个元素的数组的正确方式。 我们也可以在下面的语句中这样写 int (*p)[10]=s; 但为什么更喜欢 &s at int (*o)[5]=&s; 因为它们都返回相同的输出。 #include <stdio.h>
int main()
{
int s[5]={10,1,2,3,4};
int (*p)[10]=s;
printf("%d\n",*p);
printf("%d\n",**p);
我使用GCC编译器(9.2.0版)
我想在C中使用typeof函数,但它会引发一个错误(错误:在“类型”之前的预期表达式)
如果你需要更多的信息,就问我。
int a = 5;
double b;
//the expected result is "0", but it raises an error instead...
printf("%d", typeof(a) == typeof(b));
这在我看来确实很奇怪,而且我从未在资源中看到过关于C枚举的任何讨论。变量a的类型是enum Direction,它可以是-1,但是a<0将是假的。我错过了什么?
#include <stdio.h>
enum Direction {N,W,S,E};
int main()
{
enum Direction a = N;
printf("a is %d\n", a);
a--;
printf("now a is %d\n", a);
printf("but (a<0) is %d\n\n&
下面的程序是否在C中调用Undefined Behaviour?
int main()
{
printf("Printf asking: Where is my declaration ?");
}
在上面的程序中有一个隐式的printf()声明,那么上面的代码是完全符合标准的,还是只有一些特定于实现的行为?
让我们说我们有以下表达式:
(x>y) ? printf("type of int") : func_string()
我们这里有什么?
x>y -> true -> printf("type of int") -> the type of the expression is int (because printf function is an int type function).
或
x>y -> false -> calls func_string() function which for the purpo
使用printf("%f\n", myNumber)打印int时,为什么会得到错误的值
我不明白为什么它在%d上打印得很好,但在%f上却不行。它不应该只添加额外的零吗?
int a = 1;
int b = 10;
int c = 100;
int d = 1000;
int e = 10000;
printf("%d %d %d %d %d\n", a, b, c, d, e); //prints fine
printf("%f %f %f %f %f\n", a, b, c, d, e); //prints weird stuff
#include <stdio.h>
struct A {
int data; // this is data
void *(*function)(); // this is operation
};
void myfun1() {
printf("this is fun()\n");
}
int myfun2(int a) {
printf("this is fun(%d)\n", a);
return a;
}
char myfun3(int a) {
printf("this i
int main()
{
double x = 10.08;
double *p;
p = &x;
printf("value of pointer is %d\n",p);
*p=&x;//error line
printf("value of x, *p = %lf\n",x);
return 0;
}
当我对int类型(即int x,int *p)执行此操作时,它工作得很好。但不是为了双倍,为什么?
有人能帮我处理这段代码吗?我看不出有什么问题,但不知怎么不管用。当我输入我最喜欢的数字并按回车键时,数字4223092出现了。
int target;
int after;
#include <stdio.h>
int main() {
printf("What is 6 x 4?: ");
scanf("%d", &target);
if (target == 24) {
printf("Correct!\n");
printf("By the way
struct DummyStruct{
unsigned long long std;
int type;
};
DummyStruct d;
d.std = 100;
d.type = 10;
/// buggy printf, unsigned long long to int conversion is buggy.
printf("%d,%d\n",d.std, d.type); // OUTPUT: 0,100
printf("%d,%d\n", d.type, d.std); // OUTPUT: 10,100
我收到一个警告,说赋值来自不兼容的指针类型。我是个编程新手,尽了最大的努力,但还是搞不懂。我收到以下错误: 20 6 D:\DS programs\practical 2\employees_structure_pointer.c Warning赋值来自不兼容的指针类型 /* Accept n employee details using structure and pointer and display their details. */
#include<stdio.h>
#include<conio.h>
#include<string.h>
#i
我有这样的代码:
let n = read_int()
let rec fact n = if n=0 then 1 else n*fact(n-1)
let () = Printf.printf "%d factorial is %d.\n" n fact(n)
我编译,然后编译器说:
File "fat.ml", line 3, characters 23-46:
Error: This expression has type
('a -> 'b, out_channel, unit, unit, unit, '
(float*)在g的情况下特别做些什么?如果我写g = *&i;,那么ouptut是正常的,即g=f,但是如果g = *(float*)&i;,为什么是g=0.0000?
#include <stdio.h>
int main()
{
int i = 37;
int *p;
p = &i;
float f = i;
printf("%d\n", i);
printf("%d\n", p);
printf("%d\n", *p);
float g = *(float*) &i;
printf(
有一项要求是,我必须在运行时更新指针,因此编写了类似于检查的代码。
int main()
{
printf("Hello World");
int *ptr = NULL;
int var = 10;
ptr = &var;
printf ("\nvalue is %d\t", ptr);
printf ("\nvalue is %d\t", &var);
printf ("\nvalue is %d\t", *ptr);
int add
当将整数的指针传递到另一个函数时,在第14行出现了不兼容的类型错误。有人能解释一下为什么以及如何解决这个问题吗。
#include<stdio.h>
int check_similar(int *pa, int *pb);
int main()
{
int a[5], b[5], i;
for (i=0; i<5; i++){
scanf("%d", &a[i]);
}
for (i=0; i<5; i++){
scanf("%d", &b[i]);
一个简单的程序
#include<stdio.h>
int main() {
char b='a';
printf("%s \n", b);
return 0;
}
输出:
test.c: In function ‘main’:
test.c:4:1: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s \n", b);
^
但是第二个参数是char,而不是int。
注意:这与implementation不一样,因为这里的问题专门询问有效declaration__.后面的零参数函数的。
零参数的实现应该包括void关键字吗?具体来说,对于以下两个函数的实现,C标准有什么可说的吗?注意,foo1 和 foo2 都声明为零参数函数;唯一的区别是实现,而不是声明:
#include <stdio.h>
int foo1(void); // inform compiler that foo1 and foo2 are zero-args fns.
int foo2(void);
int main() {
printf("%d\n