Explanation of sizeof() with various data types in C++ -
additional question (1 point): assume using 32-bit windows operating systems , c/c++ programs. please estimate sizeof() follows (unit: byte)
• char str[] = “hello” ; • char *p = str ; • int n = 10; please calculate: • sizeof ( str ) = __________ • sizeof ( p ) = __________ • sizeof ( n ) = __________
hello all,
i trying wrap mind around fundamental concept in c++. tell think correct answers see if on right track. first one, sizeof(str), believe 6 bytes total. noticed pattern other problems there 1 byte added these types of strings. (5 letters +1). question is, "+1" from? second 1 down, referring size of pointer,p, correct? 4 bytes in size? finally, third one, believe referring size of int, n. know ints of size 4 bytes correct? mean ints 4 bytes regardless if 10 or 10000, or other number. other important info on topic appreciated , accepted open arms! thanks!
char str[] = "hello" ;
is equivalent to:
char str[] = {'h', 'e', 'l', 'l', 'o', '\0'};
the standard guarantees sizeof(char)
1
. hence sizeof(str)
6
.
the size of pointer , int
platform dependent.
Comments
Post a Comment