Switch to full style
C++ code examples
Post a reply

Arrays using Pointers

Thu Nov 13, 2008 2:53 pm

Define integers arrays with pointers
cpp code
#include <stdio.h>

void main()
{
int Array[3];
Array[0] = 10;
Array[1] = 20;
Array[2] = 30;

int *pArray;
pArray = &Array[0];

printf("p The value pointed : %d\n", *pArray);
}


Another example:
cpp code
#include <stdio.h>

main()
{
int fred[] = { 10, 20, 30, 40, 50, 60, 70 };
int *joe = fred + 5;
int *alex = joe - 3;

fred[0] = 99;
joe[0] = 199;
alex[1] = 299;

int m;
for(m = 0; m < 7; m++) printf("%4d", m);
printf("\n");
for(m = 0; m < 7; m++) printf("%4d", fred[m]);
printf("\n");
}



Another example:
cpp code
#include <stdio.h>

void main()
{
int Array[3];
Array[0] = 10;
Array[1] = 20;
Array[2] = 30;

int *pArray;
pArray = &Array[0];

printf("p Value at this %d\n", *pArray);
pArray++;
printf("p Value at this%d\n", *pArray);
pArray++;
printf("p Value at this %d\n", *pArray);
}




Post a reply
  Related Posts  to : Arrays using Pointers
 How to use pointers and what it means     -  
 Basic Pointers     -  
 Swap Using Pointers     -  
 Types of Pointers in C++     -  
 The using of pointers between two variables (Swaping)     -  
 pointers to derived types     -  
 Passing Pointers to function example     -  
 References confuse me. How do they differ from pointers?     -  
 Concept of arrays     -  
 Defining arrays in ASP     -  

Topic Tags

C++ Arrays