 <stdio.h> defined,).
==================================================================
CHAPTER 2: Pointer types and Arrays
Okay, defined as pointing to an
integer, 2 bytes would be copied, if a long, 4 bytes would be
copied. Similarly for floats and doubles the appropriate number
will be copied. But, defining the type that the pointer points
to permits a number of other interesting ways a compiler can
interpret code. For example, consider a block in memory
consisting if ten integers in a row. That is, 20 bytes of memory
are set aside to hold 10 integer. 2 to
ptr instead of 1, so the pointer "points to" the _next_
_integer_, at memory location 102. Similarly, were the ptr) (i.e. 2 for an integer, 4 for a long,
etc.).:
------------------------------------------------------
#include <stdio.h>.
==================================================================
CHAPTER 3: Pointers and Strings
The Pascal or (most versions
of) Basic, strings are treated differently from arrays. define two character pointers
and show the string on the screen. We then "point" the ponter.
Note that, initialize it also with
something like:
strB[80] = "12345678901234567890123456789012345678901234567890"
where the number of digits used is greater than the length of
strA and then repeat the single stepping procedure while watching
the above variables. Give these things a try!. On the other hand, note that
_automatically_ marked with a special value like the nul
character. We could implement a version that relied on a
special value to identify the end. For example, we could
copy an array of postive.
Note that this permits using functions to manipulate very.
Note that];
this gets interpreted by C to read:
*.
==================================================================
CHAPTER 5: Pointers ------------------
#include <stdio.h>
#include <string.h>
struct tag{
char lname[20]; /* last name */
char fname[20]; /* first name */
int age; /* age */
float rate; /* e.g. 12.75 per hour */
};
struct tag my_struct; /* declare the structure m_struct */
int main(void)
{
strcpy(my_struct.lname,"Jensen");
strcpy(my_struct.fname,"Ted");
printf("\n%s ",my_struct.fname);
printf("%s\n",my_struct.lname);
return 0;
}
-------------- end of program 5.1 --------------
Now, this particular structure is rather small compared to
many used in C programs. To the above we might want to add:
date_of_hire; there must be
enough room on the stack to hold it. define such a pointer
with the definition:("\n%s ",my_struct.fname);
printf("%s\n",my_struct.lname);
my_struct.age = 63;
show_name(st_ptr); /* pass the pointer */
return 0;
}
void show_name(struct tag *p)
{
printf("\n%s ", p->fname); /* p points to a structure */
printf("%s ", p->lname);
printf("%d.
==================================================================
CHAPTER 6: Some more on Strings, and Arrays of Strings '\0'."
multi[1] = "abcdefghij"
multi[2] = "ABCDEFGHIJ"
multi[3] = "9876543210"
multi[4] = "JIHGFEDCBA"
with individual elements being, for example:
multi[0][3] = '3'
multi[1][7] = 'h'
multi[4][0] = 'J'
Since arrays are to be contiguous, our actual memory block
for the above should look like:
"0123456789abcdefghijABCDEFGHIJ9876543210JIHGFEDCBA"
Now, the compiler knows how many columns are present in the
array so it can interpret multi + 1 as the address of the 'a' row 3
When you use pointers, you must give them the respect they deserve. If
you do not code carefully, and you make an off-by-one error, your
program will behave very badly. This is many times worse with malloc()ed
memory, because some implementations will store their internal data right after
your data, making it so your little error only shows up at
the next malloc(), which
can be in a totally unrelated section of code.
On the other hand, a correctly used pointer is a wonderful thing. You
can run along a string with speed and ease using a pointer. You can
build efficient, intricate webs of inter-linkage in memory. And then there's
the function pointer, which allows amazing flexibility when used
with libdl. A pointer is a Good Thing, but don't mistreat it, or it will
become a Very Bad Thing.
Point"er (?), n.
One who, or that which, points.
The hand of a timepiece
One of a breed of dogs trained to stop at scent of game, and with the nose point it out to sportsmen
The two stars (Merak and Dubhe) in the Great Bear, the line between which points nearly in the direction of the north star
Diagonal braces sometimes fixed across the hold.
© Webster 1913.
Log in or register to write something here or to contact authors.
Need help? accounthelp@everything2.com