-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex9.c
56 lines (44 loc) · 1.08 KB
/
ex9.c
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
56
#include <stdio.h>
int main(int argc, char *argv[])
{
int numbers[4] = {0};
char name[5] = {'a'};
// first print them out raw
printf("numbers: %d %d %d %d\n",
numbers[0], numbers[1],
numbers[2], numbers[3]);
printf("name each: %c %c %c %c %c\n",
name[0], name[1],
name[2], name[3],
name[4]);
printf("name: %s\n", name);
// setup the numbers
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
// setup the name
name[0] = 'D';
name[1] = 'a';
name[2] = 'v';
name[3] = 'e';
name[4] = '\0';
// then print them out initialized
printf("numbers: %d %d %d %d\n",
numbers[0], numbers[1],
numbers[2], numbers[3]);
printf("name each: %c %c %c %c %c\n",
name[0], name[1],
name[2], name[3],
name[4]);
// print the name like a string
printf("name: %s\n", name);
// another way to use name
char *another = "Dave";
printf("another: %s\n", another);
printf("another each: %c %c %c %c %c\n",
another[0], another[1],
another[2], another[3],
another[4]);
return 0;
}