Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Code, Pointers - Introduction to Programming - Lecture Slides, Slides of Computer Programming

Code, logic, Pointers, Declaring Pointer to Integer, Dereferencing Operator, Initializing Pointers, Bubble Sort, Swapping, constant pointer, Array, Starting Address of Array are the key points of this lecture.

Typology: Slides

2011/2012

Uploaded on 11/06/2012

somo
somo 🇮🇳

4.8

(4)

70 documents

1 / 30

Toggle sidebar

Related documents


Partial preview of the text

Download Code, Pointers - Introduction to Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity! Introduction to Programming Lecture 14 Docsity.com Code calculateSalary ( int sal [ ] [ 2 ] , int lucky [ ] , int numEmps ) { for ( i = 0 ; i < numEmps ; i ++ ) { // netSalary = grossSalary – tax if ( sal [ i ] [ 0 ] <= 5000 ) { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] ; } Docsity.com Code else { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] - 0.15 * sal [ i ] [ 0 ] ; } } } } Docsity.com if ( sal [ i ] [ 0 ] >= 0 && sal [ i ] [ 0 ] <= 5000 ) { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] ; } if ( sal [ i ] [ 0 ] > 5000 && sal [ i ] [ 0 ] < 10000 ) { sal [ i ] [ 1 ] = sal [ i ] [ 0 ] - 0.05 * sal [ i ] [ 0 ] ; } ... … … Docsity.com if ( grossSalary > sal [ i ] [ 0 ] && netSalary < sal [ i ] [ 1 ] ) This logic will fail Docsity.com Pointers Docsity.com Pointers 10 x 60000 Location Address of x Docsity.com Declaring Pointer to Integer int *myptr ; myptr is pointer to an integer Docsity.com Dereferencing Operator * *ptr is read as “The value of what ever ptr points to” Docsity.com z = *ptr * 2 ; Docsity.com Initializing Pointers ptr = &var ; ptr = 0 ; ptr = NULL ; 0 and NULL points to nothing Docsity.com Declaring pointers int *ptr , x ; Docsity.com Declaring pointers int *ptr , x , a [ 10 ] ; Docsity.com Bubble Sort 5 1 3 6 9 2 4 8 1 5 3 6 4 8 2 9 3 1 6 5 4 2 9 8 4 3 2 1 6 5 9 8 Docsity.com Example main ( ) { int x = 10 , y = 20 , * yptr , * xptr ; yptr = &y ; xptr = &x ; swap ( yptr , xptr ) ; } Docsity.com Example swap ( int *yptr , int *xptr ) { … … … } Docsity.com const int *const myptr = &x ; myptr is a constant pointer to an integer Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved