logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
03009867267499815390
#1 Posted : Thursday, March 11, 2010 1:19:00 AM(UTC)
Quote
03009867267499815390
Rank: Advanced Member

Reputation:

Joined: 2/16/2010(UTC)
Posts: 30


Sizeof array and string (in C language)?
lets say i have the following program:
String s1 = "Hello";
char[] s2 = {'H', 'e', 'l', 'l', 'o'};

and i try to find sizeof s1 and sizeof s2, what would be returned?
will both get the same answer, 5?

Edited by user Thursday, March 11, 2010 4:28:21 AM(UTC)  | Reason: Not specified

Sponsor

Soan
#2 Posted : Thursday, March 11, 2010 4:28:59 AM(UTC)
Quote
Soan
Rank: Administration

Reputation:

Joined: 1/9/2010(UTC)
Posts: 449
Man
Location: India

Was thanked: 1 time(s) in 1 post(s)
1) SizeOf(s1) will give you 6
2) SizeOf(s2) will give you 5.

1) Sizeof function will count the number of characters (5) + the null terminated character at the end of every string (1), hence answer is 6 .
2) As s2 is a character array and NOT a string, the sizeOf function will count the number of elements in the array and hence will return 5.
Quick Reply Show Quick Reply
Users browsing this topic
Guest (2)
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.