Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int *pi;
for(*pi=0; *pi<5; *pi++)

What is the logical mistake in this code? Or is there any false?
Posted
Updated 11-Nov-10 9:44am
v2

Firstly, try assigning a value to pi:
int* pi = &integerVariable;

Then, try incrementing the content, rather than the pointer:
(*pi)++ instead of *pi++
 
Share this answer
 
You have declared pi as a pointer to integer, but you have not initialized it, then it points to a random address; then in the for loop you are using the random address that pi holds. This could cause serious problems as memory corruptions, memory protection faults, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900