DEV Community

David Hwang
David Hwang

Posted on

5/21 TIL: C/C++ setup on MacOS & C pointers

  • To run C programs, we need a compiler

    • clang and gcc are usually used on MacOS—they are built-in
    • we can check if these compilers exist in our system by doing this on terminal:
      gcc -v
      clang -v
  • To run a C program in VS code

    • Install the 'C/C++' and 'code runner' extensions
    • Write your C program and compile it by selecting Terminal > Run Build Task (choose gcc/clang build in the dropdown)
  • Pointers in C

      int x = 10;
      // * used here in the declaration statement has nothing to do with dereferencing; we are simply declaring a variable named aptr of type 'pointer to int' (meaning it stores the address of an integer variable)
      int *aptr = &x; 
      printf("%x returns a memory address", aptr);
      // * here is now used for dereferencing
      printf("%d is the value dereferenced, *aptr);

Discussion (0)