Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include<string.h>
- void delete_str(char *str);
- int main()
- {
- char* dst1 = "string Literal"; //can't change the contents; note that address of char* dst1 is different seg from char safedst[]
- //dst1[0] = 'T'; //crashes. no compiler running
- const char* dst2 = "string Literal"; //can't change the contents
- //dst2[0] = 'T'; //won't compile. dst2[] is read-only location
- char source[] = "Sample string";
- char safedst[] = "sample String alternative dest";
- //safedst[0] = 'T'; //allowed
- //strcpy(dst1,source); //No warning or error, just Undefined Behavior; pgm crashes
- //strcpy(dst2,source); //Compiler issues a warning; pgm crashes
- strcpy(safedst, source); // No warning or error. No crash
- puts(safedst);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement