标签: compiler-errors

如何用C编写Hello World

我写了一个小程序在C中打印"Hello world".我不是C程序员,但我喜欢尝试它.在我的程序中有一个错误.请告诉我它是什么?这是我的计划:

int main(){
    printf("Hello World");
}
Run Code Online (Sandbox Code Playgroud)

我用Java Experiences写了这篇文章.我找不到有什么不对.

c compiler-errors

-4
推荐指数
2
解决办法
5382
查看次数

为什么我在'int'之前得到"error:expected'=',',',';','asm'或'__attribute__'?

processpairs2.c:7:错误:在'int'之前预期'=',',',';','asm'或' attribute '

我每次编译文件时都会得到错误,错误将我引用到第7行,这是我声明main()函数的地方.

我的主要功能被声明为

int main(int argc, char *argv[])
Run Code Online (Sandbox Code Playgroud)

有谁知道是什么导致了这个?

任何帮助是极大的赞赏.

第1-6行是

#include<stdio.h>
#define ROWS 4
#define COLS 10
void checkhighestpair();
int *ptotal, *pval1, *pval2
Run Code Online (Sandbox Code Playgroud)

c compiler-errors

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

左值作为条件运算符中赋值的左操作数

#include <stdio.h>
int main()
{
        int a = 1, b;
        a ? b = 3 : b = 4;
        printf("%d, %d", a, b);
        return 0;
}

[user@localhost programs]$ gcc -Wall vol.c
vol.c: In function ‘main’:
vol.c:5:16: error: lvalue required as left operand of assignment
  a ? b = 3 : b = 4;
                ^
Run Code Online (Sandbox Code Playgroud)

我给了左值,b然后为什么gcc显示错误以及如何解决它?

c c++ gcc compiler-errors conditional-operator

-4
推荐指数
1
解决办法
8007
查看次数

关于C中的一段代码的争论

我的朋友和我正在争论这段小代码:

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

int foo (int k) 
{
    int i, n;

    for (i = i ? 0 : i, n ^= n; i < sizeof(k) * 8;)
        n += k >> i++ & ~-2;
    return n;
}
Run Code Online (Sandbox Code Playgroud)

我怀疑它不会被编译,因为它i未初始化的,但我的朋友们认为它会.你怎么看?

c compiler-construction compiler-errors

-4
推荐指数
1
解决办法
98
查看次数

使用指针调用函数

任何人都可以解释我为什么会收到错误

无法将int**转换为argument1的int*

我已经看到所有堆栈溢出的答案,但没有找到解决我的问题的方法.我的代码

#include<stdio.h>

int* sum(int,int*);

int main()
{
    int a=5;
    int *b;

    *b=6;
    int *res;

    res=sum(a,&b);
    printf("\n%d\n%d\n",a,*b);
    printf("%d",*res);
}

int* sum(int x,int *y)
{
    x=x+1;
    *y=*y+3;
    return (&y);
}
Run Code Online (Sandbox Code Playgroud)

这是一个基本问题,但我发现很难解决错误.

c pointers compiler-errors function

-4
推荐指数
1
解决办法
72
查看次数

如何解决"预期"; 在C中的'{'token'之前?

我创建了一个打印罗马相当于一年的程序,但是我的程序显示了一个编译错误.我的节目说:

33 4 C:\ Users\ABC\Desktop\cc [Error] expected';' 在'{'之前

这是我的代码:

#include<stdio.h>
main()
{
    int a,rom;
    printf("Enter the year.");
    scanf("%d",&a);
    rom=reverse(a);
    printf("Roman equivalent of %d is:",a);
}
reverse(int a)
{
    int i,rev=0,rem;
    for(i=a;i>0;i=i/10)
    {
        rem=i%10;
        rev=rev*10+rem;
    }
    roman(a);
}
roman(int a)
{
    int c=0,i,j,k,l,m;
    for(i=a;i>0;i=i/10)
    {
        m=i%10;
        for(j=1;j>0;j--)
        {
            if(c==0)
            {
                printf("m\n");
            }
            elseif(c==1)
            {
                printf("d\n");
                for(l=m-5;l>0;l--)
                    printf("c");
                printf("\n");
            }
            elseif(c==2)
            {
                printf("l\n");
                for(l=m-5;l>0;l--)
                {
                    printf("x");
                }
                printf("\n");
            }
            elseif(c==3)
            {
                printf("v\n");
                for(l=m-5;l>0;l--)
                {
                    printf("i");
                }
                printf("\n");
            }
        }
        c++;
    }
}
Run Code Online (Sandbox Code Playgroud)

c compiler-errors compilation runtime-compilation

-4
推荐指数
1
解决办法
1972
查看次数

为什么此代码段显示编译错误?

我收到了这个编译问题,我无法弄清楚原因.有人可以帮忙吗?

    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int n = scan.getInt() ;
    System.out.println(factorial(n)) ;


int factorial(int a){
        if (a==0) 
            return 1;
        else 
            return (a*factorial(a-1));
    }}
Run Code Online (Sandbox Code Playgroud)

Post Edit注意:我不知道在main()中不能声明另一个函数.在外面写它,它工作得很好.

java compiler-errors

-4
推荐指数
1
解决办法
49
查看次数

无法将int类型隐式转换为int数组

我有简单的方法.我无法弄清楚它为什么会抛出错误.提前致谢!

 public static int[] Shift(int[] a) 
 {    
       if (a == null) return -1;
       ...
 }
Run Code Online (Sandbox Code Playgroud)

编译器抛出以下错误:

无法隐式转换intint[]

c# arrays methods int compiler-errors

-4
推荐指数
2
解决办法
1130
查看次数

为什么编译器认为Environment.Exit可以返回?

示例代码:

switch(something)
{
    case 0:
        System.Environment.Exit(0);
    case 1:
        // blah ...
        break;
}
Run Code Online (Sandbox Code Playgroud)

它不会编译,因为编译器认为执行可以从Exit()返回.编译器显然是错误的.

没有技巧.System.Environment.Exit()是真实的.

System.Environment.Exit()返回时不仅完全不合逻辑,我追踪代码并最终调用ExitProcess(exitCode);无法返回的代码.

c# compiler-errors design-rationale

-4
推荐指数
1
解决办法
164
查看次数

我的method.add(int)不会将用户输入添加到我的数组中

我正在尝试创建一个数组,询问用户的长度,然后要求用户一次一个地输入许多单个单词.不过我的代码是句子.add(s); 不会将我的"S"变量添加到我的名为句子的ArrayList中.请你看看我的代码,看看我做错了什么.编辑运行时,在输入数组的长度程序之后程序要求我输入一个单词,但立即打印在它下面的行上,带有两个括号[]并在那里停止程序.如果有人知道为什么这是在讨厌我会非常感激!

import java.util.Scanner;
import java.util.ArrayList;

public class UsingWords
{
    public static void main(String [] args)
    {
        Scanner scan = new Scanner(System.in);

        System.out.println("Enter an array length ");
        int lengthArray = scan.nextInt();

        ArrayList<String[]> sentences = new ArrayList<String[]>();

        for (int i=0; i <= lengthArray; i++); { 
            System.out.println("Please enter a word: "); 
            String s = scan.nextLine();
            sentences.add(s);
        }
        System.out.println(Arrays.toString(sentences));
    }
}
Run Code Online (Sandbox Code Playgroud)

java compiler-errors arraylist

-4
推荐指数
1
解决办法
60
查看次数