What will happen with the following code? #include <string.h> main() { char str[ ] = "Exforsys" ; strcat ( str, '!' ) ; }

On the outset users might see the command strcat and think that the string str having value “Exforsys” would get concatenated with ‘!’. But this will not happen


Surprised to hear this!!!!!


But there is an interesting fact to know in the above code. The string handling function strcat() concatenate only string and does not concatenate characters.


In other words string which are collection of characters and which is represented in C programming language as array of characters can be concatenated using the function strcat(). But in the above code the second parameter represented in strcat() function is not string but character represented s ‘!’ and so cannot be sued in strcat().


So in summary to make the above code work the second parameter must be represented as “!” to make it as string and if such a change is made the string “Exforsys” gets concatenated with “!” to give Exfrosys!

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

himani

  • Aug 30th, 2007
 

it will generate an error message that 

" invalid use of function"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions