Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Example 1 to display array values and address of an array using pointers

Posted By: Meryl Schmidt     Category: C Programming     Views: 4053

Example 1 to display array values and address of an array using pointers.

Code for Example 1 to display array values and address of an array using pointers in C Programming

#include <stdio.h>
void printarr(int a[]);
void printdetail(int a[]);
void print_usingptr_a(int a[]);
main()
{
int a[5];
int *b;
int *c;
for(int i = 0;i<5;i++)
{
a[i]=i;
}
printarr(a);
*b=2;        \\ A
b++;        \\ B 
*b=4;        \\ C
b++;
*b=6;        \\ D
b++;
*b=8;        \\ E
b++;
*b=10;
b++;
*b=12;
b++;
a=c; //error    \\J
printarr(a);    


}
void printarr(int a[])
{
for(int i = 0;i<5;i++)
{
printf("value in array %d\n",a[i]);
}
}
void printdetail(int a[])
{
for(int i = 0;i<5;i++)
{
printf("value in array %d and address is %16lu\n",a[i],&a[i]);
}
}

void print_usingptr_a(int a[])
{

for(int i = 0;i<5;i++)
{
printf("value in array %d and address is %16lu\n",*a,a);    \\ F
a++; // increase by 2 bytes        \\ G
}
}
  
Share: 



Meryl Schmidt
Meryl Schmidt author of Example 1 to display array values and address of an array using pointers is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!