[check the code] : why does code 1 and code 2 prints 13 and 14 characters respectively? Why different? They should have the same
[check the code] : why does code 1 and code 2 prints 13 and 14 characters respectively? Why different? They should have the same value right since both of them takes '\0' input at last. Please Explain. CODE 1 : #include <stdio.h> int countLength(char arr[]); int main() { char name[] = "Anirban Mitra"; // 13 characters clearly printf("the no of characters are : %d", countLength(name)); return 0; } int countLength(char arr[]) { int count = 0; for (int i = 0; arr[i] != '\0'; i++) { count++; } return count; } PRINTS : the no of characters are : 13 CODE 2 : #include <stdio.h> int countLength(char arr[]); int main() { char name[100]; fgets(name, 100, stdin); //INPUT IS SAME AS THE PREV CODE (Anirban Mitra) printf("the no of characters are : %d", countLength(name)); return 0; } int countLength(char arr[]) { int count = 0; for (int i = 0; arr[i] != '\0'; i++) { count++; } return count; } PRINTS : the no of characters are : 14