Pointer Comparison

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

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

View Full Document Right Arrow Icon
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,
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
Block Traversal for(pi = p; pi < p+SIZE; pi++)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
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 Right Arrow Icon
Ask a homework question - tutors are online