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 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
int main(int argc, char* argv[]) {
char* s1 = "ABC"; // string on the DATA SEGMENT
// s1 is the address of string on the data segment.
// The characters ('A', 'B', 'C') are on the data segment.
// The address where the characters can be found is on the stack segment.
char s2[] = "ABC"; // string on the STACK SEGMENT
// s2 is an array of char's on the stack segment.
char s3[] = { 'A', 'B', 'C', '\0' };
char s4[] = { 65, 66, 67, 0 };
printf("s1 == %s\n", s1);
printf("s2 == %s\n", s2);
printf("s3 == %s\n", s3);
printf("s4 == %s\n", s4);
return EXIT_SUCCESS;
}
/*
char fmt[] = "s1 == %s\n"
// how many characters are in fmt.
{ 's', '1', ' ', '=', '=', ' ', '%', 's', '\n' }
*/
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2023 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.