Example program oFind sum of squares and sum of cubes of array elements using

Example program ofind sum of squares and sum of cubes

This preview shows page 6 - 10 out of 17 pages.

Example program: o Find sum of squares and sum of cubes of array elements using pointers. o To copy elements of one array to another using pointer to array. o To find the maximum value out of the array elements. o All the operations possible on arrays.
Image of page 6
©LPU CSE101 C Programming (Lec-26)Pointer to group of 1D Arrays 1-D array can be represented in terms of a pointer (array name) and an subscript, 2-D array can also be represented with an equivalent pointer notation. A 2-D array is actually a collection of 1-D arrays. Therefore , we can define a 2-D array as a pointer to a group of contiguous 1-D arrays. 2 D array declaration can be written as data-type (*ptrvar) [expression 2]; rather than data type array[expression 1] [expression 2];
Image of page 7
©LPU CSE101 C Programming Eg: a is 2 D array having 10 rows and 20 columns. The item in row 2 and column 5 can be accessed by writing: a [2][5]; or *(*( a +2)+5)
Image of page 8
©LPU CSE101 C Programming a is a 2 D array having 10 rows and 20 columns. We can declare x as: int (*a)[20]; Rather than int a[10][20]; In this first declaration, a is defined to be a pointer to a group of contiguous 1 –D 20 element integer arrays. Thus a points to the first 20 element array which is actually the first row i.e row 0 of original 2 D array.
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 17 pages?

  • Spring '18
  • Aman
  • Array, Pointer, Function pointer

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors