Pointer Array in C


Provide any example program with the use of pointer and array at a time.

void printArray(int *ptr, size_t length);            
{         
    //for statment to print values using array             
    size_t i = 0;
    for( ; i < length; ++i )      
    printf("%d", ptr[i]);        
}   

 void printString(const char *ptr);            
{         
    //for statment to print values using array             
    for( ; *ptr!=NULL; ++ptr)        
    printf("%c", *ptr);        
}         

int main()    
{    
    int array[6] = {2,4,6,8,10};     
    const char* str = "Hello World!";
    printArray(array, 6);    
    printString(str);
    return 0;     
}

10 comments:

  1. #include
    #include
    #include
    char* funcx(char* str);
    int main()
    {
    char* str[100];
    char* ptr;
    ptr=funcx(str);
    printf("\n The return string is: %s",ptr);
    getch();
    return 0;

    }

    char* funcx(char* str)
    {
    strcpy(str,"pointer and string combination that was given by arif sir");
    return str;

    }






    ReplyDelete
  2. #include
    #include
    main()
    {
    int n,j;
    printf("The array size : ");
    scanf("%d",&n);
    int a[n];
    printf("\nThe sum is :%d\n",arr(n,a));
    }

    int arr(int p,int q[])
    {
    int i,sum=0,*pt;
    printf("\nEnter your values :\n");
    for(i=0;i<p;i++)
    {
    scanf("%d",&q[i]);
    pt=&q[i];
    {
    sum+=*pt;
    pt++;
    }
    }
    return sum;
    }

    ReplyDelete

  3. int main()
    {
    int n;
    printf("The array size : ");
    scanf("%d",&n);
    int a[n];
    printf("\nThe sum is :%d\n",arr(n,a));
    }

    int arr(int x,int m[])
    {
    int i,sum=0,*pt;
    printf("\nEnter your values :\n");
    for(i=0;i<x;i++)
    {
    scanf("%d",&m[i]);
    pt=&m[i];
    {
    sum+=*pt;
    pt++;
    }
    }
    return sum;
    }

    ReplyDelete

  4. int main()
    {
    int n;
    printf("The array size : ");
    scanf("%d",&n);
    int a[n];
    printf("\nThe sum is :%d\n",arr(n,a));
    }

    int arr(int x,int m[])
    {
    int i,sum=0,*pt;
    printf("\nEnter your values :\n");
    for(i=0;i<x;i++)
    {
    scanf("%d",&m[i]);
    pt=&m[i];
    {
    sum+=*pt;
    pt++;
    }
    }
    return sum;
    }

    ReplyDelete
  5. int main()
    {
    int n;
    printf("The array size : ");
    scanf("%d",&n);
    int a[n];
    printf("\nThe sum is :%d\n",arr(n,a));
    }

    int arr(int x,int m[])
    {
    int i,sum=0,*pt;
    printf("\nEnter your values :\n");
    for(i=0;i<x;i++)
    {
    scanf("%d",&m[i]);
    pt=&m[i];
    {
    sum+=*pt;
    pt++;
    }
    }
    return sum;
    }

    ReplyDelete
  6. ID : 201620195
    https://www.dropbox.com/s/577o20n6fo7bafy/06.cpp?dl=0

    ReplyDelete
  7. ID:201520552
    1)https://drive.google.com/open?id=0B5pG0kIjzgEKSUxrRUU0ZnhhOXM
    2)https://drive.google.com/open?id=0B5pG0kIjzgEKVy1aeEx3ekx3Wms

    ReplyDelete
  8. Summer 2017
    ID#201610042

    https://drive.google.com/file/d/0B99eePh0LV8gQUpXblVLa2lsS3c/view?usp=drivesdk

    ReplyDelete
  9. MD USUF MIA
    ID 201610456
    link:
    https://drive.google.com/open?id=0B_PIGnOMR0K2TVVudFpIQk5DZXM

    ReplyDelete
  10. #include
    using namespace std;

    class arr
    {
    public:
    int a[5],i,sum=0,*p;
    arr()
    {
    for(i=0;i<5;i++)
    {
    cin>>a[i];
    }

    }
    void pointer()
    {
    p=&a[0];
    for(i=0;i<5;i++)
    {
    sum+=*p;
    p++;
    }
    cout<<sum;
    }
    };
    int main()
    {
    arr obj;
    obj.pointer();
    return 0;
    }

    ReplyDelete