-5

I'm new to coding and recently I came across a problem that my code doesn't work unless I save that first so is it necessary to save a code every time I make a change in a code.(vscode)(c)

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • Save changes often. You never know when something happens. If you don't save often you might loose hours of work. Not only code, but when doing just about anything. – Some programmer dude Sep 03 '22 at 12:33
  • 3
    More specifically for programming and code, also use a [VCS (Version Control System)](https://en.wikipedia.org/wiki/Version_control) like for example Git. Commit changes often. And use remote repositories where you can push changes to keep them safe as a form of backup. It also help you keep track of the changes you make, and can help with debugging to *roll back* changes if needed. – Some programmer dude Sep 03 '22 at 12:36
  • 2
    If you make a change to your code, but don't save it, the compiler will compile the last saved file on the computer, which won't have the changes that are in your unsaved file. This isn't a shortcoming in VSCode, it's the same for any editor (Vim, Notepad, Emacs, Ultra32, Sublime, Brackets, et cetera). – Eljay Sep 03 '22 at 12:42
  • Does this answer your question? [Why don't other programs see the changes I made to a file in VS Code until I save those changes?](https://stackoverflow.com/questions/76984829/why-dont-other-programs-see-the-changes-i-made-to-a-file-in-vs-code-until-i-sav) – starball Aug 27 '23 at 06:36

2 Answers2

2

Usually, C and C++ are compiled, i.e. the file(s) with the source code need to go through a compiler to get translated to machine code. So, the program source needs to be saved first before it can go into the compiler, yes.

Most IDEs, like VSCode, will save when you ask them to compile, because that's useful assistance to you.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
1

No you don't. You can enable autosave: File > Auto Save

mikyll98
  • 1,195
  • 3
  • 8
  • 29