In my code below:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define BLOCKSIZE 256;
int main()
{
char text[BLOCKSIZE];
char *new_line;
new_line=strcpy(text,"hello");
int i;
for(i=0;i<sizeof(text)/sizeof(char);i++)
{
printf("%c",*(new_line+i));
}
return 0;
}
I am trying to print the string "hello" on screen using a pointer which points to the address of the char array text. But in my code I get the string hello continued by some garbage values and then leads to core dumped. Can anyone show me the right way? Thanks

char *ptr = text; while (*ptr) printf("%c",*ptr++);Your code is attempting to print 256charof"hello"which is only 6charlong. GTG*ptrtakes the pointerptrand reads what it points to: somechar. The value of thatcharis tested inwhile(*ptr)for truth-ness (is it non-zero)? So if the end of the string is not reached (the'\0'), the while loop continues.