Download presentation
Presentation is loading. Please wait.
Published byRoy Jackson Modified over 9 years ago
2
A First Book of ANSI C Fourth Edition Chapter 2 Getting Started in C Programming
3
A First Book of ANSI C, Fourth Edition2 个人信息 刘伯强 办公地址:山大南区四号楼 209 室 办公电话: 88392824 手机: 13854181564 电子邮件: bqliusd@163.com
4
A First Book of ANSI C, Fourth Edition3 Objectives Introduction to C Programming Programming Style Data Types Arithmetic Operations
5
A First Book of ANSI C, Fourth Edition4 Objectives (continued) Variables and Declarations Case Study: Temperature Conversion Common Programming and Compiler Errors
6
A First Book of ANSI C, Fourth Edition5 2.1 Introduction to C Programming
7
A First Book of ANSI C, Fourth Edition6 Introduction to C Programming (continued) C provides a comprehensive set of functions –Stored in a set of files known as the standard library –The standard library consists of 15 header files
8
A First Book of ANSI C, Fourth Edition7 Introduction to C Programming (continued)
9
A First Book of ANSI C, Fourth Edition8 Introduction to C Programming (continued) File : Pgm2-1.cpp #include int main( ) { float radius, circumference; radius = 2.0 ; circumference = 2.0 * 3.1416 * radius; printf("The circumference of the circle is %f ", circumference ) ; return 0 ; }
10
A First Book of ANSI C, Fourth Edition9 Introduction to C Programming (continued) Identifiers
11
A First Book of ANSI C, Fourth Edition10 Identifiers Identifiers in C consist of three types: –Reserved words –Standard identifiers –Programmer-created identifiers
12
A First Book of ANSI C, Fourth Edition11 Identifiers (continued) Reserved word: word that is predefined by the programming language for a special purpose and can only be used in a specified manner for its intended purpose –Also referred to as keywords in C
13
A First Book of ANSI C, Fourth Edition12 Identifiers (continued)
14
A First Book of ANSI C, Fourth Edition13 Identifiers (continued) Standard identifiers: words predefined in C Most of the standard identifiers are the names of functions that are provided in the C standard library It is good programming practice to use standard identifiers only for their intended purpose
15
A First Book of ANSI C, Fourth Edition14 Identifiers (continued)
16
A First Book of ANSI C, Fourth Edition15 Identifiers (continued) Programmer-created identifiers: selected by the programmer –Also called programmer-created names –Used for naming data and functions –Must conform to C’s identifier rules –Can be any combination of letters, digits, or underscores (_) subject to the following rules: First character must be a letter or underscore (_) Only letters, digits, or underscores may follow the initial character Blank spaces are not allowed Cannot be a reserved word
17
A First Book of ANSI C, Fourth Edition16 Identifiers (continued) Examples of invalid C programmer-created names: –4ab7 –calculate total –while All uppercase letters used to indicate a constant A function name must be followed by parentheses An identifier should be descriptive: degToRadians() –Bad identifier choices: easy, duh, justDoIt C is a case-sensitive language –TOTAL, and total represent different identifiers
18
A First Book of ANSI C, Fourth Edition17 The main() Function Sometimes referred to as a driver function
19
A First Book of ANSI C, Fourth Edition18 The main() Function (continued) Function header line Executable statements
20
A First Book of ANSI C, Fourth Edition19 The printf() Function printf() formats data and sends it to the standard system display device (i.e., the monitor) Inputting data or messages to a function is called passing data to the function –printf("Hello there world!"); Syntax: set of rules for formulating statements that are “grammatically correct” for the language Messages are known as strings in C –A string of characters is surrounded by double quotes printf("Hello there world!");
21
A First Book of ANSI C, Fourth Edition20 The printf() Function (continued) Function arguments
22
A First Book of ANSI C, Fourth Edition21 The printf() Function (continued) /* File : Pgm2-2.cpp Description : Displays Hello there world ! Programmer : G. Bronson Data : 6/15/00 */ #include int main ( ) { printf("Hello there world !"); return 0 ; }
23
A First Book of ANSI C, Fourth Edition22 A Comment Block The first six lines of program code, starting with the slash and asterisk symbol pair on line one, /*, and ending with the matching asterisk slash pair, */, on line six, constitutes a comment block. This block of comment statements consists of all typed characters following the start of the comment, which begins with the /* symbols and ends when the closing */ symbol pair is encountered.
24
A First Book of ANSI C, Fourth Edition23 #include The seventh line of the program # include is a preprocessor command. Preprocessor commands begin with a pound sign, #, and perform some action before the compiler translates the source program into machine code.
25
A First Book of ANSI C, Fourth Edition24 # include Specifically, the # include preprocessor command causes the contents of the named file, in this case stdio.h, to be inserted where the # include command appears. The file stdio.h is referred to as a header file because it is placed at the top, or head, of a C program using the # include command. In particular, the stdio.h file provides a proper interface to the printf ( ) function and should be included in all programs using printf ( ). Preprocessor commands do not end with a semicolon.
26
A First Book of ANSI C, Fourth Edition25 main ( ) function Following the preprocessor command is the start of the program’s main ( ) function. The main ( ) function has only two statements. Remember that statements end with a semicolon (;). The first statement in main ( ) calls the function printf ( ) and passes one argument to it. The argument is the message Hello there world !. The second statement returns control to the operating system.
27
A First Book of ANSI C, Fourth Edition26 printf ( ) Since printf ( ) is a prewritten function, we do not have to write it ; it is available for use just by calling it correctly. Like all C functions, printf ( ) was written to do a specific task, which is to print results. It is versatile and can print results in many different forms. When a message is passed to printf ( ), the function sees to it that the message is correctly printed on your screen
28
A First Book of ANSI C, Fourth Edition27 Strings Messages are called strings in C, because they consist of a string of characters made up of letters, numbers,and special characters. The beginning and end of a string of characters is marked by double quotes. Thus, to pass a message to printf ( ), the string of characters making up the message must be enclosed in double quotes The program output is Hello there world !
29
A First Book of ANSI C, Fourth Edition28 Comment Preprocessor command Header file Invoking or calling the printf() function
30
A First Book of ANSI C, Fourth Edition29 The printf() Function (continued) Program 2.3 /* File : Pgm2-3.cpp Description :Test program Programmer :G. Bronson Date :6/15/00 */ #include int main ( ) { printf (“Computers, computers everywhere ”); printf (“\n as far as I can C ”); return 0 ; }
31
A First Book of ANSI C, Fourth Edition30 When Program 2.3 is run, the following is displayed : Computers, computers everywhere as far as I can C
32
A First Book of ANSI C, Fourth Edition31 Newline Escape Sequence \n You might be wondering why the \n did not appear in the output. The two characters \ and n, when used together, are called a newline escape sequence. They tell printf ( ) to start on a new line. In C, the backslash (\) character provides an “escape ” from the normal interpretation of the character following it by altering the meaning of the next character.
33
A First Book of ANSI C, Fourth Edition32 If the backslash was omitted from the second printf ( ) call in Program 1.2, the n would be printed as the letter n and the program would print out : Computers, computers everywheren as far as I can C
34
A First Book of ANSI C, Fourth Edition33 The printf() Function (continued) Output is: Computers, computers everywhere as far as I can C Newline escape sequence
35
A First Book of ANSI C, Fourth Edition34 2.2 Programming Style Indentation Except for strings, function names, and reserved words, C ignores all white space –White space: any combination of one or more blank spaces, tabs, or new lines In standard form: –A function name is placed, with the parentheses, on a line by itself starting at the left-hand corner –The opening brace follows on the next line, under the first letter of the function name –The closing function brace is placed by itself at the start of the last line of the function
36
A First Book of ANSI C, Fourth Edition35 Programming Style: Indentation (continued) Within the function itself, all program statements are indented two spaces –Indentation is another sign of good programming practice, especially if the same indentation is used for similar groups of statements Don’t do this: int main ( ){printf ("Hello there world!" );return 0;}
37
A First Book of ANSI C, Fourth Edition36 Programming Style: Comments Comments help clarify what a program does, what a group of statements is meant to accomplish, etc. The symbols /*, with no white space between them, designate the start of a comment; the symbols */ designate the end of a comment /* this is a comment */ Comments can be placed anywhere within a program and have no effect on program execution Under no circumstances may comments be nested /* this comment is /* always */ invalid */
38
A First Book of ANSI C, Fourth Edition37 Programming Style: Comments (continued) Program 2.4 /* File :Pgm2-4.cpp Description :Test program Programmer :G.Bronson Date :6/15/00 */ #include int main ( ) /* this program prints a message */ { printf (“Hello there world !”); /* a call to printf ( ) */ return 0; }
39
A First Book of ANSI C, Fourth Edition38 Programming Style: Comments (continued)
40
A First Book of ANSI C, Fourth Edition39 2.3 Data Types Data type: set of values and a set of operations that can be applied to these values Built-in data type: is provided as an integral part of the language; also known as primitive type
41
A First Book of ANSI C, Fourth Edition40 Data Types (continued)
42
A First Book of ANSI C, Fourth Edition41 Data Types (continued)
43
A First Book of ANSI C, Fourth Edition42 An integer value, which is called an integer constant in C, is any positive or negative number without a decimal point. Example: 3 -10 +25 1000 -26351 +36 Compilers have integer limits on the largest and smallest. The limits depend on how much storage each compiler sets aside for an integer
44
A First Book of ANSI C, Fourth Edition43 Integer Data Types
45
A First Book of ANSI C, Fourth Edition44 Integer Data Types (continued) int : whole numbers (integers) –For example: 0, -10, 253, -26351 –Not allowed: commas, decimal points, special symbols char : stores individual characters (ASCII) –For example: 'A', '$', 'b', '!'
46
A First Book of ANSI C, Fourth Edition45 Integer Data Types (continued)
47
A First Book of ANSI C, Fourth Edition46 Integer Data Types (continued)
48
A First Book of ANSI C, Fourth Edition47 Integer Data Types (continued)
49
A First Book of ANSI C, Fourth Edition48 Floating-Point Data Types A floating-point value (real number) can be the number zero or any positive or negative number that contains a decimal point –For example: +10.625, 5., -6.2, 3251.92, +2 –Not allowed: commas, decimal points, special symbols float : single-precision number double : double-precision number Storage allocation for each data type depends on the compiler (use sizeof() )
50
A First Book of ANSI C, Fourth Edition49 Floating-Point Data Types (continued) float literal is indicated by appending an f or F long double is created by appending an l or L –9.234 indicates a double literal –9.234f indicates a float literal –9.234L indicates a long double literal
51
A First Book of ANSI C, Fourth Edition50 Floating-Point Data Types (continued)
52
A First Book of ANSI C, Fourth Edition51 Exponential Notation In numerical theory, the term precision typically refers to numerical accuracy
53
A First Book of ANSI C, Fourth Edition52 Exponential Notation (continued)
54
A First Book of ANSI C, Fourth Edition53 2.4 Arithmetic Operations Arithmetic operators: operators used for arithmetic operations: –Addition + –Subtraction - –Multiplication * –Division / –Modulus Division % Binary operators require two operands An operand can be either a literal value or an identifier that has a value associated with it
55
A First Book of ANSI C, Fourth Edition54 Arithmetic Operations (continued) A simple binary arithmetic expression consists of a binary arithmetic operator connecting two literal values in the form: –literalValue operator literalValue 3 + 7 12.62 - 9.8.08 * 12.2 12.6 / 2. Spaces around arithmetic operators are inserted for clarity and can be omitted without affecting the value of the expression
56
A First Book of ANSI C, Fourth Edition55 Displaying Numerical Values The printf ( ) function allows us to evaluate arithmetic expression and display their results. To do this we must pass at least two items to printf ( ): a control string that tells the function where and in what form the result is to be displayed, and the value that we wish to be displayed.
57
A First Book of ANSI C, Fourth Edition56 Displaying Numerical Values (continued) For example, printf ( “ The total of 6 and 15 is %d”, 6 + 15); In the statement, the first argument is the message The total of 6 and 15 is %d, and the second argument is the expression 6 + 15. The first argument passed to printf ( ) must always be a message, which also includes a conversion control sequence, such as %d, is termed a control string.
58
A First Book of ANSI C, Fourth Edition57 Displaying Numerical Values (continued) The percent sign % in a conversion control sequence tells printf ( ) to print a value at the place in the message where the % is located. The d, place immediately after %, tells printf ( ) that the value should be printed as an integer. The next argument is the expression 6+15, which has a value of 21, so it is this value that is displayed. Thus, the statement printf ( “ The total of 6 and 15 is %d”, 6 +15); Causes the printout The total of 6 and 15 is 21
59
A First Book of ANSI C, Fourth Edition58 Displaying Numerical Values (continued)
60
A First Book of ANSI C, Fourth Edition59 Displaying Numerical Values (continued) Just as the %d conversion control sequence alerts printf ( ) that an integer value is to be displayed, the conversion control sequence %f indicates that a number with a decimal point is to be displayed. For example, the statement printf ( “ The sum of %f and %f is %f. “, 12.2, 15.754,12.2 + 15.754 ); causes the display The sum of 12.200000 and 15.754000 is 27.954000.
61
A First Book of ANSI C, Fourth Edition60 Displaying Numerical Values (continued) Program 2.5 # include int main( ) { printf ( “%f plus %f equals %f\n”, 15.0, 2.0, 15.0 + 2.0); printf ( “%f minus %f equals %f\n”, 15.0, 2.0, 15.0 – 2.0); printf ( “%f times %f equals %f\n”, 15.0, 2.0, 15.0 * 2.0); printf ( “%f divided by %f equals %f”, 15.0, 2.0, 15.0 / 2); return 0; }
62
A First Book of ANSI C, Fourth Edition61 Displaying Numerical Values (continued)
63
A First Book of ANSI C, Fourth Edition62 Displaying Numerical Values (continued) Program 2.6# include int main ( ) { printf ( “ The decimal value of the letter %c is %d.”, ‘a’, ‘a’); printf ( “ \nThe octal value of the letter %c is %o.”, ‘a’, ‘a’); printf ( “ \nThe hex value of the letter %c is %x.”, ‘a’, ‘a’); return 0; } The output is The decimal value of the letter a is 97. The octal value of the letter a is 141. The hex value of the letter a is 61.
64
A First Book of ANSI C, Fourth Edition63 Displaying Numerical Values (continued)
65
A First Book of ANSI C, Fourth Edition64 Expression Types Expression: any combination of operators and operands that can be evaluated to yield a value Integer expression: contains only integer operands; the result is an integer Floating-point expression: contains only floating- point operands; the result is a double-precision In a mixed-mode expression the data type of each operation is determined by the following rules: –If both operands are integers, result is an integer –If one operand is real, result is double-precision
66
A First Book of ANSI C, Fourth Edition65 Integer Division 15/2 = 7 –Integers cannot contain a fractional part –Remainder is truncated % is the modulus or remainder operator –9 % 4 is 1 –17 % 3 is 2 –14 % 2 is 0
67
A First Book of ANSI C, Fourth Edition66 Negation A unary operator is one that operates on a single operand, e.g., negation (-) The minus sign in front of a single numerical value negates (reverses the sign of) the number
68
A First Book of ANSI C, Fourth Edition67 Negation (continued)
69
A First Book of ANSI C, Fourth Edition68 Operator Precedence and Associativity Two binary arithmetic operator symbols must never be placed side by side Parentheses may be used to form groupings –Expressions in parentheses are evaluated first Parentheses may be enclosed by other parentheses Parentheses cannot be used to indicate multiplication
70
A First Book of ANSI C, Fourth Edition69 Operator Precedence and Associativity (continued) Three levels of precedence: 1.All negations are done first 2.Multiplication, division, and modulus operations are computed next; expressions containing more than one of these operators are evaluated from left to right as each operator is encountered 3.Addition and subtraction are computed last; expressions containing more than one addition or subtraction are evaluated from left to right as each operator is encountered
71
A First Book of ANSI C, Fourth Edition70 Operator Precedence and Associativity (continued) Example: 8 + 5 * 7 % 2 * 4 = 8 + 35 % 2 * 4 = 8 + 1 * 4 = 8 + 4 = 12
72
A First Book of ANSI C, Fourth Edition71 Operator Precedence and Associativity (continued)
73
A First Book of ANSI C, Fourth Edition72 2.5 Variables and Declarations All data used in a computer must be stored and retrieved from the computer memory. In high-level language such as C, symbol names are used in place of actual memory address. These symbolic names are called variables. The term “variable” is used because the value stored in the variable can change or vary. For each name that the program uses, the computer keeps track of the memory address corresponding to that name
74
A First Book of ANSI C, Fourth Edition73 Variables and Declarations (continued) Variables are names given by programmers to computer storage Variable name usually limited to 255 characters Variable names are case sensitive
75
A First Book of ANSI C, Fourth Edition74 Variables and Declarations (continued)
76
A First Book of ANSI C, Fourth Edition75 Variables and Declarations (continued) num1 = 45; num2 = 12; total = num1 + num2; Assignment statements
77
A First Book of ANSI C, Fourth Edition76 Variables and Declarations (continued)
78
A First Book of ANSI C, Fourth Edition77 Declaration Statements Naming and specifying the data type that can be stored in each variable is accomplished using declaration statements Declaration statements within a function appear immediately after the opening brace of a function function name() { declaration statements; other statements; } Definition statements define or tell the compiler how much memory is needed for data storage
79
A First Book of ANSI C, Fourth Edition78 Declaration Statements (continued)
80
A First Book of ANSI C, Fourth Edition79 Declaration Statements (continued)
81
A First Book of ANSI C, Fourth Edition80 Declaration Statements (continued)
82
A First Book of ANSI C, Fourth Edition81 Declaration Statements (continued)
83
A First Book of ANSI C, Fourth Edition82 Declaration Statements (continued) Program 2.7 # include int main ( ) { float grade1; /* declare grade1 as s float variable */ float grade2; /* declare grade2 as s float variable */ float total; /* declare total as s float variable */ float average; /* declare average as s float variable */ grade1 = 85.5; grade2 = 97.0; total = grade1 + grade2; average = total/2.0; /* divide the total by 2.0*/ printf ( “ The average grade is %f\n”, average); return 0; }
84
A First Book of ANSI C, Fourth Edition83 Declaration Statements (continued) You can omit the f and let the compiler convert the double precision value into a float value when the assignment is made
85
A First Book of ANSI C, Fourth Edition84 Selecting Variable Names Make variable names descriptive Limit variable names to approximately 20 characters Start the variable name with a letter, rather than an underscore (_) In a variable name consisting of several words, capitalize the first letter of each word after the first
86
A First Book of ANSI C, Fourth Edition85 Selecting Variable Names (continued) Use variable names that indicate what the variable corresponds to, rather than how it is computed Add qualifiers, such as Avg, Min, Max, and Sum to complete a variable’s name where appropriate Use single-letter variable names, such as i, j, and k, for loop indexes
87
A First Book of ANSI C, Fourth Edition86 Character Variables Character variables are declared using the reserved word char. For example, the declaration char ch; declares ch to be a character variable.
88
A First Book of ANSI C, Fourth Edition87 Selecting Variable Names (continued) Program 2.8 # include { char ch; /* this declares a character variable */ ch = ‘a’; /* store the letter a into ch*/ printf ( “\nThe character stored in ch is %c. “, ch); ch = ‘m’; /* now store the letter m into ch */ printf ( “\nThe character now stored in ch is %c.”, ch); return 0; } The output is The character stored in ch is a. The character now stored in ch is m.
89
A First Book of ANSI C, Fourth Edition88 Selecting Variable Names (continued) Variables having the same data can always be grouped together and declared using a single declaration statement. For Example, the four separate declarations in the program 2.7 float grade1; float grade2; float total; float average; can be replaced by the single declaration statement float grade1, grade2, total, average;
90
A First Book of ANSI C, Fourth Edition89 Initialization Declaration statements can be used to store an initial value into declared variables –int numOne = 15; When a declaration statement provides an initial value, the variable is said to be initialized Literals, expressions using only literals such as 87.0 + 12 − 2, and expressions using literals and previously initialized variables can all be used as initializers within a declaration statement
91
A First Book of ANSI C, Fourth Edition90 Case Study: Temperature Conversion A friend of yours is going to Spain, where temperatures are reported using the Celsius temperature scale. She has asked you to provide her with a list of temperatures in degrees Fahrenheit, and the equivalent temperature in degrees Celsius. The formula relating the two temperatures is Celsius = 5/9(Fahrenheit − 32). Initially, you are to write and test a program that correctly converts the Fahrenheit temperature of 75 degrees into its Celsius equivalent.
92
A First Book of ANSI C, Fourth Edition91 Case Study: Temperature Conversion (continued)
93
A First Book of ANSI C, Fourth Edition92 Common Programming Errors Omitting the parentheses, (), after main Omitting or incorrectly typing the opening brace, {, that signifies the start of a function body Omitting or incorrectly typing the closing brace, }, that signifies the end of a function Misspelling the name of a function; for example, typing print() instead of printf() Forgetting to close a string passed to printf() with a double quote symbol
94
A First Book of ANSI C, Fourth Edition93 Common Programming Errors (continued) Omitting the semicolon at the end of each executable statement Forgetting to include \n to indicate a new line Forgetting to declare all the variables used in a program Storing an incorrect data type in a declared variable Using a variable in an expression before a value has been assigned to the variable
95
A First Book of ANSI C, Fourth Edition94 Common Programming Errors (continued) Dividing integer values incorrectly Mixing data types in the same expression without clearly understanding the effect produced Not including the correct conversion control sequence in printf() function calls for the data types of the remaining arguments Not closing the control string in printf() with a double quote symbol followed by a comma when additional arguments are passed to printf() Forgetting to separate all arguments passed to printf() with commas
96
A First Book of ANSI C, Fourth Edition95 Summary A C program consists of one or more functions A function is a C language description of an algorithm Many functions are supplied in a standard library of functions provided with each C compiler Simple C programs consist of the single function named main() An executable statement causes some specific action to be performed when the program is executed
97
A First Book of ANSI C, Fourth Edition96 Determining Storage Size The sizeof ( ) operator returns the number of the object or data type included in the parentheses. Unlike a function, the sizeof ( ) operator is an integral part of the C language itself. sizeof (num1) sizeof (int) sizeof (char)
98
A First Book of ANSI C, Fourth Edition97 Storage Size If the item in parentheses is a variable, as in the example sizeof (num1), sizeof ( ) returns the number of bytes of storage that the compiler has reserved for the variable; If the item in parentheses is a data type, such as int or char, sizeof ( ) will return the number of bytes of storage that the complier allocates for the given data type.
99
A First Book of ANSI C, Fourth Edition98 Program 2-9-1 # include int main ( ) { char ch; int num1; printf ( “Bytes of storage used by a character : %d”, sizeof (ch); printf ( \nBytes of storage used by an integer : %d”, sizeof (num1); return 0; }
100
A First Book of ANSI C, Fourth Edition99 The output is Bytes of storage used by a character : 1. Bytes of storage used by an integer : 2.
101
A First Book of ANSI C, Fourth Edition100 Addresses Three major items associated with every variable are the value stored in it, its address, and its data type. The value stored in a variable is referred to as the variable’s contents, while the address of the first memory location used for the variable constitutes its address. The number of memory locations used by the variable depends on the variable’s data type.
102
A First Book of ANSI C, Fourth Edition101 Programmers are usually concerned only with the value assigned to a variable (its contents) and give little attention to where the value is stored (its address). For example, consider Program 2.12.
103
A First Book of ANSI C, Fourth Edition102 Program 2.12 #include int main( ) { int num; num =22; printf(“ The value stored in num is %d.”, num); printf(“ \n The computer uses %d bytes to store this value”, sizeof (int)); return 0; }
104
A First Book of ANSI C, Fourth Edition103 The output displayed Program 2.12 when is run is The value stored in num is 22. The computer uses 2 bytes to store this value Program 2.12 displays both the number 22,which the value stored in the integer variable num(its contents), and the amount of storage used for an integer.
105
A First Book of ANSI C, Fourth Edition104 Determine the Address We can go further and obtain the address corresponding to the variable num. The address that is displayed corresponds to the address of the first byte set aside in the computer’s memory for the variable. To determine the address of num, we must use the address operator,&, which means the address of,directly in front of the variable name (no space between & and variable).
106
A First Book of ANSI C, Fourth Edition105 The Address Operator,& For example, &num means the address of num, &total means the address of total, and &price means the address of price. Program 2.13 uses the address operator to display the address of the value num.
107
A First Book of ANSI C, Fourth Edition106 Program 2.13 #include int main( ) { int num; num =22; printf(“num = %d The address of num is %p.”, num, &num); return 0; } The output of Program 2.13 is num = 22 The address of num is FFEO.
108
A First Book of ANSI C, Fourth Edition107 Clearly, the address output by Program 2.13 depends on the computer used to the program. Every time Program 2.13 is executed, however, it displays the address of the first byte used to store the variable num.
109
A First Book of ANSI C, Fourth Edition108 Note that the address is printed using the conversion control sequence %p. As illustrated by the output of Program 2.13, the address display is in hexadecimal notation. The display has no impact on how addresses are used internally to the program and merely provides us with a representation that is helpful in understanding what addresses are.
110
A First Book of ANSI C, Fourth Edition109 As we shall see, using addresses as opposed to only displaying them provides the C programmer with an extremely powerful programming tool. Addresses provide the ability to enter directly into the computer’s inner workings and access its basic storage structure. This gives the C programmer capabilities and programming power that are not available in most other computer languages.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.