Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created July 29, 2022 19:30
Show Gist options
  • Select an option

  • Save maxsei/b2b5f19093b5d5317c4e9aabc7297617 to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/b2b5f19093b5d5317c4e9aabc7297617 to your computer and use it in GitHub Desktop.
illistrate the difference between pointers and arrays in c
#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