指向对象类型的指针

指向对象类型的指针

Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我一直跳过我的代码的一部分,这是当用户选择zerio时,我选择如果选择0,然后执行此操作,但它只是完全跳过了它

if (select = 0)
{
    for ( i = 0; i < 20; ++i)
  printf("%d", array[i]);
    //// whenever I enter zero it skips over this if entirely
}


另外,当我尝试调用一个函数并打印它时,我不断得到提示,我必须有一个指向对象类型的指针

    if (select = 1)
{


    square(array, 20);

    for( j = 0; j < 20; ++j);
    printf("%d", a[j]);
    //the j reads that I need a pointer-to-object type
}


这是我的全部代码。我正在尝试重新学习这件事,这是一项古老的任务

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

    void initialize(int a[], int size)
    {

int i;


    }

    void square(int a[], int size)
    {
int j;

for( j = 0; j < size; ++j)
    a[j] = a[j] * a[j];



    }





    int main (void)
    {


   int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,19};
    int i,j,k,l,m, select, a, size;


void initialize ( int a[], int size);
    void square ( int a[], int size);


printf("Please select an option from the form \n\n 0 - initialize \n\n 1 - square \n\n 2 ");
scanf("%d", &select);





if (select = 0)
{
    for ( i = 0; i < 20; ++i)
  printf("%d", array[i]);
    //// whenever I enter zero it skips over this if entirely
}
if (select = 1)
{


    square(array, 20);

    for( j = 0; j < 20; ++j);
    printf("%d", a[j]);
    //the j reads that I need a pointer-to-object type
}



    }

最佳答案

真正常见的错误:

if (select = 0)


应该

if (select == 0)


试试看进行防御性编程通常是一个好习惯

if (0 == select)


因为

if (0 = select)


无法工作,编译器会大喊

关于c - 程序传递if语句并需要指向对象类型的指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23327880/

10-10 04:23