Ripping out all the irrelevant stuff and indenting your code:
#include<stdio.h>
int main()
{
char s1[]="Hello";
char *s3 = s1;
for(; *s3; )
{
printf("%c",*s3);
s3++;
}
}
If you run this, it prints the content of s1: "Hello" which is what you expect.
The only way to get an "infinite" output using
S3 + 1
would be if the output was "HHHHHHHHHHHHHHHHHHHH..." and your code looked like this:
#include<stdio.h>
int main()
{
char s1[]="Hello";
char *s3 = s1;
for(; *s3; )
{
printf("%c",*s3);
s3 + 1;
}
}
And that would be because
s3 + 1
returns a value one greater than
s3
started with, but doesn't alter the content of
s3
at all - for that you'd need to do this:
#include<stdio.h>
int main()
{
char s1[]="Hello";
char *s3 = s1;
for(; *s3; )
{
printf("%c",*s3);
s3 = s3 + 1;
}
}
Personally, I'd rewrite your code like this:
#include<stdio.h>
int main()
{
char s1[]="Hello";
for(char *s3 = s1; *s3; s3++)
{
printf("%c",*s3);
}
}