[Note: This program is verified using vs2013 version]
#include <stdio.h> #include <stdlib.h> #include < String .h> #pragma warning (disable: 4996) int main ( void ) { char buf [] = " asdwqfqwerwefq " ; // 1. access character --- string array embodiment for ( int I = 0 ; I <strlen (buf); I ++ ) { the printf ( " % C " , buf [I]); } the printf ( " \ n- " ); // 2. access string - - pure mode pointer char * B = buf;
for ( int I = 0 ; I <strlen (buf); I ++ ) { the printf ( " % C " , * (B + I)); // can use this manner, the compiler itself is a jump in this way a } the printf ( " \ n- " );
// 3. access strings --- nondescript manner char * buf = a; // array name, the first array element address for ( int I = 0 ; I <strlen (buf) ; I ++ ) { the printf ( " % C " , A [I]); } the printf ( " \ n- " );
//4. Access string --- nondescript manner for ( int I = 0 ; I <strlen (buf); I ++ ) { the printf ( " % C " , * (buf + I)); } the printf ( " \ n- " ) ;
/ * thinking: buf and p is exactly equivalent to it? buf: array name is a pointer, the first element of the array address, but [it] is a read-only constants; as defined in the first address and length of the stack, the latter system is conducive to recycling understanding * (buf + 1); // ok here as a fixed value buf operation * (buf ++); // err this operation can only variables * / the printf ( " \ n- " ); System ( " PAUSE " ); return 0; }