Home arrow C programming arrow A TUTORIAL ON POINTERS AND ARRAYS IN C - Part 2

Language Translator

Hacking Zone

Hacking Tools
Attacking

Configure Windows

Windows Configuration

Novels

Mix Novels

Human Personality

Body Language
A TUTORIAL ON POINTERS AND ARRAYS IN C - Part 2 PDF Print E-mail
Written by Hemanshu Patel   
Saturday, 29 December 2007
Article Index
A TUTORIAL ON POINTERS AND ARRAYS IN C - Part 2
Page 2
Page 3
Page 4
Page 5
Page 6

With that in mind, look at the following program:


------------ program 5.2 ---------------------
/* Program 5.2 from PTRTUT10.HTM               6/13/97 */
#include <stdio.h>
#include <string.h>
struct tag{                                /*  the structure type */
     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;                      /* define the structure */
void show_name(struct tag *p);             /* function prototype */
int main(void)
{
     struct tag *st_ptr;                   /* a pointer to a structure */
     st_ptr = &my_struct;                  /* point the pointer to my_struct */
     strcpy(my_struct.lname,"Jensen");
     strcpy(my_struct.fname,"Ted");
     printf("\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\n", p->age);
}
-------------------- end of program 5.2 ----------------


Again, this is a lot of information to absorb at one time. The reader should compile and run the various code snippets and using a debugger monitor things like my_struct and p while single stepping through the main and following the code down into the function to see what is happening.

 



Last Updated ( Monday, 06 October 2008 )
 
< Prev   Next >
Your Ad Here

Donate us!!

Enter Amount:

RSS socialnet

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits