Download presentation
Presentation is loading. Please wait.
1
C Programming Constants and Control Structures
2
Constants Can be defined in two ways. –Traditional Method –#define PI 3.14 #define is a preprocessor command. The preprocessor replaces every occurrence of PI with the literal string 3.14. #defined constants are conventionally uppercase.
3
Dangers of #define If you #define a name it may affect other code. –#define loop for –would replace the word “loop” with “for” in all code which might have unforeseen side effects.
4
const const is a new keyword developed in the ANSII standard. Use is const name; Has the advantage of checking the data type of your constant. Does not introduce side effects.
5
const const variable may only be initialized not changed. –const double top_salary= 4000; –top_salary = 3250; // would generate an error.
6
#define vs. const #define is easy to use and understand With proper safeguards it will not be a problem. const is the new way allows type checking sometimes seems strange to oldtimers.
7
while Loop while(condition)
8
do Loop do while( condition )
9
for Loop for( ; ; )
10
switch Statement switch { case : ; break; default: ; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.