Discussion
What will be the output of the following C code?
const char str1[]="ABCDEF1234567";
const char str2[] = "269";
len = strcspn(str1, str2);
printf("First matching character is at %d\n", len + 1);
Answer: A
Correct answer: First matching character is at 8
strcspn returns the length of the initial segment of str1 containing no character from str2. Scanning ABCDEF1234567 against 269, the first seven characters ABCDEF1 are all absent from the set, and the eighth, 2, is present. So the function returns 7, and the program prints 7 + 1 = 8 - the 1-based position of the first match.
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