C/Variables: Diferenzas entre revisións

Contido eliminado Contido engadido
Gallaecio (conversa | contribucións)
Continúo a tradución (sigo traducindo, pero gardo por se acaso)
Gallaecio (conversa | contribucións)
Liña 152:
 
==Calificador <tt>const</tt>==
Cando se usa o cualificador <tt>'''const'''</tt>, a variable declarada debe inicializarse ao declararse. A partires de entón non pode cambiar o seu valor.
 
Mentres que a idea dunha variable que nunca cambia pode non parecer moi útil, hai boas razóns para usar <tt<const</tt>. Por un lado, moitos compiladores poden efectuar algunhas optimizacións nos datos ao sabes que estes nunca van cambiar. Por exemplo, se necesitas o valor de &pi. Nos teus cálculos, podes declarar a variable <tt>const</tt> de <tt>pi</tt>, de xeito que un programa ou outra función escrita por outra persoa non pode cambiar o valor de <tt>pi</tt>.
When the <tt>'''const'''</tt> qualifier is used, the declared variable must be initialized at declaration. It is then not allowed to be changed.
 
While the idea of a variable that never changes may not seem useful, there are good reasons to use <tt>const</tt>. For one thing, many compilers can perform some small optimizations on data when it knows that data will never change. For example, if you need the value of &pi; in your calculations, you can declare a const variable of <tt>pi</tt>, so a program or another function written by someone else cannot change the value of <tt>pi</tt>.
 
NoteTeña thaten aconta Standardque conformingun compilercompilador mustque issuesiga a warningnormativa ifestándar andebería attemptamosar isunha madealerta toavisando changedo aintento de cambiar o valor dunha variable <tt>const</tt>, variablemais -e butdespois afterde doingfacelo soo thecompilador compileré islibre freede toignorar ignoreo thecualificador <tt>const</tt> qualifier.
 
== Magic numbers ==