Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char string[30];
- // Set the array to the lowercase alphabet using the way we already
- // know: brackets
- for (int i = 0; i < 26; i++)
- {
- // Character constants can be treated like integers. It saves us from
- // having to look up to see what integer value the lowercase letter
- // A has.
- string[i] = 'a' + i;
- }
- string[26] = 0;
- printf("%s\n",string);
- // Here's another way: using pointers and some math
- for (int i = 0; i < 26; i++)
- {
- char *index = string + (i * sizeof(char));
- // Use a capital A just for something different
- *index = 'A' + i;
- }
- string[26] = 0;
- printf("%s\n",string);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement