logo

Difference between arrays and pointers in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int example(int* l) { return 0; } int main(int argc, char* argv[]) { int arr[3]; arr[0] = 1; arr[1] = 2; arr[2] = 3; int *arrp = arr; int* p = malloc(3 * sizeof(int)); p[0] = 1; p[1] = 2; p[2] = 3; example(p); example(arr); printf("%llu %llu\n", sizeof(arr), sizeof(p)); free(p); return 0; }
Course thumb

The C programming language made simple

Courses with this lesson