char ch[] = ""

R

Radde

Hello,
why char ch[] = ""; allocated one byte of memory, even thogh i
created empty,,when i did sizeof(ch) gives 1 byte. What is it for?? Is
it of '\0' ???

Cheers..
 
C

Clark S. Cox III

Hello,
why char ch[] = ""; allocated one byte of memory, even thogh i
created empty,,when i did sizeof(ch) gives 1 byte. What is it for?? Is
it of '\0' ???

Yes, remember that even an empty string needs a terminating nul character.
 
J

Jaspreet

Radde said:
Hello,
why char ch[] = ""; allocated one byte of memory, even thogh i
created empty,,when i did sizeof(ch) gives 1 byte. What is it for?? Is
it of '\0' ???

Cheers..

Yes cheer up more, you are right. The string terminator is
automatically given space.
 
D

Default User

Radde said:
Hello,
why char ch[] = ""; allocated one byte of memory, even thogh i
created empty,,when i did sizeof(ch) gives 1 byte. What is it for?? Is
it of '\0' ???


Yes. Besides that, it's impossible to have objects of size 0, so it's
not possible to have an array with no elements.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top