1. What is C? Set up VS Code and run your first program

Aap kis language mein padhna chahoge?

Which language do you want to learn in?

Code aur technical words English mein hi rahenge. Aap baad mein bhi language badal sakte ho.

Lesson 1

What is C? Set up VS Code and run your first program

Beginner 60 minutes

You need before starting

  • A laptop with Windows 10 or Windows 11
  • Internet to download about 1 GB
  • No coding knowledge. This lesson starts from zero.

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

  1. You write source code in VS Code and save it as hello.c.
  2. You run gcc. It checks your code for mistakes.
  3. If there are no mistakes, gcc makes hello.exe.
  4. 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

  1. Use a Windows 10 or Windows 11 laptop.
  2. Keep about 1 GB of internet data ready.
  3. Keep 60 minutes free. You do this setup only once.
  4. 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.

  1. Open code.visualstudio.com/download (opens in a new tab) in your browser.
  2. Click the Windows button. The installer downloads.
  3. Open the downloaded file.
  4. Click I accept the agreement, then Next.
  5. Tick Add to PATH when you see it. Keep the other options as they are.
  6. Click Next, then Install, then Finish.
Check: VS Code opens and shows a Welcome page.

Step 2: Install MSYS2

  1. Open msys2.org (opens in a new tab) in your browser.
  2. Click the installer link. Its name looks like msys2-x86_64-20260611.exe.
  3. Open the downloaded file and click Next.
  4. Keep the folder C:\msys64. Click Next two more times.
  5. Wait for the green bar to finish. Click Next.
  6. 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.

Check: You see a black window with a line that ends with a $ sign.

Step 3: Install gcc

  1. Click inside the MSYS2 UCRT64 window.
  2. Type the command below. You can also copy it and paste it with a right click.
  3. Press Enter.
MSYS2 UCRT64
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

pacman is the MSYS2 shop counter. -S means "get these packages for me".

MSYS2 asks you two questions:

Output
:: 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):
  1. Press Enter to pick all.
  2. When you see :: Proceed with installation? [Y/n], type Y and press Enter.
  3. Wait. The download takes 2 to 10 minutes.

You may see a slightly different list. MSYS2 updates often. That is fine.

Check: The last lines say 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.

  1. Press the Windows key and type environment.
  2. Click Edit environment variables for your account.
  3. In the top box, User variables, click Path. Then click Edit.
  4. Click New.
  5. Type C:\msys64\ucrt64\bin and press Enter.
  6. Click OK, then OK again.
Check: When you open the Path list again, you see C:\msys64\ucrt64\bin in it.

Step 5: Check gcc in VS Code

  1. Open VS Code.
  2. Open a terminal with Ctrl + </kbd>. The <kbd> key is above Tab.
  3. Type the command below and press Enter.
PowerShell
gcc --version
Output
gcc.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.

Check: The first line starts with 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.

  1. Press Ctrl + Shift + X. The Extensions panel opens.
  2. Type C/C++ in the search box.
  3. Click C/C++ by Microsoft.
  4. Click Install.
Check: The C/C++ extension shows an Uninstall button instead of Install.

Step 7: Make a practice folder

You will keep every C file of this course in one folder.

  1. Open File Explorer and click This PC, then Local Disk (C:).
  2. Right click an empty area. Click New, then Folder.
  3. Name it c-practice.
  4. In VS Code, click File, then Open Folder.
  5. Pick C:\c-practice and click Select Folder.
  6. If VS Code asks "Do you trust the authors?", click Yes, I trust the authors.
Check: The left side of VS Code shows C-PRACTICE at the top.

Step 8: Write your first program

  1. Click File, then New File.
  2. Type the name hello.c and press Enter.
  3. Type the code below. Typing it yourself helps you learn faster than pasting.
  4. Press Ctrl + S to save.
hello.c
#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.

LineMeaning
#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".
Check: The tab at the top says 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.

  1. Open the terminal with Ctrl + `, if it is not open.
  2. Type the command below and press Enter.
PowerShell
gcc hello.c -o hello

This command prints nothing when it works. No news is good news.

Here is how to read it:

  • gcc runs the compiler.
  • hello.c is your source file.
  • -o hello means "name the output app hello". Windows adds .exe for you.
Check: A new file named hello.exe appears in the left panel of VS Code.

Step 10: Run the program

PowerShell
.\hello.exe
Output
Hello, 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.

Check: The terminal prints 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.

PowerShell
gcc hello.c -o hello; .\hello.exe
Output
Hello, BCA!

Press the Up arrow key in the terminal to bring back your last command. This saves a lot of typing.

Check: One command prints 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-practice with hello.c and hello.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

Output
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 : CommandNotFoundException

Why: 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

hello.c
#include <stdio.h>

int main(void)
{
    printf("Hello, BCA!\n")
    return 0;
}
PowerShell
gcc hello.c -o hello
Output
hello.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

hello.c
#include <stdio.h>

int main(void)
{
    Printf("Hello, BCA!\n");
    return 0;
}
PowerShell
gcc hello.c -o hello
Output
hello.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");
      |     ^~~~~~
      |     printf

Why: 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

Output
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 .\

Output
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 : CommandNotFoundException

PowerShell 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

Output
Program 'hello.exe' failed to run: An Application Control policy has blocked this file

Windows 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.

  1. Press the Windows key, type Windows Security and open it.
  2. Click App & browser control.
  3. Click Smart App Control settings.
  4. Pick Off. Click Yes if Windows asks.
  5. Run .\hello.exe again.

Microsoft Defender antivirus still protects your laptop after this. Microsoft says recent Windows updates let you turn Smart App Control on again later.

Check: .\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.c and change the text inside the quotes.
  • Use two printf lines.
  • 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
me.c
#include <stdio.h>

int main(void)
{
    printf("My name is Asha Verma.\n");
    printf("I study BCA at City College, Lucknow.\n");
    return 0;
}
PowerShell
gcc me.c -o me; .\me.exe
Output
My name is Asha Verma.
I study BCA at City College, Lucknow.
Check: The terminal prints your name and your college on two separate lines.

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.