2 2 votes int main() { char str[10]="GATE2018"; int length=strlen(str); str[length]='\0'; for(i=0;str[i];i++) printf("%c",str[i]); return 0; } Find the output? Programming in C programming-in-c programming + – srestha 1.1k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Angkit commented Oct 17, 2017 i edited by Angkit Oct 17, 2017 reply Follow flag GATE2018 ? 1 1 replyShare srestha commented Oct 17, 2017 reply Follow flag how? 0 0 replyShare joshi_nitish commented Oct 17, 2017 reply Follow flag it will give GATE2018 but there are few errors like 'i is undeclared' , '#include<string.h> is missing'.... 2 2 replyShare Angkit commented Oct 17, 2017 reply Follow flag srestha i have edited it , plz see now. 0 0 replyShare srestha commented Oct 17, 2017 reply Follow flag yes, compiler error will be answer I think 1 1 replyShare saipriyab commented Oct 17, 2017 reply Follow flag Here i is undeclared and the preprocessor directive in which strlen is present is not defined so these will throw errors. Otherwise if i is declared and #include<string.h>is present it will print GATE2018 0 0 replyShare Please log in or register to add a comment.
Best answer 3 3 votes -> we have to add int i; -> strlen(str) will return 8 ->BUT S[8] is already null // array starts from 0, So, GATE2018 is answer Angkit answered Oct 17, 2017 • selected Oct 17, 2017 by srestha Angkit comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes On execution of the above program gives output as: GATE2018 amaity answered Oct 17, 2017 amaity comment Share Follow 0 reply Please log in or register to add a comment.