SparkNotes: Free Study Guides No Fear Shakespeare: The Bard made easy SparkCharts: Just the facts TestPrep: SAT, ACT, and more 101s: College texts condensed Subject Finder: Browse by subject SparkCollege: Get in! SparkLife: 100% study-free home_bottom home_top BN_link
 
 
 
◄ PREVIOUS
Pointers and Arrays

 

What Are Pointers?

 
 

Problems

 
Problem 3.1: Are pointers and arrays exactly the same thing? Can they be used identically? [Solution]
Problem 3.2: What does the following program do?
int main()
{
	char *p;
	for(p = "WNT"; *p; p++) printf("%c", *p - 1);
	printf("\n");
	return 0;
}
 
[Solution]
Problem 3.3: What does the following program do?
int main()
{
	char *p;
	for(p = "HAL"; *p; p++) printf("%c", *p + 1);
	printf("\n");
	return 0;
}
 
[Solution]
Problem 3.4: Will the following program compile? Will it run?
int main()
{
	char *p;
	p = p + 500;
	return 0;
}
 
[Solution]
Problem 3.5: 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;
}
 
[Solution]
Problem 3.6: 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. [Solution]
Problem 3.7: Give two names for the second element of the array: int spark[5]; [Solution]
 
Help | Feedback | Make a request | Report an error | Send to a friend

◄ PREVIOUS
Pointers and Arrays

 
 
 
 
 
 
Message Boards
Ask a question or start a discussion on the community boards.
  • C++ Programming
  • Computational Theory
  • Cryptography
  • Fast Algorithms
  • Games
  • Hardware
  • Java Programming
  • Perl Programming
  • Unix
  •  
     
     
    Study Guides
    Learn more about the subject you're studying with these related SparkNotes.
  • Why Use Pointers?
  • Review of Pointers
  •  
    SparkCharts
    A textbook's worth of information on an easy-to-read chart.
  • Java
  • Unix
  •  
     
     
    Contact Us | Privacy Policy | Terms and Conditions | About | Sitemap
    ©2008 SparkNotes LLC, All Rights Reserved.