1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
// char
char ch = 'A';
printf("%c\n", ch);
// address of char
char* a_ch = &ch; // create an address variable initialized with the
// address of the variable 'ch'.
// A string is an array of characters in memory.
// string -- s1 is the address of the beginning of an array of char (i.e., a string)
char* s1 = "dictionary"; // in data segment (do not change)
printf("s1 == \"%s\"\n", s1);
// Here, we access the first element of the array at s1.
char c2 = s1[0]; // c2 gets the first element of the array of characters at s1
printf("c2 == '%c'\n", c2);
// ... and the second element
char c3 = s1[1]; // c3 gets the second element of the array of characters at s1
printf("c3 == '%c'\n", c3);
return EXIT_SUCCESS;
}
|
© Copyright 2017 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.