Program to verify my thoughts about array bounds checking.

#include <stdio.h>

int main()
{
char s[5];
int loc;

printf("Enter a string: ");
scanf("%s",s);

printf("Enter a location: ");
scanf("%d",&loc);

printf("Character stored in this location is: %c\nCharacter stored in the -1 location is: %c\nCharacter stored in the 10th location is: %c\n",s[loc],s[-1],s[10]);

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s