Discussion
#include <stdio.h>
int main()
{
char *str1 = "GeeksQuiz";
char str2[] = "GeeksQuiz";
printf("sizeof(str1) = %d, sizeof(str2) = %d",
sizeof(str1), sizeof(str2));
return 0;
}
Answer: B
Correct answer: sizeof(str1) = 4, sizeof(str2) = 10
str1 is a pointer, so sizeof gives the size of a pointer - 4 bytes on a 32-bit build. str2 is an array, so sizeof gives the whole array: 9 characters plus the terminating null, 10. The initialiser looks identical in the two cases, which is what makes this worth knowing.
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