UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

expressions

We can use dereferenced integer pointers in integer expressions just like any other integer variable. The type of a dereferenced integer pointer is an integer.

The Program

/********************************************* * File: express.c * Author: R. Chang * Date: ? * Modified by S. Bogar * Date: 12/31/98 * Section: 101 * EMail: bogar@cs.umbc.edu * * A sample program that shows how to * use pointers in an expression. **********************************************/ #include <stdio.h> int main () { int i = 3, j = 5, *p, *q, *r ; int result ; p = &i ; q = &j ; if ( p == &i ) { printf("p is pointing to i.\n") ; } /* A * and & pair cancel each other out */ result = **&p ; printf("result = %d\n", result) ; /* Dereferenced pointers are expressions */ result = 7 * *p / * q + 7 ; printf("result = %d\n", result) ; /* All these asterisks get confusing */ result = (* (r = & j) *= *p) ; printf("result = %d\n", result) ; return 0; }

The Sample Run

p is pointing to i. result = 3 result = 11 result = 15
Last Modified - Tuesday, 22-Aug-2006 07:14:17 EDT


CSEE | 201 | 201 F'06 | lectures | news | help