[go: up one dir, main page]

0% found this document useful (0 votes)
9 views6 pages

C 12

Uploaded by

hlemorvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

C 12

Uploaded by

hlemorvan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
06/12/2028 06:37 Constants 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools C Constants [crv] Looe | Constants If you don't want others (or yourself) to change existing variable values, you can use the const keyword. This will declare the variable as "constant", which means unchangeable and read- only: Example const int myNum = 15; // myNum will always be 15 myNum = 10; // error: assignment of read-only variable ‘myNum’ You should always declare the variable as constant when you have values that are unlikely to change: Example const int minutesPerHour = 60; const float PI = 3.145 nitpsilmww:vdschools.comiele_constants.pnp 6 06/12/2028 06:37 Constants 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools Notes On Constants When you declare a constant variable, it must be assigned with a value: Example Like this: const int minutesPerHour = 60; This however, will not work: const int minutesPerHour; minutesPerHour = 68; // error Good Practice Another thing about constant variables, is that it is considered good practice to declare them with uppercase. It is not required, but useful for code readability and common for C programmers: Example const int BIRTHYEAR = 1980; nitpsilmww:vdschools.comiele_constants.pnp 26 06/12/2028 06:37 Constants 3 w Tutorials~ Exercisesw Serviesey§ QO SignUp Login css JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS c ADVERTISEMENT > Earn Your Certificate Today And Unlock Tomorrow's Opportunities! Oe tipsitinww.w3schools com/cle_constants php 36 06/12/2028 06:37 Constants 3 w Tutorialsy —Exercisesw Servicese§ QO Log in schools ADVERTISEMENT ADVERTISEMENT 3 w SPACES UPGRADE NEWSLETTER schools nitpsilmww:vdschools.comiele_constants.pnp 46 06/12/2028 06:37 w i Tutorials + schools = SS JAVASCRIPT Top Tutorials HTML Tutorial 3S Tutorial JavaScript Tutorial How To Tutorial ‘SQL Tutorial Python Tutorial Wa.cSs Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial Top References HTML Reference SS Reference JavaScript Reference SQL Reference Python Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference ‘Angular Reference Query Reference Top Examples HTML Examples SS Examples JavaScript Examples How To Examples SQL Examples Python Examples W2.CSS Examples Bootstrap Examples PHP Examples Java Examples XML Examples JQuery Examples Exercises ¥ Constants Sevicesy Q @O SignUp Login PYTHON JAVA PHP = HOWTO ~—W3.CSS Get Certified HTML Certificate css centficate JavaScript Certificate Front End Certificate SQL Certificate Python Certificate PHP Certificate Query Certificate Java Certificate c++ Certificate Ci Certificate XML Certificate G@ @& ® © Forum asour W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning Tutorials, references, and examples are constantly reviewed to avold errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by tipsitinww.w3schools com/cle_constants php c 06/12/2028 06:37 Constants 3 w Tutorials» —Exercisese Servicese§ QU O SignUp Login schools = CSS JAVASCR SQL. PYTHON JAVA PHP = HOWTO = W3.CSS_— tipsitinww.w3schools com/cle_constants php ae

You might also like