Skip to content

Commit f977321

Browse files
committed
Update void_ptr.c
1 parent 44ed6c0 commit f977321

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

RawPointer/void_ptr.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
// clang-format off
12
/*****************************************************************//**
23
* \file void_ptr.c
34
* \brief Let's look into the void!
45
*
56
* (void*) are strictly pointers, but without type information.
67
* They are simply 8-byte pointers on a 64-bit machine pointing to memory addresses.
7-
* It's the same type that malloc(), calloc(), realloc() and reallocarray() returns.
8+
* It's the same type that malloc(), calloc(), realloc() and realloc() returns.
89
* Without type information, pointer arithmetic are undefined.
910
*
1011
* \author Xuhua Huang
1112
* \date December 08, 2022
1213
*********************************************************************/
14+
// clang-format on
1315

1416
#include <stdio.h>
1517
#include <stdlib.h>
1618

1719
int main(void) {
18-
1920
void* vp;
20-
int* ip;
21+
int* ip;
2122

2223
/* print out the size of pointers */
2324
printf("sizeof(void*) -> %zu\n", sizeof(vp));
2425
printf("sizeof(int*) -> %zu\n", sizeof(ip));
2526

2627
int x = 0xFEEDBEEF;
27-
ip = &x;
28-
vp = ip;
28+
ip = &x;
29+
vp = ip;
2930

3031
/* print out the address of both p and ip */
3132
printf("vp -> %p\n", vp);
@@ -45,9 +46,8 @@ int main(void) {
4546
/* c and cpp differ with the following lines */
4647
// int* ip2 = malloc(sizeof(int)); // error in cpp, requires explicit conversion
4748
// prefer the explicit conversion for portability and readability
48-
int *ip2 = (int*)malloc(sizeof(int));
49+
int* ip2 = (int*)malloc(sizeof(int));
4950
free(ip2);
5051

51-
system("pause");
5252
return EXIT_SUCCESS;
5353
}

0 commit comments

Comments
 (0)