lec3 - CS240: Programming in C Lecture 3: More on Types...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS240: Programming in C Lecture 3: More on Types Sunday, January 16, 2011 Type representation and enforcement #include <stdio.h> int main () { short s = 9; long l = 32768; printf("%d\n", s); s = l; printf("%d\n", s); return 0; } short can store -32768 to 32767 Sunday, January 16, 2011 Type representation and enforcement #include <stdio.h> int main () { short s = 9; long l = 32768; printf("%d\n", s); s = l; printf("%d\n", s); return 0; } short can store -32768 to 32767-32768 Sunday, January 16, 2011 Pointers The address of a location in memory is also a type based on what is stored at that memory location char * is “a pointer to char” or the address of memory where a char is stored int * points to a location in memory where a int is stored float * points to a location in memory where a float is stored We can do operation with this addresses The size of an address is platform dependent, on many is 32 bits. … 10101101 0xbffffaab Sunday, January 16, 2011 & and * Given a variable v &v means the address of v Given a pointer ptr *ptr means the value stored at the address specified by ptr All variables are associated with an address (a memory location). Both the contents of the location as well as the location itself are manipulable. Sunday, January 16, 2011 Example #include <stdio.h> int main() { char c; char * c_ptr = &c; printf(" Size of char *: %d (bytes)\n", sizeof(c_ptr)); printf(" Address of c is: %p \n", &c); printf(" Value of c_ptr is: %p \n", c_ptr); return 0; } Sunday, January 16, 2011 Example...
View Full Document

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

Page1 / 20

lec3 - CS240: Programming in C Lecture 3: More on Types...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online