I am new to pointers, please let me know how can i print the entered character.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *ptr;
ptr = malloc(32 * sizeof(char));
*ptr = 'h';
ptr++;
*ptr = 'e';
ptr++;
*ptr = 'l';
ptr++;
*ptr = 'l';
ptr++;
*ptr = 'o';
ptr++;
*ptr = '\n';
printf("value entered is %s\n", ptr);
return 0;
}
I want to print hello
ptris no longer pointing to the original location; Andcharstrings in C are really called null-terminated byte strings. This null-terminator is incredibly important for all string handling (including usingprintfwith the%sformat) to know where the string ends.ptrright after malloc, then do all arithmetic on the temporary pointer.