LEC20081016 - Introduction to Computer Programming October...

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

View Full Document Right Arrow Icon
Introduction to Computer Programming October 16, 2008 CSC180 Fall 2008, University of Toronto
Background image of page 1

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

View Full DocumentRight Arrow Icon
Null pointers A null pointer points to nothing. It contains a special value that is not the address of any object. A null pointer constant: an integral constant expression with value 0 , or such an expression cast to type void * : #define NULL 0 #define NULL (1-1) #define NULL ((void *)0) /* typical */ #define NULL ((void *)(1-1)) NULL is defined in stdio.h , stdlib.h , string.h , stddef.h , time.h , and locale.h . CSC180 Fall 2008, University of Toronto 1
Background image of page 2
How to get a null pointer? Assign a null pointer constant to the pointer. A null pointer compares unequal to a pointer to any object. Example: #include <stdio.h> char *p, *q; int *r, *s; /* * 0 in a pointer context is converted to a null pointer constant */ p = 0; q = NULL; /* preferred way */ /* p and q are null pointers of type char */ printf(‘‘p and q are null pointers\n’’); CSC180 Fall 2008, University of Toronto 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
if (r != NULL)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto- Toronto.

Page1 / 11

LEC20081016 - Introduction to Computer Programming October...

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