C Get Started

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:

#include <stdio.h> // Include standard input/output library

int main() { // Main function
printf("Hello, World!\n"); // Print text to the screen
return 0; // Exit program
}

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:

#include <stdio.h>

int main() {
int age = 25; // Integer
float height = 5.9; // Floating-point number
char grade = 'A'; // Character

printf("Age: %d\n", age);
printf("Height: %.1f\n", height);
printf("Grade: %c\n", grade);

return 0;
}

  • %d → integer

  • %f → float

  • %c → char


6. Getting User Input

#include <stdio.h>

int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age); // Take input from user
printf("You are %d years old\n", age);
return 0;
}

  • 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

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *