cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
problem with sizeof()
problem with sizeof()
Oct 21, 2012 at 9:07am UTC
geekocoder
(103)
Why am i getting the output of the followiing code as
1
even if there is no character between the double quotes???
1
2
3
4
5
6
#include <stdio.h>
int
main() { printf(
"%d"
,
sizeof
(
""
)); getchar(); }
Last edited on
Oct 21, 2012 at 9:09am UTC
Oct 21, 2012 at 9:57am UTC
DesiredNote
(238)
Why? Because string literals are still null-terminated, just like strings and character arrays. That still takes up a character which is equal to one byte.
Last edited on
Oct 21, 2012 at 10:16am UTC
Topic archived. No new replies allowed.