EasyManuals Logo
Home>Casio>Desktop>FX-890P

Casio FX-890P User Manual

Casio FX-890P
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #103 background imageLoading...
Page #103 background image
103
Here, variable “i” is declared outside of any function, so “i” will be treated as a global
variable. Consequently, it will retain its current value regardless of whether execution
is in main() or pr(). In this program, variable “i” is assigned a value by the “for” loop in
main(), and then the value of “i” is printed by function pr().
Note that any function has access to “i”, not only to read it but as well to modify it.
This increases the risk of unexpected software errors and is a major drawback of
global variables.
If you decide to use global variables, here are some basic rules to follow:
Restrict the usage to variables that make sense to be global, but cannot be
considered as a constant. Example: Screen_W, Dist_Unit.
Use long, descriptive names to make obvious the type of value that is stored.
6.1.2 Pointers and variable storage locations
Entering values
Here, we will write a calculation program that performs specific integer arithmetic
operations on values entered via the scanf() standard function. With this program,
entry of “33+21 . . “ would for example produce the result “=54”.
/* scanf example */
/* #include <stdio.h> */
main(){
char op;
int x,y,xy;
xy=0;
scanf(“%d%c%d”,&x,&op,&y);
if(op==’+’) xy=x+y;
else if(op==’-‘) xy=x-y;
else if(op==’*‘) xy=x*y;
else if(op==’/‘) xy=x/y;
else if(op==’%‘) xy=x%y;
else printf(“unknown op”);
printf(“=%d”¥n”,xy);
}
Variable “op” is a character type while “x”, “y”, and “xy” are integer type. Since we are
using the scanf() function, arguments are expressed preceded by ampersands,
becominf “&x”, “&op” and “&y”. In C, an argument such as “&x” represents the
location in memory that the contents of variable “x” are stored. It is called an address.
The scanf() function understands arguments to be addresses, and represents the
value stored at the address within the expression. See the Command Reference for
detailed information on the scanf() function.
The line “scanf’”%d%c%d”, &x, &op, &y);” accepts input of integers for variables “x”
and “y”, and a character code for variable “op”.
The execution of the next statement depends on the character assigned to variable
“op”. If it is a plus sign, the first “if” statement is executed, if it a a minus sign, the
second “if” statement is executed, etc.

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Casio FX-890P and is the answer not in the manual?

Casio FX-890P Specifications

General IconGeneral
BrandCasio
ModelFX-890P
CategoryDesktop
LanguageEnglish

Related product manuals