jazykc  2013.3
upoljazykc
 All Classes Files Functions Variables Typedefs Macros Pages
prace-s-promennymi.c
Go to the documentation of this file.
1 
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 #include <limits.h>//nepovolenej, ale co se da delat
27 
28 int cislo = 3;
29 double des_cislo = 3.45;
30 char muj_znak = '+';
31 double male_cislo = 1.2e-10;
32 
33  char ch = 'c';//-128..127
34 unsigned char uch = '\xa1';//0..255
35  short s = 12345; // -32768..32767
36 unsigned short us = 65535;
37  int i = 0xBABABEBE; //32bitu na ILP32, LP64 platforme
38 unsigned int ui = 0xB1aaB1ee;
39  long l = 12345; //64bitu na LP64, 32bit na ILP32
40 unsigned long ul = 65535;
41 //explicitni velikosti viz stdint.h
42 
43  float flout = 22.0/7;//C stejne pocita s float jako s double!
44  double dabl = 22.0/7;
45 long double ldabl = 22.0/7;
46 
50 size_t sz;
51 
52 int main(void) {
53  printf("Hodnota promenne cislo je: %i\n", i);
54  printf("Hodnota promenne des_cislo je: %3.2f\n", des_cislo);
55  printf("Hodnota promenne muj_znak je: %c\n", muj_znak);
56  printf("Hodnota promenne male_cislo je: %g\n", male_cislo);
57 
58 //dalsi zajimave pokusy
59 //locale pro kompilaci je utf-8!!! \xa1 je neplatne utf!
60 //pro 8bitove locale je \xa1 zaporne cislo, char je default signed!
61  ch = '\xa1';
62  ch = 'รก';//dlouhe a
63  printf(" ch: '%c' \\x%x\n", ch, ch);
64  printf("uch: '%c' \\x%x\n", uch,uch);
65 
66  printf(" i %%i: %i\n", i);
67  printf("ui %%i: %i\n",ui);
68  printf("ui %%u: %u\n",ui);
69  printf("LONG_MAX=%li\n", LONG_MAX);
70  printf(" INT_MAX=%i\n", INT_MAX);
71 
72  printf("flout %%g: %g, %%e: %e, %%f: %f, %%60.58f: %60.58f\n", flout, flout, flout, flout);
73  printf(" dabl %%g: %g, %%e: %e, %%f: %f, %%60.58f: %60.58f\n", dabl, dabl, dabl, dabl);
74 //long double potrebuje %Lf apod!!!
75  printf("ldabl %%Lg: %Lg, %%Le: %Le, %%Lf: %Lf, %%60.58Lf: %60.58Lf\n", ldabl, ldabl, ldabl, ldabl);
76 
77 //note: zmena na 32bit long pomoci -m32
78 #define SIZEOF(type) printf("sizeof(" #type ")==%zu\n",sizeof(type))
79  SIZEOF(char);
80  SIZEOF(short);
81  SIZEOF(int);
82  SIZEOF(long);
83  SIZEOF(double);
84  SIZEOF(long double);
85  SIZEOF(char *);
86 
87  return EXIT_SUCCESS;
88 }
size_t sz