What will be the output of the following program?

main( )

{

printf ( “Hello” ) ;

printf ( -3 + “WelCome” ) ;

}

Ans: The output is

Hellolo

As the strings in the printf( ) function are constant strings they are stored in a temporary buffer in adjacent locations. The first printf( ) prints ‘Hello’. In the second printf( ) the string “WelCome” acts as a pointer to the string. Hence pointer arithmetic is possible. On adding -3 the pointer would reach to the character ‘l’ after traversing ‘\0′ and ‘o’ in the reverse direction. Now the printf( ) starts printing the characters from ‘l’ onwards up to ‘\0′ of ‘Hello’. Hence the output.

Subscribe / Share

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

Powered by Yahoo! Answers