Home > SparkNotes > Computer Science Study Guides > What Are Pointers? >

sparknotes

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];