Products
Services
Contact Us

Scripts: c :: Pointers :: Library Article #1

Developer's Section

Using Pointers in C
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3521)
Favorites:

Brief explanation on how to create Pointers

A pointer in C is a reference to a memory location in your computer. Pointer can be of type int or string, and depending on how you use it you can change the refence.

Let's take a look at Strings with Pointers:

 Code Snippet 1

#include <stdio.h>

main(argc, argv, envp) {

char myString[40] = "This is my new String";

char *myPointer; //pointer of type char
                          //referenced to a memory location
myPointer = &myString[0]; //copy address location of
                                         //first char to myPointer

*myPointer = "Assign Pointer to a new variable"; 

//output result

printf("the value of myPointer is: %d\n",*myPointer); 

}



Now, here is how you can use Integers with Pointers:

 Code Snippet 2

#include <stdio.h>

main(argc, argv, envp) {

    int myInt = 53497;  //an Integer

    int *myIntegerPointer;  //integer pointer

    myIntegerPointer = &myInt;  //initialize

 
    *myIntegerPointer = 24742;  //reset pointer at
                                               //memory location
                                               //put new value 24742
      
      printf("myInt is equal to %d\n", myInt);
}


See other Scripts in Pointers

Submit Your Scripts:

If you would like to have your C scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]