Discussion
What will be the output of the program ?
#include <stdio.h>
int main()
{
char str[7] = "IndiaBIX";
printf("%s\n", str);
return 0;
}
Answer: C
Correct answer: Cannot predict
The initialiser needs nine bytes - eight characters and a null - but the array has only seven. A compiler will warn, and where it accepts the code it truncates, leaving IndiaB with no terminating null. Printing that runs past the end of the array, so what appears depends on whatever bytes follow.
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