Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

C Pointers

August 28, 2013 Posted by: GPA Views: 766 0 comments

Problem

What Are Pointers? Write simple example using pointers?

Solution

In this article, we discuss one of the most important and useful features of the C programming language,the pointer. Pointers are variables whose values are memory addresses of another variables. Pointers, as all variables, must be defined before they can be used:

int *pointerExample; 

Here int - C type; 

asterisk * is used to declare a pointer;

pointerExample is the name of the pointer variable.

Example:

   

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
     int somevalue =5 ;
     int *pointerExample;  //pointer variable declaration
     pointerExample = &somevalue;//store address of var in pointer variable
     //show result
     printf("Address of somevalue variable: %x\n", &somevalue);
     printf("Address stored in pointerExample variable: %x\n", pointerExample );
     printf("Value of *pointerExample variable: %d\n", *pointerExample );
     system("PAUSE"); //delay
   return 0;
}

Output

C Pointers

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe