Doubt regarding this code please clear this. The following program giving strange output so please help what is happenig with this code what is error in this. Code: #include<stdio.h> #include<string.h> main() { char str1[100],str2[100]; int i.length1,length2; printf("Enter the first string"); gets(str1); length1 = strlen(str1); printf("Enter second string \n"); gets(str2); length2 = strlen(str2); for(i=0;i<length2;i++) str1[length1++] = str2[i]; str1[length1+length2] = '\0'; printf("concatenated string is %s",str1); getch(); } And please also tell me why this & is not required while accespting string using scanf() statement. Regards Vivek Nayak
First I really doubt your program will compile because it has some syntax errors. Second & is not required for strings because you are already passing the address of the character array
you are not passing the address of character array here means that the name of an array is itself a pointer( refer to the property of an array)
As you said if & is not required to accept string array. then why do we need & sign for integer array. please kindly reply for this. in program what i sent for you it gets compiled but gives wrong output. please give the exact reason for the same. Thank you for the last reply. Regards Vivek Nayak Code: #include<stdio.h> #include<string.h> main() { char str1[100],str2[100]; int i,length1,length2; printf("Enter the first string"); gets(str1); length1 = strlen(str1); printf("Enter second string \n"); gets(str2); length2 = strlen(str2); for(i=0;i<length2;i++) str1[length1++] = str2[i]; str1[length1+length2] = '\0'; printf("concatenated string is %s",str1); getch(); }