Machine-translated by Google. Questions are authored in English.
Top

Discussion

For the following code snippet:
char *str = "AllIndiaExams.in\0" "training classes";
The character pointer str holds reference to string:

  • A.AllIndiaExams.in
  • B.AllIndiaExams.in training classes
  • C.AllIndiaExams.in\0training classes
  • D.Syntax error

Answer: C

Correct answer: AllIndiaExams.in\0training classes

Adjacent string literals are concatenated at translation time, so "AllIndiaExams.in\0" and "training classes" become a single literal. The embedded \0 is retained as a byte within it, and the compiler still appends its own terminating null at the very end.

The pointer therefore refers to the whole of that storage. Printing it with %s would show only AllIndiaExams.in, because printf stops at the first null - but what str holds a reference to is the complete concatenated sequence, which is what the question asks.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.