Discussion
Point out the error in the following program.
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "Learn through IndiaBIX\0.com", str2[120];
char *p;
p = (char*) memccpy(str2, str1, 'i', strlen(str1));
*p = '\0';
printf("%s", str2);
return 0;
}
Answer: D
Correct answer: No error and prints "Learn through Indi"
memccpy copies bytes until the given character has been copied, and returns a pointer to the byte after it - or NULL if the character never appeared. The first lower-case 'i' in the string is the one in Indi, so the copy stops there, the returned pointer is used to write the terminating null, and the result is Learn through Indi.
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