advertisement

Lec27

50 %
50 %
advertisement
Information about Lec27
Education

Published on March 3, 2014

Author: SriHarsha1508

Source: slideshare.net

Description

A keynote on Problem Solving using Computers
advertisement

Pointers Next step V. Kamakoti

Yesterday’s class • 2-D Array can be viewed as an array of row pointers each pointing to a column pointer. • It is pointer to a pointer – Double pointer

An example #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) a[I] = (int *)malloc(ncols*sizeof(int)); } //Creates a matrix a[nrows][ncols]

An example #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) //a[I] = (int *)malloc(ncols*sizeof(int)); *(a+I) = (int *)malloc(ncols*sizeof(int)); } //Creates a matrix a[nrows][ncols]

An example #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) *(a+I) = (int *)malloc(ncols*sizeof(int)); a[2][5] = 15; printf(“%dn”,a[2][5]); } //Creates a matrix a[nrows][ncols]

An example #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) *(a+I) = (int *)malloc(ncols*sizeof(int)); a[2][5] = 15; printf(“%dn”,*(*(a+2)+5)); } //Creates a matrix a[nrows][ncols]

An example #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) *(a+I) = (int *)malloc(ncols*sizeof(int)); a[2][5] = 15; // printf(“%dn”,*(*(a+2)+5)); printf(“%dn”,*(a[2] + 5)); } //Creates a matrix a[nrows][ncols]

What happens when we print • In Unsigned hex – “a” : 0x8049660 – “a+1”: 0x8049664 – “a+2”:0x8049668 – “*a”:134518448 == “a[0] or *(a)” – “*(a+1)”: 134527456 //ncols = 2251 – Difference is 2252, but need not be always – I worked in a system without any other user

Reallocate #include <stdio.h> main() { int **a, I, nrows,ncols; scanf(“%d %d”,&nrows,&ncols); a = (int *) malloc(nrows*sizeof(int *)); for (I = 0; I < nrows; I++) *(a+I) = (int *)malloc(ncols*sizeof(int)); *(a+1)=(int*)malloc(ncols*sizeof(int)); printf(“%dn”,a[1] - a[0]); //It will not be 2252 free(a); } //Creates a matrix a[nrows][ncols]

Strings • • • • • • Can be declared as matrix of characters How? Automatic initialization char *color[2] = {“red”,”black”}; This creates an array of two pointers Each of this points to a pointer to array of characters of length 4 and 6 resp.

Add a comment

Related presentations

Related pages

Lec27 - PHYS - 115

View Notes - Lec27 from PHYS 115 at University of Saskatchewan. Electric Field Lines A convenient aid for visualizing electric eld pa8erns is
Read more

Lec27: Sociobiology and culture; Practical issues and ...

This lecture discusses the relationships between sociobiology and culture as well as practical issues in sociobiology.
Read more

Lec27_04_06.html

ORGANISCHE CHEMIE III . Gliederung der heutigen Vorlesung 1. Aromatizität; aromatische Kohlenwasserstoffe 1.2 Aromatizität und Hückel MO-Theorie
Read more

lec27 - CIS - 120

View Notes - lec27 from CIS 120 at UPenn. Programming Languages and Techniques (CIS120) Lecture 27 November 12, 2012 StaAc Members,
Read more

Lec27_05_02.html

ORGANISCHE CHEMIE I. Gliederung der heutigen Vorlesung 4. Alkene & Halogenalkane - Saytzev und Hofmann Regel - Hydroborierung und ...
Read more

lec27

lec27 - Free download as PDF File (.pdf), Text File (.txt) or read online for free. lecture
Read more

EECS150 - Digital Design Lecture 27 – Miscellanea

1 Spring 2005 EECS150 – Lec27-misc Page 1 EECS150 - Digital Design Lecture 27 – Miscellanea May 3, 2005 John Wawrzynek Spring 2005 EECS150 – Lec27 ...
Read more

Lec27_05_05.html

SPEKTROSKOPIEKURS. Zweidimensionale NMR-Spektroskopie 1. Einführung: was bedeutet 2D NMR? 2. Grundlagen - Skalare Kopplung - Kern-Overhauser ...
Read more

Lec27 03 16 15 phys2020 - Home | University of Colorado ...

3/15/15 1 A loop of wire is moving rapidly and entering a region of uniform magnetic field as shown. At the instant shown, is the flux through the
Read more