📄 dataseg.c
字号:
#include <stdio.h>int main (){ char *PtoString = "The boy stood on the burning deck\n"; /* the string is sored in the data segment. PtoString holds the address of its first character */ "I wandered lonely as a cloud\n"; /* this also puts a string into the data segment, but we don't provide a variable to store the address so don't know how to get at it! Some compilers recognise this and decide not to store the string at all */ printf("Humpty Dumpty sat on a wall\n"); /* another string for the data segment. There's no variable to store the address but the address is passed to printf so printf can print the characters stored at successive locations until it meets a '\0' */ printf("%s", PtoString); /* yes, even this writes to the data segment! it stores three characters - %, s and the null \0. The address of the first character, the %, is passed to printf which encounters the %s specifier. This tell sit to take the address stored in PtoString and to walk down the characters until it meets null */ printf(PtoString); /* pass the pointer directly to printf. Rather than having to go through a %s, it gets a pointer to T atthe beginning of the string */ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -