Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int myfn1() {
- int i=10;
- return i;
- }
- char myfn2() {
- char buf[10]="Hello";
- return buf;
- }
- int main(){
- printf("%dn", myfn1());
- printf("%sn", myfn2());
- }
- 10
- Segmentation fault
- char myfn2() {
- buf[10]="Hello";
- return buf;
- }
- char * myfn2() {
- buf[10]="Hello";
- return buf;
- }
- int main(void) {
- printf("%pn", (void*) myfn2()); // OK - pointer's value is printed
- printf("%sn", myfn2()); // Bad - code attempts sting access to invalid pointer.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement