C - Write program to fill char array using pointer

Requirements

Write program to fill char array using pointer

Set the char array's size to 27 so that it can hold 26 letters.

Fill the array with the letters 'A' through 'Z' by using pointer notation.

Display the results by using pointer notation.

Hint

Here's the statement you can use:

*pn=x+'A'; 

In fact, in case you're totally lost, I've put my solution for Exercise 19-7 in  
Listing 19-3. 

Demo

#include <stdio.h>

int main()/* w  w  w.  j a  v a  2  s  . co m*/
{
    char alphabet[27];
    int x;
    char *pa;

    pa = alphabet;      /* initialize pointer */

/* Fill array */
    for(x=0;x<26;x++)
    {
        *pa=x+'A';
        pa++;
    }

    pa = alphabet;

/* Display array */
    for(x=0;x<26;x++)
    {
        putchar(*pa);
        pa++;
    }
    putchar('\n');

    return(0);
}

Result

Related Exercise