Discussion
Assume that a character takes 1 byte. Output of following program?
#include <stdio.h>
int main()
{
char str[20] = "GeeksQuiz";
printf ("%d", sizeof(str));
return 0;
}
Answer: C
Correct answer: 20
sizeof reports the size of the array as declared, not the length of the string in it. The array was given 20 elements, so the answer is 20, of which the first ten hold "GeeksQuiz" and its null and the remaining ten are zero-filled. strlen(str) would give 9.
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