Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST

C Tutorial

C HOME C Intro C Get Started C Syntax C Output C Comments C Variables C Data Types C Type Conversion C Constants C Operators C Booleans C If...Else C Switch C While Loop C For Loop C Break/Continue C Arrays C Strings C User Input C Memory Address C Pointers

C Functions

C Functions C Function Parameters C Scope C Function Declaration C Math Functions C Inline Functions C Recursion C Function Pointers

C Files

C Create Files C Write To Files C Read Files

C Structures

C Structures C Nested Structures C Structs & Pointers C Unions C typedef C Struct Padding

C Enums

C Enums

C Memory

C Memory Management

C Errors

C Errors C Debugging C NULL C Error Handling C Input Validation

C More

C Date C Random Numbers C Macros C Organize Code C Storage Classes C Bitwise Operators C Fixed-width Integers

C Projects

C Projects

C Reference

C Reference C Keywords C <stdio.h> C <stdlib.h> C <string.h> C <math.h> C <ctype.h> C <time.h>

C Examples

C Examples C Real-Life Examples C Exercises C Quiz C Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate

C Get Started


Get Started With C

At W3Schools, you can start learning C without installing anything.

Our Online C Editor runs directly in your browser and shows both the code and the result:

Code:

#include <stdio.h>

int main() {
  printf("Hello World!");
  return 0;
}

Result:

Hello World!
Try it Yourself »

This editor will be used in the entire tutorial to demonstrate the different aspects of C.


Install C

If you want to run C programs on your own computer, you need two things:

  • A text editor to write C code
  • A compiler to turn the C code into a program the computer can run

The compiler reads your C code and translates it into machine code.

There are many editors and compilers available. To make things easier, most people use an IDE, which includes both.


Install IDE

An IDE (Integrated Development Environment) is a program that helps you write, compile, and run code.

Popular IDEs include Code::Blocks, Eclipse, and Visual Studio. These are free tools that can also help you find errors in your code.

Note: Web-based IDEs can also work, but they often have limited features.

In this tutorial, we will use Code::Blocks, which is a good and simple choice for beginners.

You can download Code::Blocks from https://www.codeblocks.org. Choose the mingw-setup.exe file, which includes both the editor and a compiler.


C Quickstart

Let's create our first C file.

Open Codeblocks and go to File > New > Empty File.

Write the following C code and save the file as myfirstprogram.c (File > Save File as):

myfirstprogram.c

#include <stdio.h>

int main() {
  printf("Hello World!");
  return 0;
}

Note: C source files always end with .c.

Don't worry if you don't understand the code above - we will discuss it in detail in later chapters. For now, focus on how to run the code.

In Codeblocks, it should look like this:

Then, go to Build > Build and Run to run (execute) the program. The result will look something to this:

Hello World!
Process returned 0 (0x0) execution time : 0.011 s
Press any key to continue.

If you see the message above, your setup is working correctly.

Congratulations! You have now written and executed your first C program.

What just happened? You wrote C code, the compiler turned it into a program, and the computer ran it. This is the basic workflow you will use throughout this tutorial.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.