Stepping through an array of structures using pointer notation. - C String

C examples for String:char array

Description

Stepping through an array of structures using pointer notation.

Demo Code

#include <stdio.h>

#define MAX 4/*  w  ww  . j a v  a 2  s .co  m*/

struct part {
    short number;
    char name[10];
} data[MAX] = {1, "A",
               2, "B",
               3, "C",
               4, "D"};

int main( void ){
    struct part *p_part;
    int count;

    p_part = data;

    for (count = 0; count < MAX; count++){
        printf("At address %d: %d %s\n", p_part, p_part->number, p_part->name);
        p_part++;
    }
    return 0;
}

Related Tutorials