.


:




:

































 

 

 

 





: if - else, switch goto. :

if (_) _1; else _2;

, _1, - _2. , . if else .

if - else if else . if, . else if.

switch . :

switch () { case _1: _1; break; case _2: _2; break;................ default: _default; }

( ) ( ). . ( ). default , ( default ). default , , .

break, switch.

switch.

3.

. . , . , . . , : . , :

int a[100]; char b[20]; float d[50];

100 : [0], [1],..., [99] ( ). b char, - float.

, . , char [10][20]; . . , .. , . , : [5][9].

:

int a[2][3];

: a[0][0], a[0][1], a[0][2], a[1][0], a[1][1], a[1][2].

- , ( [0][0]). , a = 1000. [0][1] 1002 ( int 2 ), [0][2] - 1004 .. , , ? , . .

. , , , .

int a[5];

[0], a[1], a[2], a[3], a[4]. *

int *;

= &a[0]; [0]. , y+1 , ( int - 2 , long - 4 , (double - 8 ..).

, = &a[0]; : = . [1] *(+1). , - a, : a[i] *(+i) - .

. - = ; y++; - . - , a = y; a++; , .

( ) (.. ), .. , ( <, >, = =,!= ). 6 ( , ). NULL. . , .

. :

_[...]... [...] = { };

:

int a[5] = {0, 1, 2, 3, 4}; char ch[3] = {'d', 'e', '9'}; int b[2][3] = {1, 2, 3, 4, 5, 6};

: b[0][0] = 1, b[0][1] = 2, b[0][2] = 3, b[1][0] = 4, b[1][1] = 5, b[1][2] = 6.

, , , : char *m[5];. m[5] - , char.

, . , - .

char [10]; 10 . , char. , , , , , , . printf("%s", ), , .. , . - , printf() , , , . (, ): , .

:

char array[7] = "";

char s[ ] = {'', '', '', '', '', '', '\0'};

( ).

- . char *b; b, . b . b ="IBM PC";, . -, , - "IBM PC", ('\0'). -, ( 'I') b. printf("%s", b) , , , .

, .. .

scanf() printf() gets() puts() ( stdio.h).

string - , :

gets(string);

( <Enter>). :

puts(string);

, , string.h.

strcpy(), strcat(), strlen() strcmp().

string1 string2 - , strcpy() :

strcpy(string1, string2);

string2 string1. string1 , string2. , .

strcat() :

strcat(string1, string2);

string2 string1 , string1, string2 . , , .

strlen() , . a - , :

a = strlen(string);

strcmp() 0, .

- (, , , ..). , . , .

struct, , :

struct { _1 _1;......... _n _n; };

. , .

:

sruct date { int day; int month; int year; };

, , , :

struct date {...} a, b, c;

( ). ; . , :

struct date days;

days date.

, .

, :

struct man { char name[20], fam[20]; struct date bd; int age; };

data : day, month, year, (int). man name, fam, bd voz. - name[20] fam[20] - 20 . bd ( ) data. age int). , :

struct man man_[100];

man_, 100 man.

, , , :

man_[j].age = 19; man_[j].bd.day = 24; man_[j].bd.month = 2 man_[j].bd.year = 1987;

, . , man_ man, year .. , , . man_[i]=man_[j]; man_[i] man_[j] - , . , .

& . , day:

struct date {int d, m, ;} day;

day - date, : d, m, .

struct date *db;

, db - date.

:

db = &day;

d, m, :

(*db).d; (*db).m; (*db).y;

, db - , *db - . , , , . ->. :

db -> d; db -> m; db -> ;

typedef

:

struct data {int d, m, ;};

- data. , :

struct data , b, ;

, (). typedef. :

typedef ;

"" - "" - .

:

typedef int INTEGER;

:

INTEGER , b;

, int a,b;. , INTEGER int.

. - , . signed int unsigned int 1 16 . . , :

struct prim { int a:2; unsigned b:3; int c:5; int d:1; unsigned d:5; } i, j;

( ). : unsigned d:6, , 0 - 5 .

signed .

. , &.

4.

(). , , . . . , .

. (.. ) , (.. ) (.. main()), . , , . , .

:

_( __1, __2,...);

, . , , (int).

(: (int, float,...), (: (int , float b,...)).

. .

:

_( __1, __2,...) { }

return, :

return ;

, . :

int f(int a, int b) { if (a > b) { printf("max = %d\n", a); return a; } printf("max = %d\n", b); return b; }

:

c = f(15, 5); c = f(d, g); f(d, g);

, , . return ; . " " ( ).

, .. , . , . , , . :

void swap(int *a, int *b) { int *tmp = *a; *a = *b; *b = *tmp; }

swap(&b, &c) ( b ) , b c .

, , . , () .

, . :

  1. (: int m[100];).
  2. (: int m[];).
  3. (: int *m;). .

. .

, , , , .

- , . : , , . , #. ( ).

#define

( ). , (), "" - , "" - , , . .

:

#define MAX 25

#define BEGIN {

MAX 25. ({) BEGIN.

, , , #define, const ( ++):

const int MAX = 25;

( int , ).

#define :

#define (,..., )

, . , :

#define READ(val) scanf("%d", &val)

READ(y); , scanf("%d",&y);. val - .

, , \.

, ##, :

#define PR(x, ) x##y

PR(, 3) 3. , ,

#define z(a, b, c, d) a(b##c##d)

z(sin, x, +, y) sin(x+y).

#, , . ,

#define PRIM(var) printf(#var"= %d", var)

year = 2006;

PRIM(year);

:

year = 2006;

printf("year""= %d", year);

. #include . :

#include " "

#include < >

. . , . , , , , #include <...>. #include .

. . #if, #else, #elif, #endif, #ifdef, #ifndef. #if :

#if _ _

#endif

. , , , .

#else else , :

#if _

__1

#else

__2

#endif

, __1, - __2.

#elif "else if". :

#if _

_

#elif __1

__1

#elif __n

__n

#endif

: if...else if...else if...

#ifdef

, .. #define.

#ifndef

. , , #else (#elif ) #endif. , #else #endif, , #else ( #else , #endif). #if #ifndef "" .

#undef

, , .. .

. :

#ifdef WRITE

#undef WRITE

#endif

WRITE (.. #define WRITE...), , WRITE , .. .

#ifndef WRITE

#define WRITE fprintf

#endif

WRITE , , WRITE fprintf.

#error :

#error __

, . . , .

#line _LINE_ _FILE_, . _LINE_ , . _FILE_ . #line :

#line "_"

- , _LINE_, _ - , _FILE_.

#pragma . ,

#pragma inline

, . :

asm mov ax, 5

asm {

inc dx

sub bl, al

}

..

( ). : _LINE_, _FILE_, _DATE_, _TIME_, _STDC_. (_LINE_ _FILE_) . _DATE_ , . _TIME_ , . _STDC_ 1, - . .

 





:


: 2017-03-18; !; : 248 |


:

:

- , .
==> ...

2088 - | 1843 -


© 2015-2024 lektsii.org - -

: 0.09 .