-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointer_cheatsheet.c
64 lines (49 loc) · 2 KB
/
Pointer_cheatsheet.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
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
int number = 1;
int *Pnumber = &number;
printf("%p adress number \n", Pnumber);
printf("%d value of variable to which pointer points \n", *Pnumber);
printf("%p adress Pnumber \n\n", &Pnumber);
//---------------------------------
char name[8] = "Jessica";
//points to first element of name[]and at the same
//time can address all buckets of the name[]
//with name[1]...
char *Pname = name;
printf("%p Adress of name[0]\n", Pname);
printf("%p Adress of Pname\n", &Pname);
printf("%c Value of first char where Pname points to\n", *Pname); //or Pname[0]
printf("%c value of second char where Pname points to\n\n", Pname[1]);
//-----------------------------------
char nameMale[] = "Benjamin";
//array of char pointers
char *P_name[5];
P_name[0] = nameMale;
printf("%p adress of pointer \n", P_name);
printf("%p adress of pointer 0\n", &P_name[0]);
printf("%p adress of pointer 1\n", &P_name[1]);
printf("%p adress of nameMale[0]\n", &nameMale[0]);
printf("%s value of variable to which pointer points\n", *P_name);
printf("%s value of variable to which pointer points\n\n", P_name[0]);
//----------------------------------------
char nameFemale[] = "Dorothee";
char nameFemale2[] = "Sonja";
char *P_fname[5];
//array of char pointers pointing to P_fname
char **PP_fname[2];
P_fname[0] = nameFemale;
P_fname[1] = nameFemale2;
PP_fname[0] = &P_fname[0];
PP_fname[1] = &P_fname[1];
printf("%p adress of nameFemale \n", nameFemale);
printf("%p adress of nameFemale\n", P_fname[0]);
printf("%p adress of P_fname \n", PP_fname[0]);
printf("%p adress of PP_fname\n", &PP_fname);
printf("%p adress of P_fname\n", &P_fname);
printf("%s value of variable to which pointer of P_fname[0] points\n", *PP_fname[0]);
printf("%s value of variable to which pointer of P_fname[0] points\n", *PP_fname[1]);
}