Basic and Advance C Question:

Download Job Interview Questions and Answers PDF

Why does not
strcat(string, "!");
work?

C Programming Interview Question
C Programming Interview Question

Answer:

There is a very real difference between characters and strings, and strcat concatenates strings.
A character constant like '!' represents a single character. A string literal between double quotes usually represents multiple characters. A string literal like "!" seems to represent a single character, but it actually contains two: the ! you requested, and the which terminates all strings in C.
Characters in C are represented by small integers corresponding to their character set values Strings are represented by arrays of characters; you usually manipulate a pointer to the first character of the array. It is never correct to use one when the other is expected. To append a ! to a string, use
strcat(string, "!");

Download C Programming Interview Questions And Answers PDF

Previous QuestionNext Question
What is the right type to use for Boolean values in C? Is there a standard type? Should I use #defines or enums for the true and false values?Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?