summaryrefslogtreecommitdiff
path: root/test/c/initializers.c
blob: 5fa4fd4ad9b782fbfe5a42ad5d4f9dc9377dd9e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>

char x1 = 'x';

int x2 = 12345;

double x3 = 3.14159;

char x4[4] = { 'a', 'b', 'c', 'd' };

int x5[10] = { 1, 2, 3 };

struct { int y; int z; } x6 = { 4, 5 };

struct { int y; char z; } x7 = { 6, 'u' };

struct { char y; int z; } x8 = { 'v', 7 };

struct { char y[9]; double z; } x9 = { { 'a', 'b' }, 2.718 };

struct {
  struct { char y; int z; } u;
  double v;
} x10 = { { 'v', 7 }, 2.718 };

float x11 = 1 + 1 / 3.14159;

double x12 = 1 / 3.14159 + 1;


int main(int argc, char ** argv)
{
  int i;

  printf("x1 = '%c'\n", x1);
  printf("x2 = %d\n", x2);
  printf("x3 = %.5f\n", x3);
  printf("x4 = { '%c', '%c', '%c', '%c' }\n",
         x4[0], x4[1], x4[2], x4[3]);
  printf("x5 = { ");
  for (i = 0; i < 10; i++) printf("%d, ", x5[i]);
  printf("}\n");
  printf("x6 = { %d, %d }\n", x6.y, x6.z);
  printf("x7 = { %d, '%c' }\n", x7.y, x7.z);
  printf("x8 = { '%c', %d }\n", x8.y, x8.z);
  printf("x9 = { { ");
  for (i = 0; i < 9; i++) printf("'%c', ", x9.y[i]);
  printf("}, %.3f }\n", x9.z);
  printf("x10 = { { '%c', %d }, %.3f }\n",
         x10.u.y, x10.u.z, x10.v);
  printf("x11 = %.10f\n", x11);
  printf("x12 = %.10f\n", x12);
  return 0;
}