Lec26-CS110 Computational Engineering

67 %
33 %
Information about Lec26-CS110 Computational Engineering

Published on March 3, 2014

Author: SriHarsha1508



A keynote on Problem Solving using Computers

Pointers V. Kamakoti

Pointers and Multidimensional Arrays • A two dimensional array is a collection of CONTIGUOUS one dimensional arrays. • int x[10][20] - can be written as – int (*x)[20]; – “x” points to the first element of the first 20 element array - first (zeroth) row – “x+1” points to the first element of the second 20 elements array - One’th row. – Interestingly - x[2][5] is equivalent to *(*(x+2) + 5)

Contiguous Arrays continued • • • • • a[row][col] == *(*(a+row) + col) scanf (“%d”,&a[row][col]); scanf(“%d”,(*(a+row)+col)); printf (“%d”,a[row][col]); printf(“%d”,*(*(a+row)+col));

Strings and Pointers • char *name - is a string • char *names[] - is an array of strings • char names[10][12] – Array of 10 strings, each 12 characters in length. • char *names[10]; – names[0], ….., names[9] are all pointers – So array of pointers

Strings and Pointers • If we want an array of “10” strings each of maximum size “n” characters • char *names[10]; – – – – names[0], ….., names[9] are all pointers So array of pointers Different from 2-dimensional arrays 2-dimensional arrays are CONTIGUOUS one dimensional arrays • Array of strings NEED NOT BE CONTIGUOUS ONE DIMENSIONAL Arrays

Objective • Understand difference between 2-D arrays and Array of Pointers. • Declaration • int x[10][20]; int (*x)[20] • char mystr[10][20]; char *mystr[10] • What is char (*mystr)[20] - a two dimensional array of characters

Add a comment

Related presentations

Related pages

Lec14-CS110 Computational Engineering - Education

International Journal of Computational Engineering Research(IJCER) ... Lec26-CS110 Computational Engineering. Lec19-CS110 Computational Engineering.
Read more

Computational Engineering | LinkedIn

View 4978 Computational Engineering posts, presentations, experts, and more. Get the professional knowledge you need on LinkedIn.
Read more