#include <stdio.h>
#include <string.h>

int main()
{
int A;       // This defines a interger number A.

int * ptrA;    // This defines a pointer.    It is called ptrA.    It is capable of pointing to a interger number.

ptrA = & A;     //   this takes ptrA and points it to interger A.

A = 235;   //     this sets the value of A TO 235.

// To print A

printf(" A = %d    \n", A );   // One way toprint 235 
printf(" A = %d    \n", * ptrA );  // Another way to print 235 or print the contents pointed to by ptrA.  
printf(" A = %d    \n", * &A );   // A third way of printing 235   it prints the contents of what  is pointed to by ptrA.
// now moving on to strings....

char name[10] = "charley"; //   charley is a string.

char *N ;  // we define  N it is a pointer capable of pointing to  a string.  

N = &name[0] ;  // now N points to a string ( it points to the first letter)   ;

printf("\n the name is %s \n",  name );  // note that name represents the entire string    this prints "charley"  
printf(" the name is %s \n",  & *N );  // note that & *N represents the entire string     this is another way to print "charley"

return 0;
}

Return to previous page