Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character (primitive type)

 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does a char variable have some default value? Like garbage value?
 
Henry Wong
author
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun Goenka wrote:Does a char variable have some default value? Like garbage value?


The default value for a char is a nul character -- which has an ascii value of zero.

Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's '\0', or simply 0 (as an integer literal).
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the default value for a field; all fields have default values of 0, which is interpreted as the null character for a char, false for a boolean, and null for all reference types.

Local variables and parameters do not have default values at all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic