Search
 
SCRIPT & CODE EXAMPLE
 

C

pointer arithmetic on Arrray in c

int main(int argc, char *argv[])
{	// declare an array
    char *card_deck[] = {"Joker", "one", "two", "three", "four",
    					"five", "six", "seven", "eight", "nine",
                        "ten", "Jack", "Queen", "King"};
    // declare a point and make it point to the array;
  	// You need two ** because an array is a pointer to the first element in the array
  	// So you need a pointer to a pointer AKA double pointer
    char **ptr = card_deck;
    
    for (int deck = 0; deck <= 13; deck++)
    {
      	// Now you can increment the ptr in a loop and print all the elements of the array.
        ptr++;
        printf("
card deck %s", *ptr);
    }
Comment

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;
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
C :: Install valet-linux 
C :: example of header file in c 
C :: iterating through a linked list 
C :: typedef c 
C :: what is O(N^2) in bubble sort method 
C :: Symmetrical matrix in C 
C :: ansi c read write bmp 
C :: Returns numbers between i and 0 
C :: fifo page algorithm in C 
C :: metw.cc 
C :: how to change the smartart style to 3D polished in powerpoint 
C :: c fibonacci series recursion 
C :: block quote in lua 
C :: can torch light bring change in chemical reaction 
C :: tytykjtuky 
C :: counting sort using malloc and size-t type c 
C :: deepak 
C :: man write c 
C :: gtk widget change window title 
C :: Convert arduino String to C language String 
C :: How to set bit in float number in C 
C :: send array to child process c 
C :: Calculate the area of a circle and modify the same program to calculate the volume of a cylinder given its radius and height. 
C :: attiny pinout 
C :: snprintf with malloc 
C :: changing an item in an array in c 
C :: free array in c 
Dart :: flutter listtile shape 
Dart :: flutter keyboard overflow when opens 
Dart :: card border radius in flutter 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =