






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 30
This page cannot be seen from the preview
Don't miss anything!























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