Saturday, May 9, 2009

Difference between static char and const char in C?

Hey, is anyone out there aware of the difference between a static char and a const char in C?





I keep getting memory exceptions if I declare a const char (like I'm trying to write to the const char, but I'M NOT). But when I declare it static things work fine (and memory is not written over).





I assume both mean read-only, but is there any other difference? I'm just trying to track down why I'm getting such an odd error with const here.

Difference between static char and const char in C?
A constant is read-only, cannot be changed





A Static variable is read-write but is maintained (not erased) when the procedure/function in which it is declared exits.





so:


Proc A


Proc B


Proc B


Proc B


end





Proc B:


static aNum int


aNum = aNum + 1


print aNum


end





results in 1,2,3 for a static variable aNum
Reply:I'm not sure but I am interested myself in finding out the problem. Have you tried tek-tips.com? I'm sure one of the experts there will be able to help.


No comments:

Post a Comment