Skip to content

Instantly share code, notes, and snippets.

@figengungor
Last active December 24, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save figengungor/6846837 to your computer and use it in GitHub Desktop.
Save figengungor/6846837 to your computer and use it in GitHub Desktop.
Pointer
#include<stdio.h> //for printf
#include<stdlib.h> //for system("pause")
int main(int argc, char* argv[])
{
int ages[] = {30, 28, 31, 35};
char *names[] = {"Dexter", "Debra", "Hannah", "Masuka"};
int count = sizeof(ages)/sizeof(int);
//setup pointers
int *cur_age = ages;
char **cur_name = names; //a pointer to (pointer to a char)
int i=0
//looping with index i
for(i=0; i<count; i++)
{
printf("%s is %d years old.\n", names[i], ages[i]);
}
//looping with pointers
for(i=0; i<count; i++)
{
printf("%s is alive for %d years.\n", *(cur_name+i), *(cur_age+i) )
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment