Lesson 1
What is C? Set up VS Code and run your first program
What you will learn
- What a program is, and what the C language is.
- Why a computer needs a compiler to run C.
- Install VS Code, MSYS2 and the gcc compiler on Windows.
- Write your first C program.
- Turn it into an app and run it from the VS Code terminal.
What it is
Program
A program is a list of instructions for a computer. A recipe is a list of instructions for a cook. "Boil water. Add tea leaves. Add milk. Add sugar." The cook follows the steps in order. A computer follows a program in the same way.
The C language
C is a programming language. It was made in 1972 by Dennis Ritchie at Bell Labs in the USA. A programming language is a language that people use to write programs.
C is more than 50 years old, and it is still everywhere. Windows, Linux and Android have big parts written in C. The chip inside a washing machine, an ATM or a car often runs C code.
Source code
Source code is the program you write, as plain text.
A C source file ends with .c, like hello.c.
Compiler
A computer does not understand C directly. It understands only machine code, made of 0s and 1s. A compiler is a program that turns your C source code into machine code.
Think of a translator at a meeting. You speak Hindi. The guest understands only Japanese. The translator listens to you and speaks Japanese to the guest. A compiler is your translator to the computer.
gcc
gcc is a free C compiler. Most colleges and companies use it.
On Windows, the result of gcc is an app file that ends with .exe, like hello.exe.
MSYS2
MSYS2 is a free tool that installs gcc on Windows for you. It is like a shop that sells the right tools. You go there once, pick gcc, and take it home.
How it works
- You write source code in VS Code and save it as
hello.c. - You run gcc. It checks your code for mistakes.
- If there are no mistakes, gcc makes
hello.exe. - You run
hello.exe. The computer follows your instructions.
Why you need it
- C is a main subject in the first year of BCA. Your exams and viva use it.
- C teaches how a computer really works: memory, data and instructions.
- C++, Java, Python and JavaScript all borrow ideas from C. Learn C and the others feel easy.
- Many placement tests start with C questions.
- You will set up gcc once. After that, every lesson only needs VS Code.
Before you start
- Use a Windows 10 or Windows 11 laptop.
- Keep about 1 GB of internet data ready.
- Keep 60 minutes free. You do this setup only once.
- Close other apps, so the downloads go faster.
Steps
Step 1: Install VS Code
VS Code is a free code editor from Microsoft. A code editor is like a notebook made for writing code. If you already have VS Code, skip to Step 2.
- Open code.visualstudio.com/download (opens in a new tab) in your browser.
- Click the Windows button. The installer downloads.
- Open the downloaded file.
- Click I accept the agreement, then Next.
- Tick Add to PATH when you see it. Keep the other options as they are.
- Click Next, then Install, then Finish.
Step 2: Install MSYS2
- Open msys2.org (opens in a new tab) in your browser.
- Click the installer link. Its name looks like
msys2-x86_64-20260611.exe. - Open the downloaded file and click Next.
- Keep the folder
C:\msys64. Click Next two more times. - Wait for the green bar to finish. Click Next.
- Keep Run MSYS2 now ticked. Click Finish.
A black window opens. Its title is MSYS2 UCRT64. This is a terminal. A terminal is a window where you type commands instead of clicking.
$ sign.Step 3: Install gcc
- Click inside the MSYS2 UCRT64 window.
- Type the command below. You can also copy it and paste it with a right click.
- Press Enter.
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchainpacman is the MSYS2 shop counter. -S means "get these packages for me".
MSYS2 asks you two questions:
:: There are 6 members in group mingw-w64-ucrt-x86_64-toolchain:
:: Repository ucrt64
1) mingw-w64-ucrt-x86_64-gdb-multiarch 2) mingw-w64-ucrt-x86_64-libmangle 3) mingw-w64-ucrt-x86_64-make 4) mingw-w64-ucrt-x86_64-pkgconf 5) mingw-w64-ucrt-x86_64-tools 6) mingw-w64-ucrt-x86_64-winstorecompat
Enter a selection (default=all):- Press Enter to pick all.
- When you see
:: Proceed with installation? [Y/n], typeYand press Enter. - Wait. The download takes 2 to 10 minutes.
You may see a slightly different list. MSYS2 updates often. That is fine.
installing many times, and you see the $ sign again.Step 4: Tell Windows where gcc lives
Windows looks for apps in a list of folders called PATH. It is like your phone contacts list. If a number is not saved, you cannot call it by name. You will save the gcc folder in that list.
- Press the Windows key and type
environment. - Click Edit environment variables for your account.
- In the top box, User variables, click Path. Then click Edit.
- Click New.
- Type
C:\msys64\ucrt64\binand press Enter. - Click OK, then OK again.
C:\msys64\ucrt64\bin in it.Step 5: Check gcc in VS Code
- Open VS Code.
- Open a terminal with Ctrl +
</kbd>. The <kbd>key is above Tab. - Type the command below and press Enter.
gcc --versiongcc.exe (Rev4, Built by MSYS2 project) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Your version number may be higher. That is fine.
gcc.exe and shows a version number.Step 6: Install the C/C++ extension
An extension is an add-on for VS Code, like an app on your phone. The C/C++ extension colours your code and points out mistakes as you type.
- Press Ctrl + Shift + X. The Extensions panel opens.
- Type
C/C++in the search box. - Click C/C++ by Microsoft.
- Click Install.
Step 7: Make a practice folder
You will keep every C file of this course in one folder.
- Open File Explorer and click This PC, then Local Disk (C:).
- Right click an empty area. Click New, then Folder.
- Name it
c-practice. - In VS Code, click File, then Open Folder.
- Pick
C:\c-practiceand click Select Folder. - If VS Code asks "Do you trust the authors?", click Yes, I trust the authors.
C-PRACTICE at the top.Step 8: Write your first program
- Click File, then New File.
- Type the name
hello.cand press Enter. - Type the code below. Typing it yourself helps you learn faster than pasting.
- Press Ctrl + S to save.
#include <stdio.h>
int main(void)
{
printf("Hello, BCA!\n");
return 0;
}Here is what each line means, in simple words. You learn each part properly in the next lesson.
| Line | Meaning |
|---|---|
#include <stdio.h> | Bring in the tools for printing on the screen. |
int main(void) | The program starts here. Every C program has a main. |
{ and } | The start and the end of main. |
printf("Hello, BCA!\n"); | Print Hello, BCA! on the screen. \n means "go to a new line". |
return 0; | Tell Windows "the program finished fine". |
hello.c with no white dot. A dot means the file is not saved.Step 9: Compile the program
To compile means to turn source code into an app with a compiler.
- Open the terminal with Ctrl + `, if it is not open.
- Type the command below and press Enter.
gcc hello.c -o helloThis command prints nothing when it works. No news is good news.
Here is how to read it:
gccruns the compiler.hello.cis your source file.-o hellomeans "name the output apphello". Windows adds.exefor you.
hello.exe appears in the left panel of VS Code.Step 10: Run the program
.\hello.exeHello, BCA!.\ means "in this folder". PowerShell needs it to run an app from the current folder.
Does Windows say the app is blocked? See Windows blocks your program below.
Hello, BCA!.Step 11: Compile and run with one line
You will compile and run many times in this course.
Put both commands on one line, with a semicolon ; between them.
gcc hello.c -o hello; .\hello.exeHello, BCA!Press the Up arrow key in the terminal to bring back your last command. This saves a lot of typing.
Hello, BCA!.Output
You now have:
- VS Code with the C/C++ extension.
- The gcc compiler, which works from the VS Code terminal.
- A folder
C:\c-practicewithhello.candhello.exe. - Your first program, which prints
Hello, BCA!.
You did the hardest part of the whole course: the setup.
Common errors
gcc is not recognized
gcc : The term 'gcc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gcc --version
+ ~~~
+ CategoryInfo : ObjectNotFound: (gcc:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundExceptionWhy: Windows cannot find gcc. The PATH from Step 4 is missing, or VS Code was open while you changed it.
Fix: Check the Path list again. It must have C:\msys64\ucrt64\bin with no spaces. Then close every VS Code window and open VS Code again.
A missing semicolon
#include <stdio.h>
int main(void)
{
printf("Hello, BCA!\n")
return 0;
}gcc hello.c -o hellohello.c: In function 'main':
hello.c:5:28: error: expected ';' before 'return'
5 | printf("Hello, BCA!\n")
| ^
| ;
6 | return 0;
| ~~~~~~Why: In C, most lines end with a semicolon ;. It is like a full stop at the end of a sentence.
Fix: Read the line number. hello.c:5:28 means file hello.c, line 5, character 28. gcc even shows where the ; must go. Add it, save and compile again.
A capital letter in printf
#include <stdio.h>
int main(void)
{
Printf("Hello, BCA!\n");
return 0;
}gcc hello.c -o hellohello.c: In function 'main':
hello.c:5:5: error: implicit declaration of function 'Printf'; did you mean 'printf'? [-Wimplicit-function-declaration]
5 | Printf("Hello, BCA!\n");
| ^~~~~~
| printfWhy: C is case sensitive. That means Printf and printf are different words for C.
Fix: Write printf in small letters. gcc even suggests it: did you mean 'printf'?
The file is not found
cc1.exe: fatal error: helo.c: No such file or directory
compilation terminated.Why: The file name has a spelling mistake, or the terminal is in a different folder.
Fix: Check the spelling. Check that VS Code shows C-PRACTICE at the top of the left panel.
Running the app without .\
hello : The term 'hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hello
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (hello:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundExceptionPowerShell may also print a Suggestion line that tells you to type .\hello.
Why: PowerShell does not run apps from the current folder unless you say so.
Fix: Type .\hello.exe, with the dot and the backslash.
Windows blocks your program
Program 'hello.exe' failed to run: An Application Control policy has blocked this fileWindows may also show a pop-up that says Smart App Control blocked an app that may be unsafe.
Why: Many new Windows 11 laptops have Smart App Control turned on.
It blocks every app that Microsoft does not know yet.
Your hello.exe is brand new, so Microsoft has never seen it.
Your code is fine. Windows is just being careful.
Fix: Turn Smart App Control off. Every programmer who compiles code on Windows 11 needs this.
- Press the Windows key, type
Windows Securityand open it. - Click App & browser control.
- Click Smart App Control settings.
- Pick Off. Click Yes if Windows asks.
- Run
.\hello.exeagain.
Microsoft Defender antivirus still protects your laptop after this. Microsoft says recent Windows updates let you turn Smart App Control on again later.
.\hello.exe prints Hello, BCA! with no "blocked" message.The old output still shows
You changed the code, but the program prints the old text.
Why: You did not save the file, or you ran the app without compiling again.
Fix: Press Ctrl + S. Then compile and run again with the one-line command.
Try it yourself
Practice task
Task: Write a program me.c that prints your name on one line and your college on the next line.
Hints:
- Copy
hello.cand change the text inside the quotes. - Use two
printflines. - End each text with
\n, so the next line starts below. - Compile and run with
gcc me.c -o me; .\me.exe.
Expected result: Two lines: your name, then your college.
Show solution
#include <stdio.h>
int main(void)
{
printf("My name is Asha Verma.\n");
printf("I study BCA at City College, Lucknow.\n");
return 0;
}gcc me.c -o me; .\me.exeMy name is Asha Verma.
I study BCA at City College, Lucknow.Quick recap
- A program is a list of instructions. C is a language for writing programs.
- A compiler turns C source code into an app. gcc is the compiler you installed.
- Compile with
gcc hello.c -o hello. Run with.\hello.exe. - Join both with
;and press the Up arrow to repeat. - Read error messages. They tell you the line number and often the fix.