We can compile the following program using the gcc compiler.
But when running it, we get a segmentation fault.
Why ?
#include <stdio.h>
int main()
{
// The following statement is equal to " constant char* filename = "file1.txt"; "in c++
char* filename = "file1.txt"; // Initialization and after that filename points to a constant string.
printf("\nPlease input for the filename ==> ");
scanf("%s", filename); // Try to modify a constant string. It will cause a segmentation fault !
printf("\nThe file name you have input is %s", filename);
return 0;
}