10 Jan 2015

Arrays in c basic level set one



I have collected best c language array concept which not only help student in interview preparation for Software Company but also help to cover c array programming exercises.
Question Number 1
Main()
{
   static char string[5][20]={"pascal","ada","cobol","fortran","perl"};
    int i;
    char *t;
    t=string[3];
    string[3]=string[4];
    string[4]=t; 
    for (i=0;i<=4;i++)
            printf("%s",string[i]);
}
Answer:
Compiler error: Lvalue required in function main
Explanation:
Array string are pointer constants. So it cannot be modified.

1 comment: