No, it is undefined behaviour. It just happens to work in your case, but may stop working at any time.
More Related Contents:
- Difference between static memory allocation and dynamic memory allocation
- Dynamic allocation of an unknown matrix in C
- What does this GCC error “… relocation truncated to fit…” mean?
- Create a wrapper function for malloc and free in C
- Maximum memory which malloc can allocate
- What does the brk() system call do?
- Where are constant variables stored in C?
- What happens when a variable goes out of scope?
- Explain this implementation of malloc from the K&R book
- Kernel zeroes memory?
- Why would you ever want to allocate memory on the heap rather than the stack? [duplicate]
- memory alignment within gcc structs
- Why do I get different results when I dereference a pointer after freeing it?
- Is it ok to use “classic” malloc()/free() in Objective-C/iPhone apps?
- Memory usage of current process in C
- Finding the address range of the data segment
- Determining Stack Space with Visual Studio
- Why do you specify the size when using malloc in C?
- When should I use malloc in C and when don’t I?
- C: Correctly freeing memory of a multi-dimensional array
- Size of stack and heap memory [duplicate]
- What happens if I try to access memory beyond a malloc()’d region?
- Is freeing allocated memory needed when exiting a program in C
- Is free() zeroing out memory?
- How do realloc and memcpy work?
- dynamic allocation/deallocation of 2D & 3D arrays
- Why exactly should I not call free() on variables not allocated by malloc()?
- Struct varies in memory size?
- /proc/[pid]/pagemaps and /proc/[pid]/maps | linux
- Performance: memset