0
How this code's output is 12?
(assuming 8 byte pointers) const char firstname[]="dev"; const char* lastname = "programmer"; printf(" %lu\n", sizeof(firstname)+sizeof(lastname));
3 Antworten
+ 1
firstname is equal to 4 bytes
1 byte per char + the invisible end of line character '\0' = 4
lastname is a char pointer which we are assuming has 8 bytes.
sizeof() returns the size in bytes as a long unsigned int
4+8 = 12
+ 1
firstname is an array of type char with a size of string length + 1. If you change the length of the string the sizeof() will return a number accordingly. Try it.
https://www.google.com/amp/s/www.geeksforgeeks.org/whats-difference-between-char-s-and-char-s-in-c/amp/
+ 1
@ChaoticDawg
ahh...thank you..i .was not aware of that. I'll remove my initial comment as it was incorrect.