c pointers and array

前端 未结 4 1691
后悔当初
后悔当初 2021-01-18 02:20
#include 
#include 

int main (void)
{
    int a[] = {1,2,3,4,5};
    int b[] = {0,0,0,0,0};
    int *p = b;

    for (int i =0; i <         


        
4条回答
  •  遇见更好的自我
    2021-01-18 03:23

    you shouldnt make seperate loop for printing and incrementing the values of the array . do both in same loop and do the follouwing to get ur output :) #include #include

    int main(void)
    {
    
    int a[]={1,2,3,4,5};
    int b[]={0,0,0,0,0};
    int c[]={0,0,0,0,0};
    int *p;
    int i;
    p=c;
    for( i =0 ; i<5 ; i++)
    {
        b[i]=a[i]+1;
        *p=b[i]-1;
        //*p++;
    
    //for( i =0 ; i<5 ; i++)
    
        printf(" %i \t %i \t %i \n" ,*p,b[i],a[i]);
    
    }
    return 0;
    }
    

提交回复
热议问题