Lec27

50 %
50 %
Education

Published on March 3, 2014

Author: SriHarsha1508

Source: slideshare.net

Description

A keynote on Problem Solving using Computers

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.

 User name: Comment:

Related presentations

Digital Marketing and Treditional Marketing

November 21, 2018

November 21, 2018

Germany Study Visa Checklist for Indian Student (E...

November 21, 2018

November 21, 2018

Best Certifications Offered By APRN World

November 21, 2018

What are the major difference between JK bank cler...

November 21, 2018

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

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

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

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

lec27 - CIS - 120

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

Lec27_05_02.html

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

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 ...