Suggestions
Use up and down arrows to review and enter to select.Please wait while we process your payment
If you don't see it, please check your spam folder. Sometimes it can end up there.
If you don't see it, please check your spam folder. Sometimes it can end up there.
Please wait while we process your payment
By signing up you agree to our terms and privacy policy.
Don’t have an account? Subscribe now
Create Your Account
Sign up for your FREE 7-day trial
Already have an account? Log in
Your Email
Choose Your Plan
Individual
Group Discount
Save over 50% with a SparkNotes PLUS Annual Plan!
Purchasing SparkNotes PLUS for a group?
Get Annual Plans at a discount when you buy 2 or more!
Price
$24.99 $18.74 /subscription + tax
Subtotal $37.48 + tax
Save 25% on 2-49 accounts
Save 30% on 50-99 accounts
Want 100 or more? Contact us for a customized plan.
Your Plan
Payment Details
Payment Summary
SparkNotes Plus
You'll be billed after your free trial ends.
7-Day Free Trial
Not Applicable
Renews December 13, 2023 December 6, 2023
Discounts (applied to next billing)
DUE NOW
US $0.00
SNPLUSROCKS20 | 20% Discount
This is not a valid promo code.
Discount Code (one code per order)
SparkNotes PLUS Annual Plan - Group Discount
Qty: 00
SparkNotes Plus subscription is $4.99/month or $24.99/year as selected above. The free trial period is the first 7 days of your subscription. TO CANCEL YOUR SUBSCRIPTION AND AVOID BEING CHARGED, YOU MUST CANCEL BEFORE THE END OF THE FREE TRIAL PERIOD. You may cancel your subscription on your Subscription and Billing page or contact Customer Support at custserv@bn.com. Your subscription will continue automatically once the free trial period is over. Free trial is available to new customers only.
Choose Your Plan
For the next 7 days, you'll have access to awesome PLUS stuff like AP English test prep, No Fear Shakespeare translations and audio, a note-taking tool, personalized dashboard, & much more!
You’ve successfully purchased a group discount. Your group members can use the joining link below to redeem their group membership. You'll also receive an email with the link.
Members will be prompted to log in or create an account to redeem their group membership.
Thanks for creating a SparkNotes account! Continue to start your free trial.
Please wait while we process your payment
Your PLUS subscription has expired
Please wait while we process your payment
Please wait while we process your payment
Your computer science professor has just asked you to write a program for him (he would do it himself but he's too busy grading your assignments). The program is supposed to read in all of his students' grades and then print them back out in sorted order. Simple, right? You grab your trusty bubble sort algorithm, write up a function to sort an array of data, then write a simple little program to read in all of the numbers, sort them, and print them back out, maybe something like:
There could be many reasons why your professor isn't happy with the code above. For example, there's not much in the way of error checking. More importantly though, he's probably a little wary of that 100 you have there in the code. You realize that, of course, he's got over 100 students in his class, so we'll just change this number to 500, allow him to have up to 500 students. You go home that night, again feeling very proud of yourself. The next year, though, you get a call from that professor again, and he's upset. Seems this year he had an influx of students and your program wasn't robust enough to handle all of them; you hadn't set aside enough memory and as such your program was of no more use to him. You think to yourself, "Back to the drawing board; there must be an easier way so that I don't have to keep rewriting this program every time the professor's class size changes." You're in luck, there is an easier way. Or at least a better one.
Up to this point, the memory we've been using has been static memory. What does this mean? Static memory is memory that is set aside automatically by the compiler for your program. When you declare a variable, such as the int arr[100] array we declared in the above program, you're telling the computer to set aside space for 100 integers. The computer of course obliges. The problem with this is that the computer needs to know how much memory to set aside before your program starts running. When you run your program, the computer gives it the memory it needs to hold all of the variables you've declared; in other words, you've statically allocated memory.
But this method fails in the above case with the professor. What we'd like to be able to do is to create an array whose size is specified at run time. This time, the computer doesn't oblige; it fact, neither does the compiler. If you try to write code that looks like:
So, how do we get around this? The answer is dynamic memory allocation, and for that, we need pointers.
Dynamic memory allocation is a process that allows us to do exactly what we're looking to do above, to allocate memory while our program is running, as opposed to telling the computer exactly how much we'll need (and for what) ahead of time.
Please wait while we process your payment