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

SparkLife

What's your Pretty Little Liars name?

Take this quiz to find out!

SparkLife

Which young actress just got married?

Click to find out!

SparkLife

Cat bearding WINS THE INTERNET

Have you seen this yet?

SparkLife

Scary movies with funny posters

These. Are. Hilarious.

Geek out!

The MindHut

Geeky Actors: Then and Now

Travel back in time!

The MindHut

Villains We Want These Actresses to Play

From super cute to super bad!

The MindHut

10 Movies Better Than Their Books

What do you think?

The MindHut

Summer Movie Open Thread

Leave your thoughts here!

The MindHut

12 Scientific Inaccuracies in Into Darkness

What did Star Trek get wrong?

The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps