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

PREVIOUS NEXT
Code Example
C :: what is type casting in c programming 
C :: c to fahrenheit 
C :: looping through an array in c 
C :: c structure with pointer 
C :: getline() in c 
C :: print in c 
C :: prime numbers 
C :: threads in c 
C :: int to void* c 
C :: finding characters in string 
C :: size of operator in c language 
C :: Increment & Decrement Operator in C language 
C :: example of header file in c 
C :: c read file from command line 
C :: pipe system call 
C :: largest value in u64 
C :: vscode how to output in seperate consile 
C :: C Operator associativity 
C :: C #if, #elif and #else Directive 
C :: Uri/Beecrowd problem no - 1151 solution in C 
C :: minimun number of moves in c 
C :: ssl_get_servername return null 
C :: Entering raw mode 
C :: Letters and Digits Total 
C :: algorithm for sorting numbers in ascending order 
C :: c check if character is a punctuation 
C :: string compare in c 
C :: The closest in between 
C :: params in main function in C 
C :: tableau c 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =