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

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Programming
Lecture 14
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

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

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 ] ; }

Code

else

{

if ( sal [ i ] [ 0 ] <= 20000 ) { sal [ i ] [ 1 ] = sal [ I ] [ 0 ] - 0.1 * sal [ I ] [ 0 ] ; }

Code

else

sal [ i ] [ 1 ] = sal [ i ] [ 0 ] - 0.15 * sal [ i ] [ 0 ] ;

if ( grossSalary > sal [ i ] [ 0 ] && netSalary < sal [ i ] [ 1 ] )

This logic will fail

Code

void locateUnluckyIndividual ( int sal [ ] [ 2 ] , int lucky [ ] , int numEmps ) { int i , j ; int grossSalary , netSalary ; for ( i = 0 ; i < numEmp ; i ++ ) { grossSalary = sal [ i ] [ 0 ] ; netSalary = sal [ i ] [ 1 ] ; for ( j = 0 ; j < numEmp ; j ++ ) { if ( grossSalary > sal [ j ] [ 0 ] && netSalary < sal [ j ] [ 1 ] ) { lucky [ i ] = 1 ; } } } }

Pointers

Pointers

10

x

60000

Location

Address of x

Declaring Pointers

double *x ;

char *c ;

Example

int *ptr ;

int x ;

x = 10 ;

ptr = &x ;

z = *ptr * 2 ;

Initializing Pointers

ptr = &var ;

ptr = 0 ;

ptr = NULL ;

0 and NULL points to nothing

Declaring pointers

int *ptr1 , *ptr2 , *ptr3 ;

Declaring pointers

int *ptr , x ;