Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

C Pointers and Arrays

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

  int i, x[6], sum = 0;

  printf("Enter 6 numbers: ");

  for(i = 0; i < 6; ++i) {
  // Equivalent to scanf("%d", &x[i]);
      scanf("%d", x+i);

  // Equivalent to sum += x[i]
      sum += *(x+i);
  }

  printf("Sum = %d", sum);

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