Programming in C by Stephen G. Kochan
Author:Stephen G. Kochan
Language: eng
Format: epub, pdf
ISBN: 9780672331411
Publisher: Sams Publishing
The array days is defined to contain seven entries, each a pointer to a character string. So days[0] contains a pointer to the character string "Sunday", days[1] contains a pointer to the string "Monday", and so on (see Figure 11.10). You could display the name of the third weekday, for example, with the following statement:
printf ("%s\n", days[3]);
Figure 11.10 Array of pointers.
The Increment and Decrement Operators Revisited
Up to this point, whenever you used the increment or decrement operator, it was the only operator that appeared in the expression. When you write the expression ++x, you know that this has the effect of adding 1 to the value of the variable x. And as you have just seen, if x is a pointer to an array, this has the effect of setting x to point to the next element of the array.
The increment and decrement operators can be used in expressions in which other operators also appear. In such cases, it becomes important to know more precisely how these operators work.
So far, when you used the increment and decrement operators, you always placed them before the variables that were being incremented or decremented. So, to increment a variable i, you simply wrote
++i;
Actually, it also is perfectly valid to place the increment operator after the variable, as follows:
i++;
Both expressions are perfectly valid and both achieve the same result—namely, of incrementing the value of i. In the first case, where the ++ is placed before its operand, the increment operation is more precisely identified as a preincrement. In the second case, where the ++ is placed after its operand, the operation is identified as a postincrement.
The same discussion applies to the decrement operator. So the statement
--i;
technically performs a predecrement of i, whereas the statement
i--;
performs a postdecrement of i. Both have the same net result of subtracting 1 from the value of i.
It is when the increment and decrement operators are used in more complex expressions that the distinction between the pre- and post- nature of these operators is realized.
Suppose you have two integers called i and j. If you set the value of i to 0 and then write the statement
j = ++i;
the value that gets assigned to j is 1, and not 0 as you might expect. In the case of the preincrement operator, the variable is incremented before its value is used in the expression. So, in the preceding expression, the value of i is first incremented from 0 to 1 and then its value is assigned to j, as if the following two statements had been written instead:
++i;
j = i;
If you instead use the postincrement operator in the statement
j = i++;
then i is incremented after its value has been assigned to j. So, if i is 0 before the preceding statement is executed, 0 is assigned to j and then i is incremented by 1, as if the statements
j = i;
++i;
were used instead. As another example, if i is equal to 1, then the statement
x = a[--i];
has the effect of assigning
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(11976)
Hello! Python by Anthony Briggs(9424)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9390)
The Mikado Method by Ola Ellnestam Daniel Brolund(9353)
Dependency Injection in .NET by Mark Seemann(8897)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7896)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7415)
Grails in Action by Glen Smith Peter Ledbrook(7333)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7161)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6006)
Kotlin in Action by Dmitry Jemerov(4684)
Practical Vim (for Kathryn Amaral) by Drew Neil(3748)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(3625)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3533)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3278)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(3191)
Microservices with Go by Alexander Shuiskov(2977)
Practical Design Patterns for Java Developers by Miroslav Wengner(2894)
Learning Java by Patrick Niemeyer & Daniel Leuck(2891)
![](/ebook_detail_files/space.gif)