Discussion
What will be the output of the following C code?
const char pla[] = "string1";
const char src[] = "string2";
printf("Before memmove place= %s, src = %s\n", pla, src);
memmove(pla, src, 7);
printf("After memmove place = %s, src = %s\n", pla, src);
Answer: A
Correct answer: Before memmove place= string1, src = string2 After memmove place = string2, src = string2
memmove copies 7 bytes from src to pla, that is the characters string2 without its terminating null - but pla already has a null in position 7, so it reads correctly as string2 afterwards. The source is not altered, which is why src is unchanged. (Note that both arrays are declared const, so writing to one is not something a program should do.)
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development