+ 1

Why we type this for to code str3[j]='\0' ??? And have a look to the code guys😅😅

#include<stdio.h> #include<string.h> int main() { int i=0,j=0; char str1[50],str2[50],str3[50]; printf("Enter the string 1 = "); gets(str1); printf("Enter teh string 2 = "); gets(str2); while(str1[i]!='\0'){ str3[j]=str1[i]; i++; j++; } i=0; while(str2[i]!='\0') { str3[j]=str2[i]; i++; j++; } str3[j]='\0'; puts(str3); return 0; }

6th Jun 2021, 12:45 PM
Charizard
Charizard - avatar
2 Respostas
+ 4
“\0” is the null termination character. It is used to mark the end of a string. Without it, the computer has no way to know how long a group of characters (string) goes. In C/C++ it looks for the Null Character to find the end of a string. https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.quora.com/What-is-use-of-0-in-the-C-programming-language&ved=2ahUKEwjC-aSjjoPxAhVzwTgGHS6oD7AQFjABegQIBBAF&usg=AOvVaw1SFPI0gE3MPCWjlCDwSa2k
6th Jun 2021, 1:25 PM
Abhiyantā
Abhiyantā - avatar
+ 1
Bluebuds_ckmpany You might as well could use the ASCII value of the null character, i.e., 0. That'd save some time.
6th Jun 2021, 2:24 PM
Calvin Thomas
Calvin Thomas - avatar