Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

prog / Справочные материалы

.pdf
Скачиваний:
24
Добавлен:
13.05.2015
Размер:
47.82 Кб
Скачать

Precedence of Operators

-----------------

 

+

----------

+------------------------------------------

#

Category

¦ Operator ¦ What it is (or does)

-----------------

 

+----------

 

+------------------------------------------

1.

Highest

¦

()

¦ Function call

 

 

¦

[]

¦ Array subscript

 

 

¦

- >

¦ Indirect component selector

 

 

¦

.

¦ Direct component selector

-----------------

 

+----------

 

+------------------------------------------

2.

Unary

¦

!

¦ Logical negation (NOT)

 

 

¦

~

¦ Bitwise (1's) complement

 

 

¦

+

¦ Unary plus

 

 

¦

-

¦ Unary minus

 

 

¦

++

¦ Preincrement or postincrement

 

 

¦

--

¦ Predecrement or postdecrement

 

 

¦

&

¦ Address

 

 

¦

*

¦ Indirection

 

 

¦

()

¦ Type cast

 

 

¦

sizeof

¦ Size of operand, in bytes

-----------------

 

+----------

 

+------------------------------------------

3.

Multipli-

¦

*

¦ Multiply

 

cative

¦

/

¦ Divide

 

 

¦

%

¦ Remainder (modulus)

-----------------

 

+----------

 

+------------------------------------------

4.

Additive

¦

+

¦ Binary plus

 

 

¦

-

¦ Binary minus

-----------------

 

+----------

 

+------------------------------------------

5.

Shift

¦

<<

¦ Shift left

 

 

¦

>>

¦ Shift right

-----------------

 

+----------

 

+------------------------------------------

6.

Relational

¦

<

¦ Less than

 

 

¦

<=

¦ Less than or equal to

 

 

¦

>

¦ Greater than

 

 

¦

>=

¦ Greater than or equal to

-----------------

 

+----------

 

+------------------------------------------

7.

Equality

¦

==

¦ Equal to

 

 

¦

!=

¦ Not equal to

-----------------

 

+----------

 

+------------------------------------------

8.

 

¦

&

¦ Bitwise AND

-----------------

 

+----------

 

+------------------------------------------

9.

 

¦

^

¦ Bitwise XOR

-----------------

 

+----------

 

+------------------------------------------

10.

 

¦

|

¦ Bitwise OR

-----------------

 

+----------

 

+------------------------------------------

11.

 

¦

&&

¦ Logical AND

-----------------

 

+----------

 

+------------------------------------------

12.

 

¦

||

¦ Logical OR

-----------------

 

+----------

 

+------------------------------------------

13.

Conditional ¦

?:

¦ a ? x : y means "if a then x, else y"

-----------------

 

+----------

 

+------------------------------------------

14.

Assignment

¦

=

¦ Simple assignment

 

 

¦

*=

¦ Assign product

 

 

¦

/=

¦ Assign quotient

 

 

¦

%=

¦ Assign remainder (modulus)

 

 

¦

+=

¦ Assign sum

 

 

¦

- =

¦ Assign difference

 

 

¦

&=

¦ Assign bitwise AND

 

 

¦

^=

¦ Assign bitwise XOR

 

 

¦

|=

¦ Assign bitwise OR

 

 

¦

<<=

¦ Assign left shift

 

 

¦

>>=

¦ Assign right shift

-----------------

 

+----------

 

+------------------------------------------

15.

Comma

¦

,

¦ Evaluate

-----------------

 

+----------

 

+------------------------------------------

1

In the table of operator precedence, operators are divided into 15 categories.

The #1 category has the highest precedence; category #2 (Unary operators) takes second precedence, and so on to the Comma operator, which has lowest precedence.

The operators within each category have equal precedence.

The Unary (category #2), Conditional (category #13), and Assignment (category #14) operators associate right-to-left; all other operators associate left-to-right.

Data Types

 

 

 

 

 

 

Type

Length Range

 

 

 

unsigned char

8 bits

0

to 255

 

char

 

8 bits

-128 to 127

 

enum

16 bits

-32,768 to 32,767

unsigned int

16 bits

0

to 65,535

short int

16 bits

-32,768 to 32,767

int

16 bits

-32,768 to 32,767

unsigned long 32 bits

0

to 4,294,967,295

long

32

bits

-2,147,483,648 to 2,147,483,647

float

32

bits

3.4 * (10**-38) to 3.4 * (10**+38)

double

64

bits

1.7 * (10**-308) to 1.7

* (10**+308)

long double

80

bits 3.4 * (10**-4932) to 1.1

* (10**+4932)

Keywords

 

 

 

 

 

 

asm

auto

break

case

char

const

continue

default

do

double

else

enum

extern

far

float

for

goto

huge

if

int

interrupt

long

near

pascal

register

return

short

signed

sizeof

static

struct

switch

template

typedef

union

unsigned

void

volatile

while

 

 

 

2

<STDIO.H>

Description:

scanf scans and formats input from stdin sscanf scans and formats input from a string fscanf scans and formats input from a stream printf sends formatted output to stdin sprintf sends formatted output to a string fprintf sends formatted output to a stream

getchar gets a character from stdin putchar outputs a character on stdout gets gets a string from stdin

puts outputs a string to stdout (and appends a newline character) fgetc gets a character from a stream

fputc outputs a character to a stream fgets gets a string from a stream fputs outputs a string to a stream

fopen opens a stream

fclose closes the named stream

feof tests the given stream for an end-of-file indicator fflush flushes a stream

fread reads a number of data items from an input stream into a block fwrite appends a number of data items from block to an output stream

Declaration:

int scanf

(

 

 

const char *format [,

address,

...]);

int sscanf (const char *buffer,

const char *format [,

address,

...]);

int fscanf (FILE *stream,

 

const char *format [,

address,

...]);

int printf (

 

 

const char *format [,

argument, ...]);

int sprintf(

char *buffer,

const char *format [,

argument, ...]);

int fprintf(FILE *stream,

 

const char *format [,

argument, ...]);

int

getchar(void);

 

 

 

 

int

putchar(int c);

 

 

 

 

char *gets

(

char *s);

 

 

 

int

puts

(const

char *s);

 

 

 

int

fgetc

(

 

 

FILE *stream);

 

 

int

fputc

(

int

c,

FILE *stream);

 

 

char *fgets

(

char *s, int

n, FILE *stream);

 

 

int

fputs

(const

char *s,

FILE *stream);

 

 

FILE *fopen

(const

char *filename, const char *mode);

 

 

int

fclose(FILE *stream);

 

 

 

int

feof

(FILE *stream);

 

 

 

int

fflush(FILE *stream);

 

 

 

int

fread

(

void *ptr, int size, int n, FILE *stream);

 

int

fwrite(const

void *ptr, int size, int n, FILE *stream);

 

<CONIO.H>

Description:

getch gets a character from console but does not echo to the screen getche gets a character from console, and echoes to the screen

putch outputs character to the text window on the screen clrscr clears text mode window

Declaration:

int getch (void); int getche(void); int putch (int ch); void clrscr(void);

3

<STDLIB.H>

Description:

atof

 

converts a string

to a floating point

atoi

 

converts a string

to an integer

atol

 

converts a string

to a long

itoa

 

converts an integer to a string

ltoa

 

converts a long to a string

ultoa

 

converts an unsigned long to a string

rand

 

generator

of pseudo-random numbers in the range 0 to RAND_MAX

random

returns a

random number between 0 and num-1

randomize initializes random number generator

Declaration:

 

 

 

 

 

 

 

double

atof

(const char

*s);

int

 

atoi

(const char

*s);

long

 

atol

(const char

*s);

char

 

*itoa

(int value,

char *string, int radix);

char

 

*ltoa

(long value, char *string, int radix);

char

 

*ultoa(unsigned long value, char *string, int radix);

int

rand

(void);

 

int

random

(int num);

 

void randomize(void);

 

 

 

 

 

<MATH.H>

 

 

 

Description:

 

 

 

 

 

 

cos

 

compute the cosine of the input value

sin

 

compute the sine of the input value

tan

 

compute the tangent of the input value

acos

 

compute the arc cosine of that value

asin

 

compute the arc sine of that value

atan

 

compute the arc tangent in range –Pi/2..+Pi/2 of the input value

atan2

 

compute the arc tangent in range –Pi..+Pi of the input value (as y/x)

pow

 

calculate x to the y power (x**y)

exp

 

calculate e to the x power (e**x)

log

 

calculate the

natural logarithm of x

log10

 

calculate the

base 10 logarithm of x

sqrt

 

calculate the

positive square root of the input value

abs

 

gets the absolute

value of an integer

fabs

 

gets the absolute

value of a floating-point number

Declaration:

 

 

 

 

 

 

 

double cos

(double

x);

 

double sin

(double

x);

 

double tan

(double

x);

 

double acos

(double

x);

 

double asin

(double

x);

 

double atan

(double

x);

 

double atan2(double

y, double x);

double pow

(double

x, double y);

double exp

(double

x);

 

double log

(double

x);

 

double log10(double

x);

 

double

sqrt

(double

x);

 

int

 

abs

(int x);

 

 

double fabs

(double

x);

 

4

<STRING.H>

Description:

strcmp compare two strings

strncmp compare portions of two strings

stricmp compare two strings without case sensitivity

strnicmp compare portions of two strings, without case sensitivity strcat appends one string to another

strncat appends a portion of one string to another strcpy copies string src to dst

strncpy copies at most maxlen characters of src to dst

strchr scans a string for the first occurence of a given character strlen calculates length of a string

strdup copies a string into a newly created location (use malloc) strstr finds the first occurrence of a substring in another string strset sets all characters in s to ch

strnset sets the first n characters of s to ch

Declaration:

int strcmp (const char *s1, const char *s2);

int strncmp (const char *s1, const char *s2, int maxlen); int stricmp (const char *s1, const char *s2);

int strnicmp(const char *s1, const char *s2, int maxlen); char *strcat (char *dst, const char *src);

char *strncat (char *dst, const char *src, int maxlen); char *strcpy (char *dst, const char *src);

char *strncpy (char *dst, const char *src, int maxlen); char *strchr (const char *s, int c);

int strlen (const char *s); char *strdup (const char *s);

char *strstr (const char *s1, const char *s2); char *strset (char *s, int ch);

char *strnset (char *s, int ch, int n);

<MEM.H, STRING.H>

Description:

memccpy copies a block of n bytes from src to dst memcpy copies a block of n bytes from src to dst memmove copies a block of n bytes from src to dst

memchr searches the first n bytes of array s for character c memcmp compares the first n bytes of strings s1 and s2

memicmp compares the first n bytes of strings s1 and s2, ignoring case memset sets n bytes of s to byte c

Declaration:

void *memccpy(void

*dst,

const

void

*src, int c, int n);

void *memcpy

(void

*dst,

const

void

*src, int n);

void *memmove(void

*dst,

const

void

*src, int n);

void *memchr

(const void

*s, int c,

int n);

int

memcmp

(const void

*s1, const

void *s2, int n);

int

memicmp(const void

*s1, const

void *s2, int n);

void *memset

(void

*s, int c, int n);

 

 

 

 

 

<STDLIB.H, ALLOC.H>

 

 

 

 

Description:

 

 

 

 

 

 

 

 

 

 

malloc

allocates memory

 

 

 

realloc reallocates main

memory

 

 

free

frees allocated blocks

 

 

Declaration:

 

 

 

 

 

 

 

 

 

 

void *malloc

(

 

int

size);

void *realloc(void

*block, int

size);

void

free

(void

*block);

 

 

5

...printf Conversion-Type Characters

The information in this table is based on the assumption that no flag characters, width specifiers, precision specifiers, or input-size modifiers were included in the format specifier.

NOTE: Certain conventions accompany some of these format specifiers.

Type

 

 

 

Char

 

Expected Input

Format of output

Numerics

d

Integer

Signed

decimal integer

i

Integer

Signed

decimal

integer

o

 

Integer

 

Unsigned

octal

integer

u

 

Integer

 

Unsigned

decimal integer

xInteger Unsigned hexadecimal int (with a, b, c, d, e, f)

X Integer Unsigned hexadecimal int (with A, B, C, D, E, F)

fFloating point Signed value of the form [-]dddd.dddd.

eFloating point Signed value of the form [-]d.dddd or e[+/-]ddd

gFloating point Signed value in either e or f form, based on

 

 

given value

and precision. Trailing zeros and

 

 

the decimal

point are printed if necessary.

EFloating point Same as e; with E for exponent.

G Floating point Same as g; with E for exponent if e format used

Characters

c Character Single character

sString pointer Prints characters until a null-terminator is

 

 

 

pressed or

precision is reached

%

None

 

Prints the

% character

Pointers

nPointer to int Stores (in the location pointed to by the input

 

argument)

a count of the chars

written so far.

p Pointer

Prints the

input

argument as a

pointer; format

 

 

depends on

which

memory model was used. It will

 

 

be either

XXXX:YYYY or YYYY (offset only).

Infinite floating-point numbers are printed as +INF and -INF.

An IEEE Not-A-Number is printed as +NAN or -NAN.

6

...printf Input-size Modifiers

These modifiers determine how ...printf functions interpret the next input argument, arg[f].

Modifier Type of arg arg is interpreted as ...

FPointer (p, A far pointer

Ns, and n) A near pointer (NOTE: N can't be used with any

 

 

 

conversion in huge model.)

h

 

d i o u x X

A short int

ld i o u x X A long int

e E f g G

A double

Le E f g G A long double

These modifiers affect how all the ...printf functions interpret the data type of the corresponding input argument arg.

Both F and N reinterpret the input variable arg. Normally, the arg for a %p, %s, or %n conversion is a pointer of the default size for the memory model.

h, l, and L override the default size of the numeric data input arguments. Neither h nor l affects character (c, s) or pointer (p, n) types.

7

...scanf Type Characters

The information in this table is based on the assumption that no optional characters, specifiers, or modifiers (*, width, or size) were included in the format specifier.

NOTE: Certain conventions accompany some of these format specifiers.

Type

 

 

 

 

Char

 

Expected input

 

Type of argument

Numerics

dDecimal integer Pointer to int (int *arg)

D

Decimal integer

Pointer to long (long *arg)

e, E Floating point

Pointer to float (float *arg)

f

 

Floating

point

 

Pointer

to

float

(float

*arg)

g, G

Floating

point

 

Pointer

to

float

(float

*arg)

oOctal integer Pointer to int (int *arg)

O

Octal integer

Pointer to long (long *arg)

iDecimal, octal, or Pointer to int (int *arg)

hexadecimal integer

IDecimal, octal, or Pointer to long (long *arg)

hexadecimal integer

uUnsigned decimal Pointer to unsigned int

integer

(unsigned int *arg)

UUnsigned decimal Pointer to unsigned long

integer

(unsigned long *arg)

xHexadecimal integer Pointer to int (int *arg)

X Hexadecimal integer Pointer to int (int *arg)

Characters

sCharacter string Pointer to array of chars (char arg[])

cCharacter Pointer to char (char *arg) if a field width

 

 

W is given

along with

the

c-type character

 

 

(such as %5c)

 

 

 

 

 

 

Pointer to

array of

W

chars (char arg[W])

%

% character

 

No conversion done;

the %

is stored

Pointers

n

 

Pointer to int (int *arg). The number

 

 

 

of

characters read successfully up to %n

 

 

 

is

stored in this int.

pHexadecimal form Pointer to an object (far* or near*)YYYY:ZZZZ or %p conversions default to the pointer

ZZZZ

size native to the memory model

8

...scanf Pointer-size and Argument-type Modifiers

These modifiers affect how ...scanf functions interpret the corresponding address argument arg[f].

Pointer-size Modifiers

----------------------

Pointer-size modifiers override the default or declared size of arg.

Mod arg Interpreted As...

F Far pointer

N Near pointer (Can't be used withany conversion in huge model)

Argument-type Modifiers

-----------------------

Argument-type modifiers indicate which type of the following input data is to be used (h = short, l = long, L = long double).

The input data is converted to the specified version, and the arg for that input data should point to an object of corresponding size.

Mod For This Type Convert Input to...

h d i o u x short int; store in short object

D I O U X (No effect)

e f c s n p (No effect)

l d i o u x long int; store in long object

e f g double; store in double object

D I O U X (No effect)

c s n p (No effect)

L

e f

g

 

long double; store in long double object

 

(all

others)

(No effect)

9

Соседние файлы в папке prog