Web Neiro

C Programming Tutorial

Learn the fundamentals of C programming with these interactive examples and explanations.

C Programming Basics

C is a general-purpose programming language created in the 1970s that continues to be widely used today. These examples will help you understand the fundamental concepts of C programming.

Hello World
The classic first program in C
#include <stdio.h>

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

Explanation:

This program includes the standard input/output library and defines a main function that prints 'Hello, World!' to the console.

Variables
Declaring and using variables
#include <stdio.h>

int main() {
  int age = 25;
  float height = 1.75;
  char grade = 'A';

  printf("Age: %d\n", age);
  printf("Height: %.2f meters\n", height);
  printf("Grade: %c\n", grade);
  return 0;
}

Explanation:

This example shows how to declare variables of different types (int, float, char) and print them using format specifiers.

Input/Output
Reading user input
#include <stdio.h>

int main() {
  int number;
  printf("Enter a number: ");
  scanf("%d", &number);
  printf("You entered: %d\n", number);
  return 0;
}

Explanation:

This program prompts the user to enter a number, reads it using scanf(), and then displays it back to the user.