What is o/p of below program in 64 bit system?
#include<stdio.h>
int main()
{
char *str1 = "embedded";
char str2[10] = "kernel";
printf("%lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", sizeof(str1), sizeof(str2), sizeof(str1 + 1), sizeof(str2 + 1), sizeof(*str1), sizeof(*str2), sizeof(str1[2]), sizeof(str2[3]), sizeof(&str1), sizeof(&str2));
}
Size of the pointer in 64 bit/8 byte system is 8.
str1 is char*. So, sizeof(str1) is 8.
str2[10] is array of char type of 10 bytes. sizeof(str2) prints sizeof array which is 10 bytes.
str1+1 is also char*. So, sizeof(str1+1) is 8.
str2 is char array type. but, str2+1 is treated as char pointer by the compiler. So, sizeof(str2+1) is also 8.
*str1 is dereferencing the str1 which is char 'e'(1 byte). So, sizeof(*str1) is 1.
*str2 is dereferencing the str2 which is char 'k'(1 byte). So, sizeof(*str2) is 1.
str1[2] = *(str1 + 2) which is character 'b' of 1 byte. So, sizeof(str1[2]) is 1.
str2[3] = *(str2 + 3) which is character 'n' of 1 byte. So, sizeof(str2[3]) is 1.
&str1 is the address of pointer str1 which is again a pointer value. So, sizeof(&str1) is 8.
&str2 is the address of char array str2 which is again a pointer value. So, sizeof(&str2) is 8.