[ Pobierz całość w formacie PDF ]

Byte ordering is another problem encountered when converting programs from one machine to
another. In the 68000, the low byte of a 16 bit word is the second, odd numbered, byte. The
bytes in a 32 bit long are laid out most significant byte at the address, with the least significant
byte below it. Intel chips use the opposite order. This byte sex problem leads to arguments akin
to those in religion and politics, and just as likely to lead to real solutions.
4.6 Lots Of Variable Types
Load the filelottypes.cand display it your screen.
4-3 C Tutorial Assignment & Logical compares
main( )
{
int a; /* simple integer type */
long int b; /* long integer type */
short int c; /* short integer type */
unsigned int d; /* unsigned integer type */
char e; /* character type */
float f; /* floating point type */
double g; /* double precision floating point */
a = 1023;
b = 2222;
c = 123;
d = 1234;
e =  X ;
f = 3.14159;
g = 3.1415926535898;
printf("a = %d\n",a); /* decimal output */
printf("a = %o\n",a); /* octal output */
printf("a = %x\n",a); /* hexadecimal output */
printf("b = %1d\n",b); /* decimal long output */
printf("c = %d\n",c); /* decimal short output */
printf("d = %u\n",d); /* unsigned output */
printf("e = %c\n",e); /* character output */
printf("f = %f\n",f); /* floating output */
printf("g = %f\n",g); /* double float output */
printf("\n");
printf("a = %d\n",a); /* simple int output */
printf("a = %7d\n",a); /* use a field width of 7 */
printf("a = %-7d\n",a); /* left justify in field of 7 */
printf("\n");
printf("f = %f\n",f); /* simple float output */
printf("f = %12f\n",f); /* use field width of 12 */
printf("f = %12.3f\n",f); /* use 3 decimal places */
printf("f = %12.5f\n",f); /* use 5 decimal places */
printf("f = %-12.5f\n",f); /* left justify in field */
}
This file contains every standard simple data type available in the programming language C.
There are other types, but they are the compound types that we will cover in due time.
Observe the file. First we define a simple "int" followed by a "long int" and a "short int". Consult
your reference manual for an exact definition of these for your compiler, because they are not
consistent from implementation to implementation. The "unsigned" is next and is defined as
the same size as the "int" but with no sign. The "unsigned" then will cover a range of 0 to 65535
on MS-DOS microcomputers, but as 0 to 4294967296 in HiTech. It should be pointed out that
when "long", "short", or "unsigned" is desired, the "int" is optional and left out by most
experienced programmers. We have already covered the "char" and the "float", which leaves
only the "double". The "double" usually covers a greater range than the "float" and has more
significant digits for more precise calculations. It also requires more memory to store a value
thanthesimple "float". Consult your referencemanual forthe rangeand accuracy of the"double".
Another diversion is in order at this point. Most compilers have provisions for floating point
math, but only double floating math. They will promote a "float" to a "double" before doing
calculations and therefore only one math library will be needed. Of course, this is totally
transparent to you, so you don t need to worry about it. You may think that it would be best to
simply define every floating point variable as double, since they are promoted before use in any
calculations, but that may not be a good idea. A "float" variable requires 4 bytes of storage and
a "double" requires 8 bytes of storage, so if you have a large volume of floating point data to
store, the "double" will obviously require much more memory. Your compiler may require a
different number of bytes than 4 or 8. Consult your reference manual for the correct number of
bytes used by your compiler.
Assignment & Logical compares C Tutorial 4-4
After defining the data types, a numerical value is assigned to each of the defined variables in
order to demonstrate the means of outputting each to the monitor.
4.7 The Conversion Characters
Following is a list of the conversion characters and the way they are used in the "printf" statement.
d decimal notation
o octal notation
x hexadecimal notation
u unsigned notation
c character notation
s string notation
f floating point notation [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • showthemusic.xlx.pl
  • © 2009 Silni rządzą, słabych rzuca się na pożarcie, ci pośredni gdzieś tam przemykają niezauważeni jak pierd-cichacz. - Ceske - Sjezdovky .cz. Design downloaded from free website templates