“Pointer dan Array di C” Kode Jawaban

Contoh implementasi pointer ke array di C:

#include<stdio.h>
int main()
{
printf("Welcome to DataFlair tutorials!\n\n");
int i;
double array[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
double *p;
p = array;
printf( "The array is:\n");
for ( i = 0; i < 5; i++ )
{
printf("%0.2f\n", *(p + i) ); // Pointer to an array
}
return 0;
}
christinah muunga

aritmatika pointer di arrray di 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("\ncard deck %s", *ptr);
    }
Dirty Moose

Array dan pointer C

#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 \n", *ptr);   // 3
  printf("*(ptr+1) = %d \n", *(ptr+1)); // 4
  printf("*(ptr-1) = %d", *(ptr-1));  // 2

  return 0;
}
SAMER SAEID

C pointer dan array

#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;
}
SAMER SAEID

Jawaban yang mirip dengan “Pointer dan Array di C”

Pertanyaan yang mirip dengan “Pointer dan Array di C”

Lebih banyak jawaban terkait untuk “Pointer dan Array di C” di C++

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya