Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
char str1[] = "India";
char str2[] = "BIX";
char *s1 = str1, *s2=str2;
while(*s1++ = *s2++)
printf("%s", str1);
printf("\n");
return 0;
}
Answer: B
Correct answer: BndiaBIdiaBIXia
The loop copies str2 into str1 one character at a time, printing the whole of str1 after each copy, and stops when the assigned value is the terminating null.
After copying B, str1 reads Bndia; after I, BIdia; after X, BIXia. The three prints concatenate to BndiaBIdiaBIXia. Note that the assignment's value is what controls the loop, which is the standard C string-copy idiom.
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