Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

C Arrays and Pointers

#include <stdio.h>
int main() {

  int x[5] = {1, 2, 3, 4, 5};
  int* ptr;

  // ptr is assigned the address of the third element
  ptr = &x[2]; 

  printf("*ptr = %d 
", *ptr);   // 3
  printf("*(ptr+1) = %d 
", *(ptr+1)); // 4
  printf("*(ptr-1) = %d", *(ptr-1));  // 2

  return 0;
}
 
PREVIOUS NEXT
Tagged: #C #Arrays #Pointers
ADD COMMENT
Topic
Name
8+6 =