Pointer Comparison

# Pointer Comparison - • use pi here 8: Pointer Comparison...

This preview shows pages 1–5. Sign up to view the full content.

8: Pointer Comparison Two pointers of the same type, p and q , may be compared as long as both of them point to objects within a single memory block Pointers may be compared using the <, >, <=, >=, == , != When you are comparing two pointers,

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8: Pointer Comparison Assuming double *p, *pi; and p pointing to the block of SIZE doubles: for(pi = p, product = 1; pi < p+SIZE ; pi++) product *= *pi;
Block Traversal for(pi = p; pi < p+SIZE; pi++)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • use pi here 8: Pointer Comparison • /* Find the largest element in the block p */ • double *max; • for(max = p, pi = p+1; pi < p+SIZE; pi++) • if(*max < *pi) • max = pi; "Block Traversal" Idiom 8: Pointer Comparison • Copy the contents of a block pointed to by p of size SIZE to • another block pointed to by q : • double *pi, *qi; • if(MALLOC(q, double, SIZE)) • exit(EXIT_FAILURE);...
View Full Document

## This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue.

### Page1 / 5

Pointer Comparison - • use pi here 8: Pointer Comparison...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online