Discussion
What will be the output of the program ?
#include <stdio.h>
#include <string.h>
int main()
{
static char str1[] = "dills";
static char str2[20];
static char str3[] = "Daffo";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
printf("%d\n", i);
return 0;
}
Answer: D
Correct answer: 0
Work outwards. strcpy(str2, str1) puts "dills" into str2 and returns it; strcat(str3, ...) appends that to "Daffo", making "Daffodills". Comparing that with "Daffodills" gives 0, since the strings are identical. (str3 is static and sized by its initialiser, so this relies on there being room after it - not something to imitate.)
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