C String

What would happen if we compile and run this code ?

void main(){    
    // Option A.

    char str1[] = "example"; 

    str1[1] = 'a'; 

    // Option B. 

    char* str2 = "example"; 

    str2[1] = 'a';
}
View Code

This code compiles but option B will produce a run time error.

http://www.dev102.com/2008/04/28/a-programming-job-interview-challenge/

posted @ 2014-07-16 23:18  Sparkles  阅读(114)  评论(0编辑  收藏  举报