1 / 8

Inform ática I

Inform ática I. Código 2547100 Semestre 2013-1 Para Ingeniería Electrónica e Ingeniería de Telecomunicaciones Profesor: Sebastián Isaza. Arrays and pointers. El nombre de un arreglo es siempre la dirección del primer elemento de ese arreglo

lael-malone
Télécharger la présentation

Inform ática I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Informática I Código 2547100 Semestre 2013-1 Para Ingeniería Electrónicae Ingeniería de Telecomunicaciones Profesor: Sebastián Isaza

  2. Arrays and pointers Informática I (2013-1) – Prof. Sebastián Isaza El nombre de un arreglo es siempre la dirección del primer elemento de ese arreglo Si lista es un arreglo, entonces lo siguiente es verdadero lista == &lista[0] Tanto lista como &lista[0] representan la dirección del primer elemento del arreglo lista ¡y son constantes!

  3. Stepping with pointers 0x2348 big 0x234C 0x2348 small 0x234A 0x234C int *big = 0x2348; big++; short *small = 0x2348; small++; small++; Informática I (2013-1) – Prof. Sebastián Isaza

  4. Arrays and pointers ptr sm[0] ptr+1 sm[1] ptr+2 sm[2] ptr+3 sm[3] ptr+4 sm[4] ptr+5 sm[5] short sm[5] short *ptr; ptr = sm; Informática I (2013-1) – Prof. Sebastián Isaza

  5. Arrays as function parameters Informática I (2013-1) – Prof. Sebastián Isaza intsum(int *ar, int n); int sum(int*, int n); int sum(intar[], int n); int sum(int[], int n); int sum(int*ar, int n){ // code } int sum(intar[], int n){ // code }

  6. Protecting array contents prototipo de la función declaración de variables en main() llamado de sum() en main() definición de la función int sum (constintar[], int n); intmain(void){ int res; intvalues[4] = {1, 6, 8, 4}; res = sum (values, 4); } int sum (constintar[], int n){ int i, total; for (total = 0, i = 0; i < n; i++){ total += ar[i]; } return total; } Informática I (2013-1) – Prof. Sebastián Isaza

  7. Pointer operations Informática I (2013-1) – Prof. Sebastián Isaza Asignación: ptr = &var Derreferenciación: *ptr Obtener dirección de un apuntador:&ptr Suma/Resta de un entero a un apuntador: ptr+1 Incremento/Decremento de un apuntador: ptr++ Resta de apuntadores: ptr1-ptr2 Comparación de apuntadores:ptr1<ptr2

  8. Double indirection A[0][0] A[0] A[0][1] A[1][0] A[1] A[1][1] A[2][0] A[2] A[2][1] int A[3][2]={{12,18},{20,26},{28,34}}; A == ? A[0] == ? A + 1 == ? A[0] + 1 == ? *(A[0]) == ? *A == ? **A == *(*A) ==? Informática I (2013-1) – Prof. Sebastián Isaza

More Related