3 votes 3 votes what is the output of the c program given below, #include<stdio.h> int main() { char pt[]="Gatelecture"; char qt[]="GATE"; int i=0; for( ;pt[i++]=qt[i++]; ); printf("%s",pt); } a. AeEe b. AaEe c. aAeE d. none of the above turendar asked Aug 13, 2018 edited Aug 13, 2018 by srestha turendar 1.3k views answer comment Share Follow See all 14 Comments See all 14 14 Comments reply Show 11 previous comments srestha commented Aug 13, 2018 reply Follow Share so , no segmentation fault only undefined behavior for different compiler 1 votes 1 votes Prince Sindhiya commented Aug 14, 2018 reply Follow Share @Minipanda I am getting" GaTe" as output And as Arvin said he is getting "AaEelecture" on online compiler so it should be undefined behaviour As different compiler are showing different output 1 votes 1 votes MiNiPanda commented Aug 14, 2018 reply Follow Share Yup 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes Undefined behavior in C. Answer is compiler dependent. Hence, the correct answer must be d) None of the above. gauravkc answered Aug 13, 2018 edited Aug 14, 2018 by gauravkc gauravkc comment Share Follow See all 19 Comments See all 19 19 Comments reply Show 16 previous comments Shaik Masthan commented Aug 14, 2018 reply Follow Share ASCII values of character returns if you are assigning them the integer right? ex:- int a='A'; ===> int a=65 (Both are equivalent if the range is <128) ASCII value of '\0' is 0 0 votes 0 votes gauravkc commented Aug 14, 2018 reply Follow Share Okk.. I don't know why but my laptop is also showing it will go into infinite loop. I'm using gcc 4.9.2 :/ The answer is compiler dependent I guess. Thanks for having a detailed conversation :) 0 votes 0 votes Shaik Masthan commented Aug 14, 2018 reply Follow Share note that, i shows undefined behavior.... therefore i may not assign the value as 4 in your compiler... at 4th index only we have null ===> if you didn't get that index to i, you are in infinite loop if your compiler shows infinite loop, then print i value in the loop....you should didn't encounter i=4 0 votes 0 votes Please log in or register to add a comment.