C Get Started

C Tutorial

1. Setting Up Your C Environment

To write and run C programs, you need a compiler. Some popular options:

Option 1: Install on Your PC

  • Windows: Install Code::Blocks or Dev-C++ (includes compiler).
    Or install GCC via MinGW.

  • Linux: GCC is usually pre-installed. Otherwise, install via:

    sudo apt install gcc
  • Mac: Install Xcode Command Line Tools:

    xcode-select --install

Option 2: Online Compilers

If you don’t want to install anything, you can use online C compilers:


2. Writing Your First C Program

Open your editor or online compiler and type this:


 

Explanation:

  • #include <stdio.h> → Imports the standard library for input/output.

  • int main() → Entry point of every C program.

  • printf() → Function to display text.

  • return 0; → Ends the program successfully.


3. Compiling and Running C Programs

Using a Compiler

  1. Save your file as hello.c.

  2. Open terminal/command prompt.

  3. Compile:

    gcc hello.c -o hello
  4. Run:

    ./hello # On Linux/Mac
    hello.exe # On Windows

Using Online Compiler

  • Paste your code.

  • Click Run.

  • Output will show:

Hello, World!

4. Basic C Syntax and Rules

  1. Case Sensitivemain and Main are different.

  2. Every statement ends with ;

  3. Curly braces {} – Define the start and end of a block.

  4. Comments:

    // Single-line comment
    /* Multi-line
    comment */


5. Variables and Data Types

Variables store values in memory. Examples:


 

  • %d → integer

  • %f → float

  • %c → char


6. Getting User Input


 

  • scanf() → Reads input from user.

  • & → Address operator (stores input in the variable).


7. Next Steps After Getting Started

Once you’ve run your first programs, you can move on to:

  1. Operators → +, -, *, /, %, etc.

  2. Conditional Statements → if, else, switch

  3. Loops → for, while, do-while

  4. Functions → Breaking code into reusable parts

  5. Arrays & Strings → Storing multiple values

  6. Pointers → Direct memory access

  7. Structures & File Handling → For advanced applications

You may also like...