Home / Blue J / How to Null a string or empty a string array

How to Null a string or empty a string array

Null a String/ Empty a string array
Null a string in C using pointer string or array string. Many times the string is nullified assigning arr[0]=’\0′ but this will not nullify the array as only the first index will be NULL.


1. Null a string using pointer string.
char *ptr="hello";
printf("%s" , ptr);
printf("\n %s  and  %s ",ptr,ptr+1);


TO show that array/pointer is not actually empty or null the first array null but the rest of array characters are still on the same address.

printf(“%s and %s”, ptr,ptr+1);


  and ello

2. Null a string using array string

Null a string using an array is not efficient as though the first index is nullified but the rest of the characters still have the same address.

char arr[30]="hello";
printf("null string=%s and %c",arr,arr[2]);



null string= and l


Check Also

program for display lower triangular matrix in java

What is Lower Triangular Matrix? Lower Triangular Matrix is if all the elements above the main ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.