C Programming Absolute Beginner's Guide (3rd Edition)
Here’s a second program that shows the value of linked arrays. Returning to the basketball player from the last chapter, this pr ...
Tip If you are keeping track of multiple variables tied to one object (such as one player’s different stats from a single game i ...
23. Alphabetizing and Arranging Your Data In This Chapter Putting your house in order: sorting Conducting faster searches Sort ...
FIGURE 23.1 During each pass, the lower values “float” to the top of the array. The next program sorts a list of 10 numbers. The ...
run several times (one time for each item in the list). An added bonus that is common to many improved bubble sort routines is t ...
nums[outer] = temp; didSwap = 1; } } if (didSwap == 0) { break; } } // Now list the array as it currently is after sorting puts( ...
completion of the program. Here is the swapping of the variables inside the inner loop: temp = nums[inner]; nums[inner] = nums[o ...
313 532 178 902 422 562 Suppose the program had to look for the customer ID 413. With an unsorted array, a program would have to ...
include <stdio.h> main() { int ctr; // Loop counter int idSearch; // Customer to look for (the key) int found = 0; // 1 (t ...
} // Once the loop has completed, the ID was either found // (found = 1) or not if (found) { if (custBal[ctr] > 100) { printf ...
Keeping arrays sorted is not always easy or efficient. For instance, you don’t want your program sorting a large array every tim ...
24. Solving the Mystery of Pointers In This Chapter Working with memory addresses Defining pointer variables Using the derefere ...
int num; float value; To define an integer pointer variable and a floating-point pointer variable, you simply insert an *: Click ...
FIGURE 24.1 The variable pAge points to age if pAge holds the address of age. Warning Just because you define two variables back ...
(and confuse more people). Dereferencing just means that you use the pointer to get to the other variable. When you dereference, ...
float pPrice; char code; char pCode; price = 17.50; pPrice = &price; printf("\nHow many kids are you taking to the water park? ...
} return(0); } Here’s a sample run of the program: Click here to view code image How many kids are you taking to the water park? ...
value. Don’t get too far ahead. You will fully appreciate pointers only after programming in C for a while. At this point (pun ...
25. Arrays and Pointers In This Chapter Understanding that array names are pointers Getting down in the list Working with chara ...
FIGURE 25.1 The array name is a pointer to the first value in the array. Because the array name is a pointer (that can’t be chan ...
«
5
6
7
8
9
10
11
12
13
14
»
Free download pdf