CSE 15 Lecture Notes - Lecture 6: Gnu Compiler Collection, Ampersand, Byte Addressing

18 views3 pages
19 Oct 2016
School
Course
Professor
CMPS 12B Lecture 6
10/11/2016
(5:20-6:45)
Programming in C and Pointers
Pointers = Java reference
Int[] data = {10, 20} The array is actually referencing a different location where the elements
reside. All java arrays know it has elements, .length, what type of data is in each element, etc.
Java always uses pass-by-value (call-by-value) parameter passing.
foo(data)
data = reference to an array of numbers somewhere else. If the thing you’re passing is a non-
primitive value, it’s always referencing something else.
With Java, call to foo will never change what’s in the box. With C you can.
*printf = print formatted. Starts with string, percent sign (%) says put something here, (/n) slash-
n means new line
C
Array declaration: int x[10];
Int x[]; (is also fine in Java, but poor style)
Ex: Array of 7 elements
|-----------------| int main() {
X | # | 0 int x[7];
|-----------------| int *px = x;
| # | 1 px = &x[1];
|-----------------| int *px2 = &x[0];
| # | 2
|-----------------| x[0] = 99;
| # | 3 printf(“%d %d\n”, px, px2);
|-----------------| printf(“%d/n”, x[0]m x[1]);
| # | 4
|-----------------| return 0;
| # | 5 }
|-----------------|
| # | 6 gcc (to compile)
|-----------------|
X points to first element of array
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Int[] data = {10, 20} the array is actually referencing a different location where the elements reside. All java arrays know it has elements, . length, what type of data is in each element, etc. Java always uses pass-by-value (call-by-value) parameter passing. foo(data) data = reference to an array of numbers somewhere else. If the thing you"re passing is a non- primitive value, it"s always referencing something else. With java, call to foo will never change what"s in the box. Starts with string, percent sign (%) says put something here, (/n) slash- n means new line. Int x[]; (is also fine in java, but poor style) | 6 int main() { int x[7]; int *px = x; px = &x[1]; int *px2 = &x[0]; x[0] = 99; printf( %d %d\n , px, px2); printf( %d/n , x[0]m x[1]); return 0; gcc (to compile) X is pointer, but we can"t use it like one because we haven"t declared it.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents