Skip to content

Instantly share code, notes, and snippets.

@mashcom
Created June 16, 2014 11:56
Show Gist options
  • Save mashcom/edcd86f6d99a327ac9f6 to your computer and use it in GitHub Desktop.
Save mashcom/edcd86f6d99a327ac9f6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char * argv[]){
int ages[]={12,56,23,34,51};
char *name[]={"blessing","tawanda","prosper","simba","titi"};
int count=sizeof(ages)/sizeof(int);
int i=0;
//retrieve names using for loop
for(i=0;i<count;i++){
printf(" %s is %d years old \n",name[i],ages[i]);
}
printf("-------------------going to the pointer-------------------------------\n");
//retrieve using pointers
int *cur_ages=ages;
char **cur_name = name;
for(i=0;i<count;i++){
printf("%s is %d years old \n",*(cur_name+i),*(cur_ages+i));
}
printf("----------------------------starting 2nd pointer----------------------------\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment