Hello World and Program Structure — C

View, run, and experiment with Hello World and Program Structure — C in CodeUtility's online C IDE.

🚀 1,076,971 total executions (11,025 this month)

Udemy Logo Udemy Affiliates: Popular C courses people love

Loading…

💡 Looking to improve your skills? These courses may help—check them out while our AI model processes your request.

Explore by topic

Learn C and C++ together through practical comparisons, runnable code, output, memory models, data structures, algorithms, and modern C++ features.

C/C++ Examples →

🧩 About This C Online Executor

The CodeUtility C Executor lets you write and run C programs directly in your browser - no installation or compiler setup required. It’s powered by a secure sandbox that supports real C standards, including C89, C99, C11, and the latest version.

This tool uses a real C compiler running in the cloud to compile and execute your code just like a native environment. You can easily test snippets, learn syntax, or practice writing complete programs with input and output.

It’s designed to help learners and developers quickly experiment with C fundamentals - such as data types, pointers, loops, functions, arrays, and structures - without needing to install any compiler or IDE.

More than a code runner

Use a multi-file editor, an isolated execution terminal, runtime-specific libraries, persistent workspaces, sharing, and real-time collaboration from the same executor.

How to use this executor?

Choose a runtime, open or create a file, write your code, and select Run. Output appears in the terminal, while signed-in users can keep files in a workspace, install libraries, and collaborate through shares.

  1. Select a version and edit the current file or open another workspace file.
  2. Run the code, provide input in the terminal when requested, and review saved run history.
  3. Use libraries, workspace tools, sharing, and chat when your task needs more than one snippet.

💡 C Basics & Examples You Can Try Above

1. Declaring Variables and Constants

C requires you to declare the type of each variable. Use #define or const to define read-only values.

int age = 30;
double pi = 3.14159;
char grade = 'A';
char name[] = "Alice";
bool isActive = 1; // true

// Constants
#define MAX_USERS 100
const char* COMPANY = "CodeUtility";

2. Conditionals (if / switch)

Use if, else if, and switch for decision making.

int x = 2;
if (x == 1) {
    printf("One\n");
} else if (x == 2) {
    printf("Two\n");
} else {
    printf("Other\n");
}

switch (x) {
    case 1:
        printf("One\n");
        break;
    case 2:
        printf("Two\n");
        break;
    default:
        printf("Other\n");
}

3. Loops

Use for, while, and do-while for repetition.

for (int i = 0; i < 3; i++) {
    printf("%d\n", i);
}

int n = 3;
while (n > 0) {
    printf("%d\n", n);
    n--;
}

4. Arrays

Arrays store multiple elements of the same type.

int numbers[3] = {10, 20, 30};
printf("%d\n", numbers[1]);

5. Structs

struct lets you group related data.

struct Person {
    char name[50];
    int age;
};

struct Person p = {"Alice", 30};
printf("%s is %d years old\n", p.name, p.age);

6. Console Input/Output

Use printf and scanf for console I/O.

char name[50];
printf("Enter your name: ");
scanf("%s", name);
printf("Hello, %s\n", name);

7. Functions

Functions encapsulate reusable logic. Declare return type, name, and parameters.

int add(int a, int b) {
    return a + b;
}

printf("%d\n", add(3, 4));

8. Pointers

Use pointers to store memory addresses and manipulate data indirectly.

int x = 10;
int* ptr = &x;

printf("Value of x: %d\n", x);
printf("Address of x: %p\n", ptr);
printf("Value from pointer: %d\n", *ptr);

*ptr = 20;
printf("Updated x: %d\n", x);

9. File I/O

Use fopen, fprintf, fscanf, and fclose for file operations.

FILE* file = fopen("file.txt", "w");
fprintf(file, "Hello File");
fclose(file);

char line[100];
file = fopen("file.txt", "r");
fgets(line, sizeof(line), file);
printf("%s", line);
fclose(file);

10. String Handling

Use functions from <string.h> like strlen, strcpy, and strcmp.

#include <string.h>

char text[] = "Hello";
char copy[10];

strcpy(copy, text);
printf("Length: %lu\n", strlen(copy));
printf("Compare: %d\n", strcmp(copy, "Hello"));

11. Dynamic Memory

Use malloc and free for heap allocation.

int* nums = (int*) malloc(3 * sizeof(int));
nums[0] = 1; nums[1] = 2; nums[2] = 3;

for (int i = 0; i < 3; i++) {
    printf("%d ", nums[i]);
}

free(nums);