Created
July 29, 2022 19:30
-
-
Save maxsei/b2b5f19093b5d5317c4e9aabc7297617 to your computer and use it in GitHub Desktop.
illistrate the difference between pointers and arrays in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<stdlib.h> | |
| int main(void) { | |
| int *ptr = calloc(5, sizeof(int)); | |
| printf("sizeof(ptr) = %ld\n", sizeof(ptr)); | |
| for (void *end = &ptr[5]; ptr != end; ptr++) | |
| printf("%d\n", *ptr); | |
| int arr[5] = {0, 1}; | |
| printf("sizeof(arr) = %ld\n", sizeof(arr)); | |
| int *cur = &arr[0]; | |
| for (void *end = &cur[5]; cur != end; cur++) | |
| printf("%d\n", *cur); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment