New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Ted Robel Sr.


Ted Robel Sr.
GPA 3.96


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course

Popular in ComputerScienence

This 26 page Class Notes was uploaded by Ted Robel Sr. on Thursday October 22, 2015. The Class Notes belongs to CMPSC 60 at University of California Santa Barbara taught by Staff in Fall. Since its upload, it has received 34 views. For similar materials see /class/227011/cmpsc-60-university-of-california-santa-barbara in ComputerScienence at University of California Santa Barbara.

Similar to CMPSC 60 at UCSB

Popular in ComputerScienence


Reviews for INTRO TO C C++ UNIX


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 10/22/15
Introduction to C C and UniXLinuX CS 60 Lecture 14 Miscellaneous C C operators namespace a Reading KR Chapters 17 a Read So chapters 1 3 4 Boolean 9 13 14 amp 18 tamed Notes 0 Questions Constant declarations 0 We ve already seen const for declaring variables It is illegal warning to change a const variable 0 Why use const rather than define Normal variable scoping rules Type checking is that number an integer or a short Can be used for almost any type of C construct eg a const struct 0 def ine is still useful especially for conditional compilation and of course macro definitions Constant parameters and return values 0 Functions can take const parameters and return constVahms const double Areaconst double radius double area PIradiusradius returnarea 0 Reference declarations 0 Another special variable type the reference type zkmhmmmvmmmewmsampmddmemmmm nmne nwanahas uava wMe int numbytes 1024 intamp nb numbytes nb Not all that useful for regular numbytes gt variables Function parameter passing Pass by reference Pass by value void ClearImImageamp x void ClearImImage x xdata 0 xdata 0 Pass by39pomter Differences void ClearImImage x xgtdata 0 gt xdata 0 Reference parameters and return values 0 Reference parameters are used in a function parameter list to accomplish passbyreference rather than passbyvalue But Without the mess of having to do everything with pointers void swapintamp x intamp y int temp x x y y temp Reference parameters and return values cont 0 Reference declarations can also be used for return values intamp smallerintamp x intamp y if x lt y returnx else returny int x 5 y 7 smallerx y 0 Reference parameters and return values cont 0 Reference declarations are efficient just like passing a pointer rather than all the data 0 If you want the efficiency but don t want the return value modified then const intamp smallerintamp x intamp y int x 5 y 7 smaller x y O lt Illegal Function parameter types Table 92 Type Declaration Call by value funcint var Call by address funcint gt ltVar Constant call by value funcconst int var Reference funcintamp var Constant reference funcconst intamp var Array funcarray Function return types Type Declaration Value int func Address int gt ltfunc Constant address const int gt ltfunc Constant value const int func Reference intamp func Constant reference const intamp func Function overloading 0 In C it s an error to define two functions of the same name Except when static on diff files 0 In C it s the norm 0 Multiple functions can be defined that operate on different types of data or accept different parameters 0 By convention all functions with the same name should perform the same basic function int sqrtint x float sqrtfloat x double sqrtdouble x long double sqrtlong double x void void void void void printint printchar printchar printfloat printdouble Function overloading cont 0 Important Only the parameter list differentiates functions not the return type void printint char rand void printchar short rand void printchar int rand void printfloat float rand void printdouble double rand 0K N0 Default arguments 0 Function parameters can be given default arguments that are used if not overridden void SetPixelImage im int val0 int Combineint x int y int z0 bool Reserve Rest r int Time1930 int Num2 void Drawint color1 int size10 int width2 C default arguments 0 Function parameters can have default values void Drawint color int size1 int width2 Draw 2 1 2 Draw 2 I l These are equivalent calls Draw 2 It s not possible to specify width Without specifying color and size C default arguments cont 0 What s wrong with this void Drawint color1 int size int width2 All the parameters with defaults must be to the right The compiler assumes that the N parameters you specify are the first N parameters args wout defaults args wdefaults Inline functions 0 There is an overhead cost to call a function Copy parameters to the stack jump to the function pull parameters off of the stack copy results to the stack jump back to the calling routine pull results off of the stack 0 For efficiency we can request the compiler to inline some functions put the entire body of the function in the code instead of generating a call to the function Typically used for small functions that are called frequently Inline functions cont 0 For example a function to access or modify image pixel values Called thousands of times per image inlinelvoid Productdouble ampp double fac p fac return The C new and del e te operators 0 C uses the new operator to allocate heap memory rather than mal loo 0 And uses delete to return the memory rather than free 0 There are really four operators new delete new delete 0 new and delete are part of the language not library functions as are malloc and free 20 int num num new int int list list new int100 struct CourseInfo info info new CourseInfo class Player players players new Player15 delete num delete list delete info delete players 21 Newdelete and mallocfree 0 You can use malloc and free in C but don t mix them with new and delete int arr delete arr int malloc40 f int val freeval 0 new int Illegal though the compiler won t catch mm 22 Namespaees 0 A namespace is a way to group variables and functions together under a common label 0 Rather than mylibvar1nwlibfunct2nwlibfunct3 USS 0 Or using namespace mylib var1 functionz function3 23 Namespaces cont namespace mylib declare variables int val declare function int printvoid mylib val 3 using namespace mylib mylibprint val 3 print 24 namespace project namespace groupl namespace module int version Nesting namespace group2 namespace module int version projectgroup2moduleversion 3 25 Global namespaee 0 To access a global variable use var int x namespace mygvar int funcint x int x x x int funcint x returnx 39 mygvarx x returnx Why is this usually better 26


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Janice Dongeun University of Washington

"I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.