What is the output of the below code?
#include<stdio.h>
void main()
{
char *arr1 = "TalentEve";
char arr2[] = "Embeddeddesignblog";
printf("%d\n%d\n",sizeof(arr1),sizeof(arr2));
}
---------------------------------------------------------------------
The above code tests two scenarios:
1. Size of the pointer
2. Size of the array
---------------------------------------------------------------------
arr1 is a pointer which holds the address of "TalentEve"
When sizeof(arr1) is printed, the size of the pointer is printed
So, sizeof(arr1) calculates memory address size and depends on the system size whether it is 32-bit or 64-bit
arr2 is an array which is assigned a string "Embeddeddesignblog"
sizeof(arr2) calculates the size of the string which is 19. This includes NULL character as well.
Note that size of character is 1 byte and size of int is 4 bytes
0 Comments