This is due to stream buffering of stdout
. Unless you do fflush(stdout)
or you print a newline "\n"
the output is may be buffered.
In this case, it’s segfaulting before the buffer is flushed and printed.
You can try this instead:
printf("%s",name); fflush(stdout); // Flush the stream. name[1]='s'; // Segfault here (undefined behavior)
or:
printf("%s\n",name); // Flush the stream with '\n' name[1]='s'; // Segfault here (undefined behavior)
Related Posts:
- What causes a segmentation fault (core dump) to occur in C?
- Correct format specifier for double in printf
- segmentation fault : 11
- Strings and character with printf
- segmentation fault : 11
- printf() formatting for hexadecimal
- What is the argument for printf that formats a long?
- Is there a printf converter to print in binary format?
- What is a bus error? Is it different from a segmentation fault?
- What does “%.*s” mean in printf?
- What is a bus error? Is it different from a segmentation fault?
- How to print a char array in C through printf?
- How can one print a size_t variable portably using the printf family?
- error: aggregate value used where an integer was expected
- Using floats with sprintf() in embedded C
- Printf width specifier to maintain precision of floating-point value
- Which of sprintf/snprintf is more secure?
- Does C have a string type?
- printf format specifiers for uint32_t and size_t
- What primitive data type is time_t? [duplicate]
- segmentation fault using scanf
- Segmentation fault- strcat
- segmentation fault with strcpy [duplicate]
- How big can a 64 bit unsigned integer be?
- What is *(uint32_t*)?
- Why should we typedef a struct so often in C?
- What is a string of hexadecimal digits?
- What is the difference between ++i and i++?
- Stack smashing detected
- Stack smashing detected
- How do I determine the size of my array in C?
- Why am I getting “void value not ignored as it ought to be”?
- Pointer Arithmetic
- Openssl : error “self signed certificate in certificate chain”
- What is the difference between C and embedded C?
- How do I create an array of strings in C?
- Difference between malloc and calloc?
- How do function pointers in C work?
- What are .a and .so files?
- So what does “return 0” actually mean?
- warning: assignment makes integer from pointer without a cast
- Why use bzero over memset?
- What does “1e” mean?
- how to use uint64_t in C [duplicate]
- How do I solve the following errors: “Undefined reference to WinMain”, “[Error] Id returned 1 exit status”?
- Warning comparison between pointer and integer
- How do I properly compare strings in C?
- Connect: Socket operation on non-socket
- How to correctly use the extern keyword in C
- How do we check if a pointer is NULL pointer?
- how to use wait in C
- what is the meaning of == sign?
- How do I calculate MB/s & MiB/s?
- ARM Assembler – How do I use CMP, BLT and BGT?
- Invalid read of size 8 – Valgrind + C
- warning: incompatible implicit declaration of built-in function ‘xyz’
- strcpy vs strdup
- Warning comparison between pointer and integer in C language
- error: expected declaration or statement at end of input in c
- Why do I get clang: error: linker command failed with exit code 1?
- Difference between scanf() and fgets()
- Return char[]/string from a function [duplicate]
- How to convert integer to char in C?
- Program received signal SIGPIPE, Broken pipe
- Difference between char* and const char*?
- How to read from stdin with fgets()?
- Output single character in C
- Does connect() block for TCP socket?
- Converting a C program to MIPS
- Why am I getting “array initializer must be an initializer list or string literal”?
- C: linker command failed with exit code 1
- #31 expression must have integral type
- What’s the equivalent of new/delete of C++ in C?
- sizeof float (3.0) vs (3.0f)
- How to trigger SIGUSR1 and SIGUSR2?
- Display value found at given address gdb
- Does C have a “foreach” loop construct?
- Array definition – Expression must have a constant value
- Constant pointer vs Pointer to constant
- What is the cause of flexible array member not at end of struct error?
- Variable warning set but not used
- Expected declaration specifier error in function
- valgrind – Address —- is 0 bytes after a block of size 8 alloc’d
- strcmp not working
- How to printf a memory address in C
- Data argument not used by format strings in C
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- How does one represent the empty char?
- Removing trailing newline character from fgets() input
- “Multiple definition”, “first defined here” errors
- how use EOF stdin in C
- How does the strtok function in C work? [duplicate]
- Allocating char array using malloc
- Implementation of strtok() function
- Reaching EOF with fgets
- The difference between char * and char[] [duplicate]
- How to clear input buffer in C?
- strtok segmentation fault
- Compiler warning – suggest parentheses around assignment used as truth value
- error: `itoa` was not declared in this scope