You are on page 1of 30

-

( )

.

-





-
127
63
63
63
63
31
4095
4095
511
127
127 ()
127
127
4095 ()
4095 ( )
65535 (in a hosted environment only)
15 ( #include )
1023 (case) (switch)
1023
1023
63


?


.
->

->
->

, ,
()
-

()

char
8 , 8
[-128, 127] [0, 255],
- , .
.
short (int)
16 , 16 .
[-32768, 32767] [0, 65535],
int
16 , 32 .
-2147483648, 2147483647 ] [0, 4294967295],
.
long (int)
32 , 32 .
-2147483648, 2147483647 ] [0, 4294967295],
long long (int)
64 , 64 .
C99

:
char
signed
unsigned

int
signed
unsigned
short
long


?
stdint.h . :

intN_t uintN_t N
,
8, 16, 32 64 .
?


int_leastN_t uint_leastN_t, N 8, 16, 32 64 .

int_fastN_t uint_fastN_t, N 8, 16, 32 64 .
, .
intptr_t uintptr_t, . (?)

intmax_t uintmax_t
char
?

char
. :
x86 (GNU/Linux Microsoft Windows)
char
PowerPC ARM char


!
C99 , limits.h
CHAR_MIN. , char
, .
signed unsigned char?

#include <stdio.h>
#include <limits.h>

int main (void)


{
if (CHAR_MIN == 0)
{
printf("char is unsigned.);
}
else
{
printf("char is signed.);
}
return 0;
}


, GCC

char :
-fsigned-char -funsigned-char.

.
, :

int* p; : int *p;


e: :
float* p; int* (*p)(int a, float b);
p = &x; int* foo(int x, float y);
*p = y; p = foo;
z = *p; ip = p(n, m);

(NULL) : (void):
#include <stddef.h> void* p;
p = NULL; p = &x;
*p = y; *p = y;
*(int*)p = y;
:
typedef a #define
#define typedef

#define INT_PTR int*


typedef int* int_ptr;

INT_PTR ptr1, ptr2;


int_ptr ptr3, ptr4;

int* ptr1, ptr2;

1: typedef
2:

(float )

.

:
float 32
double 64
long double ( C99)
float.h
,
, .

float 1 8 23 32

double 1 11 52 64
-

C89

.
.
:
(
)





0, (
) #define

.

#define Sunday 1
enum Days
#define Monday 2
{
#define Tuesday 3
Sunday = 1,
#define Wednesday 4
Monday,
#define Thursday 5
Tuesday,
#define Friday 6
Wednesday,
#define Saturday 7
Thursday,
Friday,
Saturday
};




1




,
:
()


int .

int







,
. ,
` !!!
!



:






.


(int)x

()
() !

:
2U -37 'c // nije isto sto i c
3L 3l 31 051 // 41
5UL 0x2b // 43
7LL 0xFFFFFFD1 // -47
11ULL
13.0 3.14159 // 3.14159
17. 6.02e23 // 6.02 x 10^23
19.0F 1.6e-19 // 1.6 x 10^-19
23.F
29.0L
31.L

.
:

int (:
char short) int
( ), ,
.
char a;
char b;
char c = a + b;


float double
:

double polovina = 1/2;

polovina?
?

?
?

, . , ,
1/2
!
:
-
1 2 .
.
, 0.

double polovina = 1.0/2.0;


:
double polovina = 1.0/2;

x y :
double kolicnik = ((double)x)/y;

, :
char, short, int, long, long long, float, double, long double
,

,
.
: !

.
.



: ()
()
:

( )
:


()

(
)

:
.
, .
.
,

.
.

( )
uint8_t p1[4];
uint32_t* p2;
p2 = (uint32_t*)p1; /* incompatibile alignment */

:
(void*) , .
NULL . NULL
( )
.
NULL .
: NULL, 0.

:
.
.

:
( )
.
Little Big endian
( )
8 , .
8 .
: 32-

?
: 32- 4 8-, .
0x0A0B0C0D :
0x0A, 0x0B, 0x0C 0x0D, ,
.
:
-
-

. :
MIPS LE BE
Intel - LE
ARM - LE
Little Big endian


= little endian



= big endian
Little Big endian

1. 0x0A0B0C0D 32-
( int )
2. 2
16-
3. 4
8-
4. :
16bit access:
LE: 0x0C0D 0x0A0B
BE: 0x0A0B 0x0C0D

8bit access:
LE: 0x0D, 0x0C, 0x0B 0x0A
BE: 0x0A, 0x0B, 0x0C 0x0D


.
: big-endian.
hton (host-to-
network). big-endian ,
hton
.
ntoh (network-to-host)
.
:
htons() - "Host to Network Short" 16
htonl() - "Host to Network Long" 32
ntohs() - "Network to Host Short" 16
ntohl() - "Network to Host Long" 32

You might also like