What Are Pointers?


Problems

Problem : Are pointers and arrays exactly the same thing? Can they be used identically?


Problem : What does the following program do?


int main()
{
	char *p;
	for(p = "WNT"; *p; p++) printf("%c", *p - 1);
	printf("\n");
	return 0;
}


Problem : What does the following program do?


int main()
{
	char *p;
	for(p = "HAL"; *p; p++) printf("%c", *p + 1);
	printf("\n");
	return 0;
}


Problem : Will the following program compile? Will it run?


int main()
{
	char *p;
	p = p + 500;
	return 0;
}


Problem : Does the following code compile? What does it do?


int main()
{
	char word[] = ;
	char *spark[10];
	int i;
	for(i=0; i<10; i) spark[i] = word + (i % 5);
	for(i=0; i<10; i) printf("%c", *spark[i]);
	printf("\n");
	return 0;
}


Problem : Write the function: int strlen(char *str) or int strlen(char str[]) that takes a string and returns its length. Write it once using pointer notation and once using array notation.


Problem : Give two names for the second element of the array: int spark[5];


Take a Study Break

Green YOUR SCHOOL!

Click here to get involved with dosomething.org!

John Krasinski's BIG MIRACLE

Click to watch the trailer and read exclusive star interviews!

Do you like Anna?

Read Dear Albert... from ANNA's perspective!

BATTLESHIP, the movie

Here's why we're super jazzed about it.

Do energy juices actually work?

Our blogger puts 'em to the test!


The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps