2 votes 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 asked Oct 17, 2017 srestha 434 views answer comment Share Follow See all 6 Comments See all 6 6 Comments reply Show 3 previous comments Angkit commented Oct 17, 2017 reply Follow Share srestha i have edited it , plz see now. 0 votes 0 votes srestha commented Oct 17, 2017 reply Follow Share yes, compiler error will be answer I think 1 votes 1 votes saipriyab commented Oct 17, 2017 reply Follow Share 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 votes 0 votes Please log in or register to add a comment.
Best answer 3 votes 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 See all 0 reply Please log in or register to add a comment.
2 votes 2 votes On execution of the above program gives output as: GATE2018 amaity answered Oct 17, 2017 amaity comment Share Follow See all 0 reply Please log in or register to add a comment.