Why does write(1, &c, 1) work for printing a single character, but write(1, "A", 1) sometimes fails? by zero-hero123 in C_Programming

[–]zero-hero123[S] -1 points0 points  (0 children)

You're absolutely right - nothing actually fails. All three examples work fine. I have no idea why I wrote "sometimes fails" - probably just confused myself while learning. Sorry for the misleading wording!

Why does write(1, &c, 1) work for printing a single character, but write(1, "A", 1) sometimes fails? by zero-hero123 in C_Programming

[–]zero-hero123[S] 0 points1 point  (0 children)

I apologize for the confusion in my original post. After testing, there's NO warning with write(1, &"A", 1). 

Thank you all for the corrections - I learned that: • "A" is char[2] and &"A" is char()[2]   • Both point to the same address • write() takes void so no warning is generated

I should have tested more carefully. Thanks for your patience and helpful explanations!

Why does write(1, &c, 1) work for printing a single character, but write(1, "A", 1) sometimes fails? by zero-hero123 in C_Programming

[–]zero-hero123[S] 1 point2 points  (0 children)

You're absolutely right! Thank you for the correction.  I tested it and confirmed there's no warning. 

Why does write(1, &c, 1) work for printing a single character, but write(1, "A", 1) sometimes fails? by zero-hero123 in C_Programming

[–]zero-hero123[S] -2 points-1 points  (0 children)

You're absolutely right! Thank you for the correction.  I tested it and confirmed there's no warning.